Performing a Token Payment

ofetisov edited this page Jun 13, 2017 · 7 revisions

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

Include a model

Add model inclusion to your source code:

require 'judopay/models/token_payment'
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:

    # response_register_card - successfull RegisterCard response
    token_payment =
      :your_consumer_reference => 'xxxxxxxx',
      :your_payment_reference => 'xxxxxxxx',
      :amount => 5.01,
      :currency => 'GBP',
      :consumer_token => response_register_card.consumer.consumer_token,
      :card_token => response_register_card.card_details.card_token,
      :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:

    result_token_payment = token_payment.create
    if result_token_payment.result == 'Success'
        puts 'Token payment successful'
        puts 'There were some problems while processing your payment'

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


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.