0

Currently, I am handling stripe payments with Omnipay's Stripe library. Similar with the example below:

$gateway = Omnipay::create('Stripe');
        $gateway->setApiKey("sk_test_xHGgkZtGOlTwxi4d8GYOHifZ");
        $formData = array('number' => '4242424242424242', 'expiryMonth' => '6', 'expiryYear' => '2030', 'cvv' => '123');
        $response = $gateway->purchase(array('amount' => '10.00', 'currency' => 'USD', 'card' => $formData))->send();

However, there are too much different payment gateways. Let's assume, I've both Paypal and Stripe packages of omnipay. How can I handle the omnipay package that selected as a default on db. I don't know what to do. Ofcourse, You could say simply use if and else. But, it's not a good in practice. What sticks my mind and bother me is implementing this idea with a generic way with the S.O.L.I.D. principles in Laravel.

bl4cksta
  • 794
  • 12
  • 32
  • You can maybe use the strategy pattern with a `StripePaiement` and a `PaypalPaiement` class that builds the good Omnipay object, both have the same exposed methods `build`, `purchase` etc.. an exemple [here](https://sourcemaking.com/design_patterns/strategy/php) of the usages – Julien METRAL Mar 04 '19 at 13:05
  • with a common used interface, I can also build a standard to extend it right? That means I can use it on any different kind of objects. So, it's kind of service class of laravel right? – bl4cksta Mar 05 '19 at 11:05

0 Answers0