PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 3, 2022

[FIXED] How to use multiple payment gateways function in single controller in laravel 8?

 July 03, 2022     controller, laravel, laravel-8, payment-gateway, paypal     No comments   

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.

enter image description here

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:

  1. PaymentController
  2. Seperate classes implementing RazorpayService, StripeService, BankTransferService apis
  3. 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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing