0

I am using Omnipay to allow users to pay using Cardsave.

I have the following:

    \Omnipay::setTestMode(true);

    $transactionId = date('YmdHis').$booking->space->id.$booking->user->id;


    $response = $gateway->purchase([
        'amount' => $booking->price,
        'currency' => 'GBP',
        'card' => $card,
        'transactionId' => $transactionId,
        'cancelUrl' => \base_url('cardsave/cancel/'.$booking->id),
        'returnUrl' => \base_url('cardsave/confirm/'.$booking->id)
    ])->send();

    if ($response->isSuccessful()) {
        $transactionReference = $response->getTransactionReference();

        //save the transaction reference in case of refund

        return ['status' => 'success', 'message' => 'Reservation process complete'];
    } elseif ($response->isRedirect()) {
        \Log::info('3DSecure redirect');

        $booking->addAdditional(['3dsecure_transaction_id' => $transactionId]);

        return [
            'status' => 'redirect',
            'form_html' => $response->getRedirectResponse()->getContent()
        ];
    }
    throw new PaymentException ($response->getMessage());

and my confirm url goes to the following method:

    $transactionId = $booking->getAdditional('3dsecure_transaction_id');

    $response = $gateway->completePurchase([
        'amount' => $amount,
        'transactionId' => $transactionId,
        'currency' => 'GBP',
    ])->send();

    if ($response->isSuccessful()) {
        $transactionReference = $response->getTransactionReference();

        return $this->finalise($booking, $transactionReference);
    } else {
        $this->cancel($booking);
    }

But looking through the code for league/omnipay-cardsave, I see the following:

    $md = $this->httpRequest->request->get('MD');
    $paRes = $this->httpRequest->request->get('PaRes');
    if (empty($md) || empty($paRes)) {
        throw new InvalidResponseException;
    }

So my question is (and I realise it is probably dumb, but I can't seem to grok this, for some reason), where is that request coming from, if I just instantiated the gateway?

I think I am doing this wrong.

EDIT:

I have discovered that the return call from the 3DSecure thing comes with the MD and PaRes values as POST parameters. This allows me to set them on the gateway. How do I do that? Is it done automatically when I instantiate the gateway?

Tom Macdonald
  • 6,433
  • 7
  • 39
  • 59

1 Answers1

0

I was right, the question was dumb.

After reading the code, and trying it out, I found out that the AbstractGateway uses Symfony's request class to automatically pickup POST variables, amongst which are in this case, 'MD' and 'PaRes'.

In fact, it says so in the CompletePurchase class:

$md = $this->httpRequest->request->get('MD');
$paRes = $this->httpRequest->request->get('PaRes');

httpRequest is setup in AbstractGateway.

Basically, it just works.

Tom Macdonald
  • 6,433
  • 7
  • 39
  • 59