Question

When processing a callback from a WorldPay transaction, what is the best way to retrieve the original transactionId that was passed to Omnipay?

This would be needed to update the appropriate database record with the result of the transaction, for instance.

I can see that there is a getTransactionReference() method available on the response, but not a getTransactionId() method (which would presumably access the 'cartId' value returned by WorldPay).

I'm guessing that the cartId value could be accessed directly, but is there a gateway-agnostic way to do this?

Was it helpful?

Solution

You should pass the transactionId back to yourself by using a custom returnUrl.

First, when you set up Worldpay:

  1. Log into your WorldPay Merchant Admin Interface
  2. Under Installations, click Setup next to your Installation ID
  3. In the Payment Response URL field, enter <wpdisplay item=MC_callback>
  4. 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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top