thephpleague / omnipay-sagepay

Sage Pay driver for the Omnipay PHP payment processing library
MIT License
54 stars 78 forks source link

Consider making Omnipay do more of the work #157

Open eileenmcnaughton opened 3 years ago

eileenmcnaughton commented 3 years ago

The advantage of Omnipay is it's possible to re-use the same code across multiple processors. However, Sagepay makes that quite tricky because is supports multiple methods and requires the integrator to have a pretty full understanding of them.

I'm wondering if Omnipay could respond more similarly to other processors by taking a queue from the context.

For example after calling

$gateway->purchase();

there is no getToken function to retrieve the json string that I could use to call repeatPurchase. However, it would be fairly easy for this function to be added & for it to return a json string that could be stored & later passed to repeatPurchase as a 'token' Further the purchase'function could actually call repeatPurchase if it is called with a token consistent with what repeatPurchase requires. Doing this would make it possible to use the same code for sagePay without understanding then inner workings (it would still be necessarly to know the initial call uses purchase`` rather thancreateCard'``` with ['action' => 'purchase'] as we are currently doing for other gateways but it would be close to compatible and that could be addressed too.)

I can try to work up a patch if you are open to it

eileenmcnaughton commented 3 years ago

Also another gotcha is that passing in an empty 'card' causes it to fail so

if ($card)

could check if any params are actually set....

judgej commented 3 years ago

Yes, that makes a lot of sense.

So:

Is that the gist of it?

There are also some unusual flags to "set token" and "store token" that need to be used in the request if yout want to be able to reuse a payment for repeat payments. I think "set token" allows a token that has been previously stored to be used, and "store token" sets a token for reuse in the current transaction. You need to kind of juggle the two, but setting "store token" to yes as a default has some security implications, in that every single transaction effectively becomes a repeatable transaction, which you don't really want unless the user has excplicitely agreed to it.

I'm a little rusty, so need to reed up on what the latest is, expecially since SagePay was purchased, and who knows what direction it will be going. I get the impression there is a tonne of technical debt in this gateway, and it will either have the tiniest of incremental changes, or will be replaced completely with a new system.

eileenmcnaughton commented 3 years ago

@judgej yep - that's pretty much the gist of it - I'll take a look since you seem open to it - I did put up #158 which is a bit tangential but part of the same thing

judgej commented 3 years ago

You caught that heavy-lifting word "assumption" on #158 ;-)

eileenmcnaughton commented 3 years ago

@judgej do you have any thoughts about the travis issues on #158 ?

judgej commented 3 years ago

Just looking at that, and much of it (as is often the case with travis) is above my head and I just end up poking it and seeing what happens. This looks like it could be worth trying: https://github.com/sebastianbergmann/php-code-coverage/issues/834#issuecomment-736337016

judgej commented 3 years ago

Also Barry is using php4snapshot here, which may help: https://github.com/thephpleague/omnipay-payfast/blob/master/.travis.yml However, I think the problem is only in December 2020's PHP releases, so it could be other drivers have not actually hit this problem yet, but will.

eileenmcnaughton commented 3 years ago

I looked at making it call repeatPurchase rather than purchase if cardReference is set but it seemed to work better to simply make purchase & authorize adapt their behaviour if it is a repeat. The code that figures that out is actually lower in the chain that they extend so it was pretty available to them. On the other hand repeatPurchase & repeatAuthorize don't share methods the others use so I felt that deprecating rather than changing them would work.

Also the task of determining which to call would need to be done in the gateway class - and it would not pick up . be able to respond if the setTransactionReference function were called after the initial construct.

eileenmcnaughton commented 3 years ago

I also opened this to raise the way 'confirm' is handled https://github.com/thephpleague/omnipay-common/issues/245

eileenmcnaughton commented 3 years ago

@judgej I'll look at the remaining bits & pieces in a couple of weeks if you get a chance to check out the PRs I've opened so far

judgej commented 3 years ago

Okay, thanks. I'll try to find some time this weekend. Just been unfeasibly busy this week.

eileenmcnaughton commented 3 years ago

@judgej fair enough ! (I'll be AFK from 19 to 27 Jan myself)