Question

I'm struggling with Omnipay and Sagepay Server. The Omnipay example code doesn't work with Sagepay Server as the final steps are completed by Sagepay and not the client, and as such can't access session data.

The transaction is registered:

$response = $this->gateway->purchase($params)->send();

The client is redirected to Sagepay:

$response->redirect();

The purchase should then be completed by Sagepay:

$gateway->completePurchase($params)->send();
$gateway->confirm(URL::to('checkout/complete'));

However, $params isn't set. I'm unsure get the transaction parameters details again without a session. Or if I cache $params, how the cache can be retrieved by Sagepay.

Any help will be very appreciated!

Thanks

Was it helpful?

Solution

You need to store the transaction details in your database before redirecting customers.

When you first create the transaction, store the id, amount, currency etc in your database, before calling $gateway->purchase(). You should also generate a unique token/slug for the transaction.

Then, you can set a custom returnUrl with the $params array. For example, you might set the return URL to https://www.example.com/checkout/complete/abcdef (where abcdef is the unique token for the current transaction).

Then, when SagePay calls your return URL, you can check the URL for a valid token, and load the transaction details. That way, you can regenerate the $params array with the correct amount from the original transaction.

For more information on designing the checkout flow, see Payment handling between requests.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top