Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong "isSuccessful" method implementation in PurchaseResponse class #37

Open
piotrfilipek opened this issue Sep 14, 2023 · 1 comment

Comments

@piotrfilipek
Copy link

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
Copy link
Member

mysiar commented Sep 29, 2023

PR more than welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants