Cainy's avatar
Level 1

Implementing Payment Drivers

Dear Laravel community,

I am currently working on a fully custom e-commerce site. I am just not quite sure how to implement the payments. The problem here is that I have to write my own API-drivers for multiple different payment providers. So we have some payment methods that are provided by provider A and some by provider B.

I thought I'd make an abstract class PaymentDriver and then store the concrete implementation in my payment_methods table in the database:

  • String driver: for example \App\Payments\PaymentDriverA

In the corresponding Livewire components I don't want to implement all the API logic because it might be that I want to have multiple different components for example for the checkout, returning an order or editing an order in the backend. So I need a global service that makes the Payment Api available to all these components. In the end, I just want to pass the PaymentMethod Model to my livewire components and that should be enough.

Any Ideas on how to improve / implement this idea? Is there anything I should be careful of?

0 likes
5 replies
Cainy's avatar
Level 1

@vincent15000 A great article, thanks a lot! I will definitely look into Services and the best-practices repo.

1 like
martinbean's avatar

The problem here is that I have to write my own API-drivers for multiple different payment providers.

@cainy Not true. This is what Omnipay aims to solve. A single API with drivers for numerous payment gateways.

1 like
Cainy's avatar
Level 1

@martinbean Thanks for the notice! That looks like a nice wrapper for the drivers. Unfortunately, my payment provider is not available so I'd have to write my own anyways.

1 like
martinbean's avatar

@Cainy Shouldn’t take too much effort to create a class for your specific payment provider. You could even then contribute it back to the project if it’s a provider other people use and would benefit from it being included in the Omnipay library 🙂

1 like

Please or to participate in this conversation.