Skip to content

Collecting on a Pre Authorization

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

Collecting a pre-auth requires that you have the receipt_id and amount of the pre-auth transaction. Before you make a payment please check if your SDK is initialized.

Creating a new collection

To collect a pre-auth funds you need to create and fill Collection model:

    # result_preauth - successful pre-authorization response    
    collection = Judopay::Collection.new(
        :receipt_id => result_preauth.receipt_id,
        :your_payment_reference => 'xxxxxx',
        :amount => 10.00
    )

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

Validating the collection

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

    validate_collection = collection.validate
    if validate_collection.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 collection result

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

    result_collection = collection.create
    
    if result_collection.result == 'Success'
        puts 'Successfully collected'
    else
        puts 'There were some problems while processing your collection'
    end

If the collection is successful, you'll receive a response array like this:

Mash
{
  "receipt_id"=>"xxxxxxxx",
  "original_receipt_id"=>"xxxxxxxx",
  "your_payment_reference"=>"xxxxxxxx",
  "type"=>"Collection",
  "created_at"=>"2016-09-21T09:36:37.3930+01:00",
  "result"=>"Success",
  "message"=>"Collection successful",
  "judo_id"=>'xxxxxxxx',
  "merchant_name"=>"xxxxxxxx",
  "appears_on_statement_as"=>"xxxxxxxx",
  "original_amount"=>"5.01",
  "net_amount"=>"5.01",
  "amount"=>"5.01",
  "currency"=>"GBP",
  "card_details"=>{
    "card_lastfour"=>"3436",
    "end_date"=>"1220",
    "card_token"=>"xxxxxxxx",
    "card_type"=>1
  },
  "consumer"=>{
    "consumer_token"=>"xxxxxxxx",
    "your_consumer_reference"=>"xxxxxxxx"
  }
}

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

Clone this wiki locally