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.