mysiar-org / omnipay-przelewy24v1

Przelewy24 API v1 driver for the Omnipay payment processing library
MIT License
5 stars 3 forks source link

Wrong "isSuccessful" method implementation in PurchaseResponse class #37

Open piotrfilipek opened 1 year ago

piotrfilipek commented 1 year ago

Description Hi, I'm using your gateway and I think I found a bug in isSuccessful method. Documentation isn't say directly how to implement it, but some examples and other omnipay drivers show that isSuccessful is always true only when payment was processed successfully. If you create a new purchase and you recive a redirect URL then your payment isn't proceed successfully yet, because you need to redirect off-site to complete the purchase. In this case you should return false, but you return true, what is wrong.
The isSuccessful method should rely on the token you received instead of the HTTP status code.

PayPal Express example:

/*
 * Is this complete purchase response successful? Will not be successful if it's a redirect response.
 *
 * @return bool
 */
public function isSuccessful()
{
    $success = isset($this->data['ACK']) && in_array($this->data['ACK'], array('Success', 'SuccessWithWarning'));
    return !$this->isRedirect() && $success;
}

Mollie example:

/**
 * When you do a `purchase` the request is never successful because
 * you need to redirect off-site to complete the purchase.
 *
 * {@inheritdoc}
 */
public function isSuccessful()
{
    return false;
}

Even example from the Omnipay documentation shows that we should rely on the token in this case:

$response = $gateway->purchase(['amount' => '10.00', 'card' => $card])->send();
if ($response->isSuccessful()) {
    // payment is complete
} elseif ($response->isRedirect()) {
    $response->redirect(); // this will automatically forward the customer
} else {
    // not successful
}

How to reproduce
Each purchase method calling

Possible Solution
Start to rely on the received data instead of the HTTP status codes.

mysiar commented 1 year ago

PR more than welcome