-
Notifications
You must be signed in to change notification settings - Fork 4
Refund a Payment
Before you make a payment please check if your SDK is initialized.
To refund money you need to create and fill Refund model:
# result_payment - successful payment response
refund = Judopay::Refund.new(
:receipt_id => result_payment.receipt_id,
:your_payment_reference => 'xxxxxxxx',
:amount => 5.01
)You can check on the required fields and the format of each field in the Judopay REST API reference.
If you need to check a refund before actually processing you can send validate request and we'll perform our internal checks without sending it to consumer's bank.
validate_refund = refund.validate
if validate_refund.code == 20
puts 'Validation passed successfully.'
else
puts 'There were some problems while processing your request'
endPlease note we can only check the card payment against our own systems. Your payment may still be declined by your consumer's issuing bank.
And after that you need to send the request to the API. Your code will look like that:
result_refund = refund.create
if result_refund.result == 'Success'
puts 'Refund successful'
else
puts 'There were some problems while processing your refund'
endIf the refund is successful, you'll receive a response Mash like this:
{
"receipt_id"=>"xxxxxxx",
"original_receipt_id"=>"xxxxxxx",
"your_payment_reference"=>"xxxxxxx",
"type"=>"Refund",
"created_at"=>"2016-09-27T08:46:04.5466+01:00",
"result"=>"Success",
"message"=>"Refund successful",
"judo_id"=>'xxxxxxx',
"merchant_name"=>"xxxxxxx",
"appears_on_statement_as"=>"xxxxxxx",
"original_amount"=>"5.01",
"net_amount"=>"0.00",
"amount"=>"5.01",
"currency"=>"GBP",
"card_details"=>{
"card_lastfour"=>"3436",
"end_date"=>"1220",
"card_token"=>"xxxxxxx",
"card_type"=>1
},
"consumer"=>{
"consumer_token"=>"xxxxxxx",
"your_consumer_reference"=>"xxxxxxx"
}
}It is also important to handle different exceptions in your code. See our Error handling section.