Making a WebPayment

Albert Mata edited this page Oct 11, 2016 · 4 revisions

JudoResponsive allows you to easily accept card payments within your WebApp. judoResponsive supports both desktop and mobile devices and make your PCI-DSS compliance easier. It also includes additional card holder verification using Post-code verification and 3D secure.

Configuration Checklist

  • You need to configure the "Success" and "Cancel" urls for your application and as it might be expected the app will return the success url if the payment is successful and the cancel url if the payment is aborted.
  • Your API token needs to have the permissions to "create" web payments, you can edit these permissions on the application configuration screen within our merchant dashboard

Provisioning the web payment

Before you can send your user to the judo payment page, you'll need to tell us the details of the web payment using our JudoPay API. Support for this is built into our PHP SDK:

// Create the JudoPay client, populate the api token and api secret with the 
// details from the application you created on our 
$judopay = new \Judopay(
	array(
        'apiToken' => 'your-token',
        'apiSecret' => 'your-secret',
        'judoId' => 'your-judo-id'
	)
);

// create an instance of the WebPayment Payment model (or you can use the Preauth model) 
// if you only want to process a pre-authorisation which you can collect later.
$payment = $judopay->getModel('WebPayments\Payment');

// populate the required data fields.
$payment->setAttributeValues(
    array(
        'judoId' => 'your_judo_id',
        'yourConsumerReference' => 'xxxxxxx',
        'yourPaymentReference' => 'xxxxxx',
        'amount' => 10.00,
        'currency' => 'GBP',
        'clientIpAddress' => '127.0.0.1',
        'clientUserAgent' => 'Their browser user agent/11.0',
    )
);

// Send the model to the JudoPay API, this provisions your webpayment and returns a unique reference along with the 
// URL of the page you'll need to dispatch your users to.

$webpaymentDetails = $payment->create();

/*
* Here's an example of the json returned, this is mapped into an Array.
* {
* postUrl: https://pay.judopay-sandbox.com/v1,
* reference: "3gcAAAoAAAAXAAAACQAAAMYG6P4SW.....CCc3iT-3tn5_RyWnmArDZAwyEkwQ"
* }
*/

$theWebPaymentReference = $webpaymentDetails["reference"]
$formPostUrl = $webpaymentDetails["postUrl"]

Note: Please make sure that you are using a unique Consumer Reference for each different consumer, and a unique Payment Reference for each transaction.

Dispatching your user to judo

You should then dispatch your user to our server using a POST request, this can be done easily by wrapping your "Pay Now" button in a form as follows:

	<form action="<?php echo $formPostUrl;?>" method="post">
	<input  id="Reference" name="Reference" type="hidden" value="<?php echo $theWebPaymentReference;?>">
	<input type="submit" value="Pay now">
	</form>

Capturing the returned information

Whether payment was successful system returns to pre-configured success url using a POST request. Included in this POST request are the following form fields :

Reference - this is our reference for the web payment.

ReceiptId - this is our reference number for the JudoPay API transaction.

CardToken - this is the unique reference for your user's card. If you want to process further payments on their card (either as a "saved card" feature, or a reoccuring subscription payment), you must capture this card token.

Please note that you cannot retreive the CardToken later, if you wish to use this card in a future payment (i.e. Pay with your saved card) you will need to capture and store this value.

Verifying the payment

Finally you should always verify the payment outcome using the JudoPay API, this will protect you from the request tampering.

// Create an instance of the WebPayment Transaction model (as web payments can either be payments or preauths we have a superclass called transaction). 

$existingTransactionRequest = $judopay->getModel('WebPayments\Transaction');


// invoke the find method passing in the reference you obtained above. 
$transactionDetails = $existingTransactionRequest->find($theWebPaymentReference);

// check the value of the "status" array key to confirm the payment was successful
$webpaymentStatus = $transactionDetails["status"];

// webpaymentStatus should be "Success"

// you can also access a copy of our receipt object using the "receipt" entry.

$receipt = $transactionDetails["receipt"];
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.