You should pass the transactionId back to yourself by using a custom returnUrl.
First, when you set up Worldpay:
- Log into your WorldPay Merchant Admin Interface
- Under Installations, click Setup next to your Installation ID
- In the Payment Response URL field, enter
<wpdisplay item=MC_callback>
- Make sure the Payment Response enabled? option is selected
Then, when you make the initial purchase request with Omnipay, pass a custom returnUrl
. For example:
$response = $gateway->purchase(array(
'amount' => '10.00',
'currency' => 'USD',
'returnUrl' => 'https://www.example.com/return?transactionId=123'
))->send();
That way, on your callback/return page, you can load the original transaction details before calling completePurchase()
:
$transaction = Transaction::find($_GET['transactionId']);
$response = $gateway->completePurchase(array(
'amount' => $transaction->amount,
'currency' => $transaction->currency,
))->send();