Skip to content

Performing a Payment

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

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

Create a payment

To make a new payment with full card details:

payment = Judopay::CardPayment.new(
  :judoId => 'your_judo_id',
  :your_consumer_reference => 'xxxxxxxx',
  :your_payment_reference => 'xxxxxxxx',
  :amount => 5.01,
  :currency => 'GBP',
  :card_number => '4976000000003436',
  :expiry_date => '12/20',
  :cv2 => '452',
  :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 payment

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

    validate_payment = payment.validate
    if validate_payment.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 payment result

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

    result_payment = payment.create    
    if result_payment.result == 'Success'
        puts 'Payment successful'
    else
        puts 'There were some problems while processing your payment'
    end

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

{
  "receipt_id"=>"xxxxxxx",
  "your_payment_reference"=>"xxxxxxx",
  "type"=>"Payment",
  "created_at"=>"2016-09-23T09:28:47.1207+01:00",
  "result"=>"Success",
  "message"=>"xxxxxxx",
  "judo_id"=>'xxxxxxx',
  "merchant_name"=>"xxxxxxx",
  "appears_on_statement_as"=>"xxxxxxx",
  "original_amount"=>"5.01",
  "net_amount"=>"5.01",
  "amount"=>"5.01",
  "currency"=>"GBP",
  "card_details"=>{
    "card_lastfour"=>"3436",
    "end_date"=>"1220",
    "card_token"=>"xxxxxxxxxxxxxxxxxxxxx",
    "card_type"=>1
  },
  "consumer"=>{
    "consumer_token"=>"xxxxxxxxxxxxxxxxxxxxx",
    "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