Skip to content

Performing a Pre Authorization

Oleg Fetisov edited this page Sep 27, 2016 · 2 revisions

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

Create pre-authorization

To make a new pre-authorization with full card details:

preauth = Judopay::CardPreauth.new(
  :your_consumer_reference => 'xxxxxxxx',
  :your_payment_reference => 'xxxxxxxx',
  :amount => 5.01,
  :card_number => '4976000000003436',
  :expiry_date => '12/20',
  :cv2 => '452',
  :currency => 'GBP',
  :card_address => {
    :line1 => '32 Edward Street',
    :town => 'Camborne',
    :postcode => 'TR14 8PA'
  },
  :consumer_location => {
    :latitude => 51.5033630,
    :longitude => -0.1276250
  }
)

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

Validating the pre-authorization

If you need to check a pre-authorization before actually processing you can send validate request and we'll perform our internal checks without sending it to the consumer's bank.

    validate_preauth = preauth.validate
    if validate_preauth.code == 20
        puts 'Validation passed successfully.'
    else
        puts 'There were some problems while processing your request'
    end

Please note we can only check the card payment against our own systems. Your payment may still be declined by your consumer's issuing bank.

Check the pre-authorization result

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

    result_preauth = preauth.create
    
    if result_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 array like this:

{
  "receipt_id"=>"xxxxxxxxxxx",
  "your_payment_reference"=>"xxxxxxxx",
  "type"=>"PreAuth",
  "created_at"=>"2016-09-23T09:34:43.2486+01:00",
  "result"=>"Success",
  "message"=>"xxxxxxxxxxx",
  "judo_id"=>"xxxxxxxxxxx",
  "merchant_name"=>"xxxxxxxxxxx",
  "appears_on_statement_as"=>"xxxxxxxxxxx",
  "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"=>"xxxxxxxxxxx",
    "card_type"=>1
  },
  "consumer"=>{
    "consumer_token"=>"xxxxxxxxxxx",
    "your_consumer_reference"=>"xxxxxxxx"
  },
  "risks"=>{
    "post_code_check"=>"PASSED"
  }
}

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

Clone this wiki locally