diff --git a/CHANGELOG b/CHANGELOG index 4ff2598466e..4cf963f862c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -62,6 +62,7 @@ * Airwallex: QA fixes for address and create_setup_intent handling [therufs] #4377 * Airwallex: add `descriptor` field and update logic for sending `request_id` and `merchant_order_id` [dsmcclain] #4379 * Visanet Peru: use timestamp instead of random for purchaseNumber [therufs] #4093 +* Credorax: add `recipient_street_address`, `recipient_city`, `recipient_province_code`, and `recipient_country_code` fields [ajawadmirza] #4384 == Version 1.125.0 (January 20, 2022) * Wompi: support gateway [therufs] #4173 diff --git a/lib/active_merchant/billing/gateways/credorax.rb b/lib/active_merchant/billing/gateways/credorax.rb index e8cf9da7047..bf632dfa77b 100644 --- a/lib/active_merchant/billing/gateways/credorax.rb +++ b/lib/active_merchant/billing/gateways/credorax.rb @@ -193,6 +193,7 @@ def refund(amount, authorization, options = {}) add_submerchant_id(post, options) add_processor(post, options) add_email(post, options) + add_recipient(post, options) if options[:referral_cft] add_customer_name(post, options) @@ -320,6 +321,15 @@ def add_email(post, options) post[:c3] = options[:email] || 'unspecified@example.com' end + def add_recipient(post, options) + return unless options[:recipient_street_address] || options[:recipient_city] || options[:recipient_province_code] || options[:recipient_country_code] + + post[:j6] = options[:recipient_street_address] if options[:recipient_street_address] + post[:j7] = options[:recipient_city] if options[:recipient_city] + post[:j8] = options[:recipient_province_code] if options[:recipient_province_code] + post[:j9] = options[:recipient_country_code] if options[:recipient_country_code] + end + def add_customer_name(post, options) post[:j5] = options[:first_name] if options[:first_name] post[:j13] = options[:last_name] if options[:last_name] diff --git a/test/remote/gateways/remote_credorax_test.rb b/test/remote/gateways/remote_credorax_test.rb index 33027896f93..b64d32020f6 100644 --- a/test/remote/gateways/remote_credorax_test.rb +++ b/test/remote/gateways/remote_credorax_test.rb @@ -338,6 +338,22 @@ def test_successful_refund assert_equal 'Succeeded', refund.message end + def test_successful_refund_with_recipient_fields + response = @gateway.purchase(@amount, @credit_card, @options) + assert_success response + + refund_options = { + recipient_street_address: 'street', + recipient_city: 'chicago', + recipient_province_code: '312', + recipient_country_code: 'USA' + } + + refund = @gateway.refund(@amount, response.authorization, refund_options) + assert_success refund + assert_equal 'Succeeded', refund.message + end + def test_successful_refund_and_void response = @gateway.purchase(@amount, @credit_card, @options) assert_success response diff --git a/test/unit/gateways/credorax_test.rb b/test/unit/gateways/credorax_test.rb index 351ef9a336c..4d01aaae1af 100644 --- a/test/unit/gateways/credorax_test.rb +++ b/test/unit/gateways/credorax_test.rb @@ -152,6 +152,25 @@ def test_successful_refund assert_equal 'Succeeded', refund.message end + def test_successful_refund_with_recipient_fields + refund_options = { + recipient_street_address: 'street', + recipient_city: 'chicago', + recipient_province_code: '312', + recipient_country_code: 'USA' + } + refund = stub_comms do + @gateway.refund(@amount, '123', refund_options) + end.check_request do |_endpoint, data, _headers| + assert_match(/j6=street/, data) + assert_match(/j7=chicago/, data) + assert_match(/j8=312/, data) + assert_match(/j9=USA/, data) + end.respond_with(successful_refund_response) + + assert_success refund + end + def test_failed_refund response = stub_comms do @gateway.refund(nil, '')