Closed acarpio89 closed 6 years ago
@zburke any reason why STATUS == 0
is considered a successful payment by this library?
A decline might seem like a failed payment status, but it's a valid transaction status in the sense that there were no errors. Take a look at some other OmniPay libraries and see how they handle declines. If they treat it differently, I'd be happy to change it.
You're certainly right about using strlen
instead of count
. If you file that in a separate PR I'd be happy to merge it.
Thanks for the quick reply @zburke
After looking at a few popular omnipay repositories, I'll admit it's not exactly clear what's the meaning of isSuccessful()
. I do have a few examples where only authorized transactions seem to be considered successful:
https://github.com/thephpleague/omnipay-eway/blob/master/src/Message/DirectResponse.php
I use a few omnipay libraries and have always relied on isSuccessful
being false for declined transactions. Maybe that was an incorrect assumption, but this is certainly the first one I use that treats declined payments as successful. In your client code, how do you determine that payment was not declined? manually checking the code/error message? I've always thought that kind of decision is precisely what omnipay tries to encapsulate.
Check out a Stripe response for a declined transaction:
array:1 [▼
"error" => array:6 [▼
"charge" => "ch_1ChEgX2sGmU2F3r7oboSqryH"
"code" => "card_declined"
"decline_code" => "generic_decline"
"doc_url" => "https://stripe.com/docs/error-codes/card-declined"
"message" => "Your card was declined."
"type" => "card_error"
]
]
This is the omnipay/stripe implementation of isSuccesful:
public function isSuccessful()
{
return !isset($this->data['error']);
}
It returns false when a transaction is declined. No doubt about it.
Note that if we implemented isSuccessful()
strictly the same way as Stripe, i.e. "not an error", then declines would be treated as successful because BluePay does not necessarily consider a decline to be an error. So, Stripe considers a "decline" to be an error; BluePay does not.
The issue is what OmniPay is trying to capture with isSuccessful
: is it a boolean describing the presence/absence of errors, or a boolean describing whether a transaction was approved? Is there any guidance from OmniPay in their documentation about this?
Check out how BluePay's official library determines if a transaction was successful: https://github.com/BluePay/BluePay-Sample-Code/blob/7bad88513532e7314fafb84fe24d20e003fc8500/PHP/BluePay.php#L962
STATUS == DECLINED
may not be considered an error, but it definitely isn't successful.
Check out how BluePay's official library determines if a transaction was successful...
Alright; that's good enough for me.
There's two issues here:
count($data)
throws a warning in PHP 7.2.strlen($data)
seems more appropriate, as$data
can be cast into stringSTATUS == 0
means the transaction was declined. This library treats declined payments as successful.