Performing a Token Payment

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

Before you make a payment please check if your SDK is initialized

Create a token payment

To make a new token payment you need to have valid Card and Consumer Tokens. They could be obtained after any successful payment or card registration. To perform a token payment you need to put them in TokenPayment model:

    //$responseRegisterCard - successfull RegisterCard response
    $tokenPayment = $judopay->getModel('TokenPayment');
            'judoId' => 'your_judo_id',
            'yourConsumerReference' => 'xxxxxxxx',
            'yourPaymentReference' => 'xxxxxxxx',
            'amount' => 10.00,
            'currency' => 'GBP',
            'consumerToken' => $responseRegisterCard['consumer']['consumerToken'],
            'cardToken' => $responseRegisterCard['cardDetails']['cardToken'],
            'cv2' => 452

Note: Please make sure that the Consumer Reference used and the card token matches the ones used when the card token was originally generated. Remember to assign a unique payment reference for each payment requested.

You can check on the required fields and the format of each field in the Judopay REST API reference.

Check the payment result

And after that, you need to send the request to the API. Your code will look like that:

    $response = $tokenPayment->create();
    if ($response['result'] === 'Success') {
        echo 'Token payment successful';
    } else {
        echo 'There were some problems while processing your payment';

If the payment is successful, you'll receive a response array like this:

    [receiptId] => xxxxxxxx
    [yourPaymentReference] => xxxxxxx
    [type] => Payment
    [createdAt] => 2016-08-15T14:30:49.7126+01:00
    [result] => Success
    [message] => AuthCode: xxxxxxx
    [judoId] => xxxxxxx
    [merchantName] => xxxxxxx
    [appearsOnStatementAs] => xxxxxxx    
    [originalAmount] => 10.00
    [netAmount] => 10.00
    [amount] => 10.00
    [currency] => GBP
    [cardDetails] => Array
            [cardLastfour] => 3436
            [endDate] => 1216
            [cardToken] => xxxxxxxxx
            [cardType] => 1

    [consumer] => Array
            [consumerToken] => xxxxxxx
            [yourConsumerReference] => xxxxxx

It is also important to handle different exceptions in your code. See our Error handling section.

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.