Skip to content

Performing a Token Payment

Oleg Fetisov edited this page Sep 27, 2016 · 3 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:

    # response_register_card - successfull RegisterCard response
    token_payment = Judopay::TokenPayment.new(
      :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'
    )

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'
    else
        puts 'There were some problems while processing your payment'
    end

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

{
  "receipt_id"=>"xxxxxxxxxxxxxx",
  "your_payment_reference"=>"xxxxxxxxxxxxxx",
  "type"=>"Payment",
  "created_at"=>"2016-09-26T09:35:41.2303+01:00",
  "result"=>"Success",
  "message"=>"xxxxxxxxxxxxxx",
  "judo_id"=>"xxxxxxxxxxxxxx",
  "merchant_name"=>"xxxxxxxxxxxxxx",
  "appears_on_statement_as"=>"xxxxxxxxxxxxxx",
  "original_amount"=>"5.01",
  "net_amount"=>"5.01",
  "amount"=>"5.01",
  "currency"=>"GBP",
  "card_details"=>{
    "card_lastfour"=>"3436",
    "end_date"=>"1220",
    "card_token"=>"xxxxxxxxxxxxxx",
    "card_type"=>1
  },
  "consumer"=>{
    "consumer_token"=>"xxxxxxxxxxxxxx",
    "your_consumer_reference"=>"xxxxxxxx"
  }
}

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

Clone this wiki locally