Skip to content

Commit

Permalink
Authorize.net: truncate nameOnAccount for bank refunds
Browse files Browse the repository at this point in the history
The API specification requires that the string be no longer than 22 characters; refunds will fail if this limit is exceeded

CER-670

REMOTE
85 tests, 304 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

UNIT
122 tests, 688 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

LOCAL
5525 tests, 77482 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

760 files inspected, no offenses detected
  • Loading branch information
jcreiff committed Jun 15, 2023
1 parent 87ee551 commit 7fbffa0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

== HEAD
* Redsys: Add supported countries [jcreiff] #4811
* Authorize.net: Truncate nameOnAccount for bank refunds [jcreiff] #4808

== Version 1.130.0 (June 13th, 2023)
* Payu Latam - Update error code method to surface network code [yunnydang] #4773
Expand Down
2 changes: 1 addition & 1 deletion lib/active_merchant/billing/gateways/authorize_net.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def normal_refund(amount, authorization, options)
xml.accountType(options[:account_type])
xml.routingNumber(options[:routing_number])
xml.accountNumber(options[:account_number])
xml.nameOnAccount("#{options[:first_name]} #{options[:last_name]}")
xml.nameOnAccount(truncate("#{options[:first_name]} #{options[:last_name]}", 22))
end
else
xml.creditCard do
Expand Down
12 changes: 12 additions & 0 deletions test/remote/gateways/remote_authorize_net_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,18 @@ def test_successful_echeck_refund
assert_match %r{The transaction cannot be found}, refund.message, 'Only allowed to refund transactions that have settled. This is the best we can do for now testing wise.'
end

def test_successful_echeck_refund_truncates_long_account_name
check_with_long_name = check(name: 'Michelangelo Donatello-Raphael')
purchase = @gateway.purchase(@amount, check_with_long_name, @options)
assert_success purchase

@options.update(first_name: check_with_long_name.first_name, last_name: check_with_long_name.last_name, routing_number: check_with_long_name.routing_number,
account_number: check_with_long_name.account_number, account_type: check_with_long_name.account_type)
refund = @gateway.refund(@amount, purchase.authorization, @options)
assert_failure refund
assert_match %r{The transaction cannot be found}, refund.message, 'Only allowed to refund transactions that have settled. This is the best we can do for now testing wise.'
end

def test_failed_credit
response = @gateway.credit(@amount, @declined_card, @options)
assert_failure response
Expand Down
14 changes: 14 additions & 0 deletions test/unit/gateways/authorize_net_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,20 @@ def test_successful_bank_refund
assert_success response
end

def test_successful_bank_refund_truncates_long_name
response = stub_comms do
@gateway.refund(50, '12345667', account_type: 'checking', routing_number: '123450987', account_number: '12345667', first_name: 'Louise', last_name: 'Belcher-Williamson')
end.check_request do |_endpoint, data, _headers|
parse(data) do |doc|
assert_equal 'checking', doc.at_xpath('//transactionRequest/payment/bankAccount/accountType').content
assert_equal '123450987', doc.at_xpath('//transactionRequest/payment/bankAccount/routingNumber').content
assert_equal '12345667', doc.at_xpath('//transactionRequest/payment/bankAccount/accountNumber').content
assert_equal 'Louise Belcher-William', doc.at_xpath('//transactionRequest/payment/bankAccount/nameOnAccount').content
end
end.respond_with(successful_refund_response)
assert_success response
end

def test_refund_passing_extra_info
response = stub_comms do
@gateway.refund(50, '123456789', card_number: @credit_card.number, first_name: 'Bob', last_name: 'Smith', zip: '12345', order_id: '1', description: 'Refund for order 1')
Expand Down

0 comments on commit 7fbffa0

Please sign in to comment.