Performing a Token Pre Authorization

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

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

Create token pre-authorization

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

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

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 result

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

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

If the pre-authorization is successful, you'll receive a response array like this:

Array
(
    [receiptId] => xxxxxxxxx
    [yourPaymentReference] => 12345
    [type] => PreAuth
    [createdAt] => 2016-08-17T12:15:57.7752+01:00
    [result] => Success
    [message] => AuthCode: xxxxxxx
    [judoId] => xxxxxxxxxxx
    [merchantName] => xxxx
    [appearsOnStatementAs] => xxxxxxxx    
    [originalAmount] => 10.00
    [amountCollected] => 0.00
    [netAmount] => 10.00
    [amount] => 10.00
    [currency] => GBP
    [cardDetails] => Array
        (
            [cardLastfour] => 3436
            [endDate] => 1216
            [cardToken] => xxxxxxxxxxxxxxxxx
            [cardType] => 1
        )

    [consumer] => Array
        (
            [consumerToken] => xxxxxxxxxxxx
            [yourConsumerReference] => 12345
        )
)

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.