Skip to content

Commit

Permalink
Braintree Blue: add graceul failure if zipcode is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
yunnydang committed Jun 12, 2024
1 parent e282efb commit 32e4da3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Braintree: Prefer options for network_transaction_id [aenand] #5129
* Cybersource Rest: Update support for stored credentials [aenand] #5083
* Plexo: Add support to NetworkToken payments [euribe09] #5130
* Braintree: Update card verfification payload if billing address fields are not present [yunnydang] #5142

== Version 1.136.0 (June 3, 2024)
* Shift4V2: Add new gateway based on SecurionPay adapter [heavyblade] #4860
Expand Down
13 changes: 9 additions & 4 deletions lib/active_merchant/billing/gateways/braintree_blue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,21 @@ def verify(creditcard, options = {})
exp_month = creditcard.month.to_s
exp_year = creditcard.year.to_s
expiration = "#{exp_month}/#{exp_year}"
zip = options[:billing_address].try(:[], :zip)
address1 = options[:billing_address].try(:[], :address1)
payload = {
credit_card: {
number: creditcard.number,
expiration_date: expiration,
cvv: creditcard.verification_value,
billing_address: {
postal_code: options[:billing_address][:zip]
}
cvv: creditcard.verification_value
}
}
if zip || address1
payload[:credit_card][:billing_address] = {}
payload[:credit_card][:billing_address][:postal_code] = zip if zip
payload[:credit_card][:billing_address][:street_address] = address1 if address1
end

if merchant_account_id = (options[:merchant_account_id] || @merchant_account_id)
payload[:options] = { merchant_account_id: merchant_account_id }
end
Expand Down
48 changes: 48 additions & 0 deletions test/remote/gateways/remote_braintree_blue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,54 @@ def test_successful_credit_card_verification
assert response = @gateway.verify(card, @options.merge({ allow_card_verification: true, merchant_account_id: fixtures(:braintree_blue)[:merchant_account_id] }))
assert_success response

assert_match 'OK', response.message
assert_equal 'M', response.cvv_result['code']
assert_equal 'M', response.avs_result['code']
end

def test_successful_credit_card_verification_without_billing_address
options = {
order_ID: '1',
description: 'store purchase'
}
card = credit_card('4111111111111111')
assert response = @gateway.verify(card, options.merge({ allow_card_verification: true, merchant_account_id: fixtures(:braintree_blue)[:merchant_account_id] }))
assert_success response

assert_match 'OK', response.message
assert_equal 'M', response.cvv_result['code']
assert_equal 'I', response.avs_result['code']
end

def test_successful_credit_card_verification_with_only_address
options = {
order_ID: '1',
description: 'store purchase',
billing_address: {
address1: '456 My Street'
}
}
card = credit_card('4111111111111111')
assert response = @gateway.verify(card, options.merge({ allow_card_verification: true, merchant_account_id: fixtures(:braintree_blue)[:merchant_account_id] }))
assert_success response

assert_match 'OK', response.message
assert_equal 'M', response.cvv_result['code']
assert_equal 'B', response.avs_result['code']
end

def test_successful_credit_card_verification_with_only_zip
options = {
order_ID: '1',
description: 'store purchase',
billing_address: {
zip: 'K1C2N6'
}
}
card = credit_card('4111111111111111')
assert response = @gateway.verify(card, options.merge({ allow_card_verification: true, merchant_account_id: fixtures(:braintree_blue)[:merchant_account_id] }))
assert_success response

assert_match 'OK', response.message
assert_equal 'M', response.cvv_result['code']
assert_equal 'P', response.avs_result['code']
Expand Down

0 comments on commit 32e4da3

Please sign in to comment.