thephpleague / omnipay

A framework agnostic, multi-gateway payment processing library for PHP 5.6+
http://omnipay.thephpleague.com/
MIT License
5.91k stars 925 forks source link

Support FCQN for GatewayFactory #650

Closed Mouke closed 3 years ago

Mouke commented 3 years ago

Hello there !

I'm testing Omnipay for the first time and I'd like to suggest an enhancement. After a small search in issues, i've seen no traces of such suggestion.

Currently, to use Omnipay/Stripe's PaymentIntents Gateway, I have to write this code : $gateway = Omnipay\Omnipay::create('Stripe\PaymentIntents');

Why not allow to use the gateway FQCN in \Omnipay\Common\Helper::getGatewayClassName ? It would be much easier (and cleaner) to write this : use Omnipay\Stripe\PaymentIntentsGateway; $gateway = Omnipay\Omnipay::create(PaymentIntentsGateway::class);

If you want, I would gladly make that small update and suggest a PR for that.

barryvdh commented 3 years ago

isn't this already possible?

Mouke commented 3 years ago

I tried yesterday (I don't have my code under the nose so I can't give you my composer.lock exact version but it should be the latest one), it doesn't work.

When I tried to give it the FQCN, it tried to load Omnipay\Omnipay\Stripe\PaymentIntentsGateway\Gateway

barryvdh commented 3 years ago

Ah yes, see https://github.com/thephpleague/omnipay-common/blob/5b16387ec5ab1b9ff86bdf0f20415088693b9948/src/Common/Helper.php#L128

Yeah I think the problem was that classes can exists (eg '\Stripe'). But we could use https://www.php.net/manual/en/function.is-subclass-of.php to check if the full name is actually a class that implements the gateway interface.

barryvdh commented 3 years ago

If you could make a testcase for it, that would be great!

Mouke commented 3 years ago

I'll try to send you a PR with the fix and a testcase this week.

Mouke commented 3 years ago

Ok got the issue : It is very weird : PaymentIntentsGateway::class (which prints 'Omnipay\Stripe\PaymentIntentsGateway') is processed as a Classname because it doesn't start by a .

barryvdh commented 3 years ago

yeah it checks on \ so need to change it.

Mouke commented 3 years ago

I'm adding a check if it starts by Omnipay. Will do the job.

barryvdh commented 3 years ago

THanks. TWeaked it a bit: https://github.com/thephpleague/omnipay-common/commit/30c6db3e9c2df34c2c9ad854b8bca53b597b456a

Mouke commented 3 years ago

Thanks for your reactivity :)