Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Credorax: Add recipient fields #4384

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lib/active_merchant/billing/gateways/credorax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -320,6 +321,15 @@ def add_email(post, options)
post[:c3] = options[:email] || '[email protected]'
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]
Expand Down
16 changes: 16 additions & 0 deletions test/remote/gateways/remote_credorax_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/unit/gateways/credorax_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')
Expand Down