Performing a Token Pre Authorization

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_preauth'
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:

    # response_register_card - successfull RegisterCard response
    token_preauth = Judopay::TokenPreauth.new(
      :your_consumer_reference => 'xxxxxxxxx',
      :your_payment_reference => 'xxxxxxxxx',
      :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 result

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

    result_token_preauth = token_preauth.create
    
    if result_token_preauth.result == 'Success'
        puts 'Preauth successful'
    else
        puts 'There were some problems while processing your preauth'
    end

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

{
  "receipt_id"=>"xxxxxxxxx",
  "your_payment_reference"=>"xxxxxxxxx",
  "type"=>"PreAuth",
  "created_at"=>"2016-09-26T09:42:12.1877+01:00",
  "result"=>"Success",
  "message"=>"xxxxxxxxx",
  "judo_id"=>'xxxxxxxxx',
  "merchant_name"=>"xxxxxxxxx",
  "appears_on_statement_as"=>"xxxxxxxxx",
  "original_amount"=>"5.01",
  "amount_collected"=>"0.00",
  "net_amount"=>"5.01",
  "amount"=>"5.01",
  "currency"=>"GBP",
  "card_details"=>{
    "card_lastfour"=>"3436",
    "end_date"=>"1220",
    "card_token"=>"xxxxxxxxx",
    "card_type"=>1
  },
  "consumer"=>{
    "consumer_token"=>"xxxxxxxxx",
    "your_consumer_reference"=>"xxxxxxxxx"
  }
}

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.