Issue
I am using PayPal, Razor pay, Stripe payment gateways in my project. When select user one of them payment gateway it redirects to assigned controller function from there it redirects its particular controller. I want to write all the functions for payment gateways in single controller to cut off redirections for customer.
when user select payment gateway and submit the form it redirects to mentioned below controller function
if ($payment_mode->payment_gateway_name == "Paypal") {
return redirect()->route('paywithpaypal', $planId);
} else if ($payment_mode->payment_gateway_name == "Razorpay") {
return redirect()->route('paywithrazorpay', $planId);
} else if ($payment_mode->payment_gateway_name == "Stripe") {
return redirect()->route('paywithstripe', $planId);
} else if ($payment_mode->payment_gateway_name == "Bank Transfer") {
}
and in that controller all functions is defined.
Solution
Create Classes as below:
- PaymentController
- Seperate classes implementing RazorpayService, StripeService, BankTransferService apis
- Factory Method to create class object of RazorpayService, StripeService, BankTransferService based on request parameters
PaymentController uses factory method to create object of appropriate service and calls appropriate method on this object using input parameters
Answered By - pks11 Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.