Skip to content

Commit

Permalink
Braintree Blue: Support Level 2 and 3 data fields
Browse files Browse the repository at this point in the history
Also refactors create_transaction_parameters for length.

Closes activemerchant#3094

Remote:
68 tests, 384 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Unit:
57 tests, 150 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
  • Loading branch information
curiousepic authored and whitby3001 committed Sep 3, 2019
1 parent 263dad7 commit d566f84
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Adyen: Pass arbitrary riskData fields [curiousepic] #3089
* Worldpay: Fix cookie header name [curiousepic] #3099
* Paymentez: Adds support for extra_params optional field [molbrown] #3095
* Braintree Blue: Support Level 2 and 3 data fields [curiousepic] #3094

== Version 1.89.0 (December 17, 2018)
* Worldpay: handle Visa and MasterCard payouts differently [bpollack] #3068
Expand Down
72 changes: 49 additions & 23 deletions lib/active_merchant/billing/gateways/braintree_blue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ def response_code_from_result(result)

def create_transaction(transaction_type, money, credit_card_or_vault_id, options)
transaction_params = create_transaction_parameters(money, credit_card_or_vault_id, options)

commit do
result = @braintree_gateway.transaction.send(transaction_type, transaction_params)
response = Response.new(result.success?, message_from_transaction_result(result), response_params(result), response_options(result))
Expand Down Expand Up @@ -588,6 +589,54 @@ def create_transaction_parameters(money, credit_card_or_vault_id, options)
parameters[:recurring] = true
end

add_payment_method(parameters, credit_card_or_vault_id, options)

parameters[:billing] = map_address(options[:billing_address]) if options[:billing_address]
parameters[:shipping] = map_address(options[:shipping_address]) if options[:shipping_address]

channel = @options[:channel] || application_id
parameters[:channel] = channel if channel

if options[:descriptor_name] || options[:descriptor_phone] || options[:descriptor_url]
parameters[:descriptor] = {
name: options[:descriptor_name],
phone: options[:descriptor_phone],
url: options[:descriptor_url]
}
end

if options[:three_d_secure]
parameters[:three_d_secure_pass_thru] = {
cavv: options[:three_d_secure][:cavv],
eci_flag: options[:three_d_secure][:eci],
xid: options[:three_d_secure][:xid],
}
end

parameters[:tax_amount] = options[:tax_amount] if options[:tax_amount]
parameters[:tax_exempt] = options[:tax_exempt] if options[:tax_exempt]
parameters[:purchase_order_number] = options[:purchase_order_number] if options[:purchase_order_number]

parameters[:shipping_amount] = options[:shipping_amount] if options[:shipping_amount]
parameters[:discount_amount] = options[:discount_amount] if options[:discount_amount]
parameters[:ships_from_postal_code] = options[:ships_from_postal_code] if options[:ships_from_postal_code]

if options[:line_items]
items = []
options[:line_items].each do |line_item|
item = {}
line_item.each do |key, value|
item[key.to_sym] = value
end
items << item
end
parameters[:line_items] = items
end

parameters
end

def add_payment_method(parameters, credit_card_or_vault_id, options)
if credit_card_or_vault_id.is_a?(String) || credit_card_or_vault_id.is_a?(Integer)
if options[:payment_method_token]
parameters[:payment_method_token] = credit_card_or_vault_id
Expand Down Expand Up @@ -634,29 +683,6 @@ def create_transaction_parameters(money, credit_card_or_vault_id, options)
}
end
end
parameters[:billing] = map_address(options[:billing_address]) if options[:billing_address]
parameters[:shipping] = map_address(options[:shipping_address]) if options[:shipping_address]

channel = @options[:channel] || application_id
parameters[:channel] = channel if channel

if options[:descriptor_name] || options[:descriptor_phone] || options[:descriptor_url]
parameters[:descriptor] = {
name: options[:descriptor_name],
phone: options[:descriptor_phone],
url: options[:descriptor_url]
}
end

if options[:three_d_secure]
parameters[:three_d_secure_pass_thru] = {
cavv: options[:three_d_secure][:cavv],
eci_flag: options[:three_d_secure][:eci],
xid: options[:three_d_secure][:xid],
}
end

parameters
end
end
end
Expand Down
45 changes: 45 additions & 0 deletions test/remote/gateways/remote_braintree_blue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,51 @@ def test_successful_purchase_using_card_token
assert_equal 'submitted_for_settlement', response.params['braintree_transaction']['status']
end

def test_successful_purchase_with_level_2_data
assert response = @gateway.purchase(@amount, @credit_card, @options.merge(:tax_amount => '20', :purchase_order_number => '6789'))
assert_success response
assert_equal '1000 Approved', response.message
end

def test_successful_purchase_with_level_2_and_3_data
options = {
:tax_amount => '20',
:purchase_order_number => '6789',
:shipping_amount => '300',
:discount_amount => '150',
:ships_from_postal_code => '90210',
:line_items => [
{
:name => 'Product Name',
:kind => 'debit',
:quantity => '10.0000',
:unit_amount => '9.5000',
:unit_of_measure => 'unit',
:total_amount => '95.00',
:tax_amount => '5.00',
:discount_amount => '0.00',
:product_code => '54321',
:commodity_code => '98765'
},
{
:name => 'Other Product Name',
:kind => 'debit',
:quantity => '1.0000',
:unit_amount => '2.5000',
:unit_of_measure => 'unit',
:total_amount => '90.00',
:tax_amount => '2.00',
:discount_amount => '1.00',
:product_code => '54322',
:commodity_code => '98766'
}
]
}
assert response = @gateway.purchase(@amount, @credit_card, @options.merge(options))
assert_success response
assert_equal '1000 Approved', response.message
end

def test_successful_verify
assert response = @gateway.verify(@credit_card, @options)
assert_success response
Expand Down

0 comments on commit d566f84

Please sign in to comment.