thephpleague / omnipay-common

Core components for the Omnipay PHP payment processing library
MIT License
329 stars 242 forks source link

Adding support for user and account gateways #209

Open DimeZilla opened 5 years ago

DimeZilla commented 5 years ago

Hi, Big fan! I really appreciate all of the work you all did to put Omnipay together.

I work for a company that is building an application that is sort of a "merchant marketplace" where essentially we are providing a platform for non-profits to create accounts and solicit donations. Like many others that have discovered Omnipay, we built our application and then discovered that we didn't totally love the payment processor we were using.

So, we began to build Omnipay into our platform but quickly noticed that there wasn't much in support for a common api for creating accounts and users with the payment processor platforms. This PR lays the foundation for that support.

If this fork is accepted, driver developers should now think of their drivers as providing 3 gateways:

Accessing the gateways would follow the same conventions from before but unlike Omnipay\Omnipay::create('[name]') to retrieve the payment gateway, you would use Omnipay\Omnipay::user('[name]') and Omnipay\Omnipay::account('[name]') to retrieve the user gateway and the account gateway. In the PR, ::create was left alone but we also added ::payment as an alias to create.

For the GatewayFactory to resolve the payment gateway, it will look for a gateway with the following namespace pattern: Omnipay\[name]\Gateway. As you can see, this was left alone. But for User and Account gateways, the Gateway factory will look for Omnipay\[name]\User\Gateway and Omnipay\[name]\Account\Gateway respectively.

To support these new gateways, we added AbstractAccountGateway and AbstractUserGateway. Again, my goal in this PR was to not break all of the existing v3 drivers, thus, some of the naming might look funky. For instance, AbstractGateway is still the class a driver would extend to build their Payment Gateway. And now, these three abstract classes extend from AbstractGenericGateway. I think in an ideal world, we'd have an AbstractPaymentGateway and then all of these classes would extend AbstractGateway, but I digress.

Further, AbstractRequest now extends AbstractGenericRequest and the new gateways can use requests that extend this new base abstract class.

To support testing of the new gateways, we forked the omnipay-tests package to radcampaign/omnipay-tests and added AccountGatewayTestCase and UserGatewayTestCase. If this PR is accepted, I'll submit a PR for this fork as well.

For an example of how a driver might look with this new PR - we are actively working on a wepay driver that can be found at radcampaign/omnipay-wepay. Please keep in mind though that this is under active development.

Thank you much! I hope that this PR furthers this project in productive way.