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

Braintree: Remove stored credential v1 #5175

Merged
merged 1 commit into from
Jul 15, 2024
Merged
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 @@ -22,6 +22,7 @@
* MerchantWarrior: Update phone, email, ip and store ID [almalee24] #5158
* Credorax: Update 3DS version mapping [almalee24] #5159
* Add Maestro card bins [yunnydang] #5172
* Braintree: Remove stored credential v1 [almalee24] #5175

== Version 1.136.0 (June 3, 2024)
* Shift4V2: Add new gateway based on SecurionPay adapter [heavyblade] #4860
Expand Down
26 changes: 2 additions & 24 deletions lib/active_merchant/billing/gateways/braintree_blue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -912,18 +912,10 @@ def add_stored_credential_data(parameters, credit_card_or_vault_id, options)
return unless (stored_credential = options[:stored_credential])

add_external_vault(parameters, options)

if options[:stored_credentials_v2]
stored_credentials_v2(parameters, stored_credential)
else
stored_credentials_v1(parameters, stored_credential)
end
stored_credentials(parameters, stored_credential)
end

def stored_credentials_v2(parameters, stored_credential)
# Differences between v1 and v2 are
# initial_transaction + recurring/installment should be labeled {{reason_type}}_first
# unscheduled in AM should map to '' at BT because unscheduled here means not on a fixed timeline or fixed amount
def stored_credentials(parameters, stored_credential)
case stored_credential[:reason_type]
when 'recurring', 'installment'
if stored_credential[:initial_transaction]
Expand All @@ -940,20 +932,6 @@ def stored_credentials_v2(parameters, stored_credential)
end
end

def stored_credentials_v1(parameters, stored_credential)
if stored_credential[:initiator] == 'merchant'
if stored_credential[:reason_type] == 'installment'
parameters[:transaction_source] = 'recurring'
else
parameters[:transaction_source] = stored_credential[:reason_type]
end
elsif %w(recurring_first moto).include?(stored_credential[:reason_type])
parameters[:transaction_source] = stored_credential[:reason_type]
else
parameters[:transaction_source] = ''
end
end

def add_external_vault(parameters, options = {})
stored_credential = options[:stored_credential]
parameters[:external_vault] = {}
Expand Down
8 changes: 4 additions & 4 deletions test/remote/gateways/remote_braintree_blue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ def test_verify_credentials

def test_successful_recurring_first_stored_credential_v2
creds_options = stored_credential_options(:cardholder, :recurring, :initial)
response = @gateway.purchase(@amount, credit_card('4111111111111111'), @options.merge(stored_credential: creds_options, stored_credentials_v2: true))
response = @gateway.purchase(@amount, credit_card('4111111111111111'), @options.merge(stored_credential: creds_options))
assert_success response
assert_equal '1000 Approved', response.message
assert_not_nil response.params['braintree_transaction']['network_transaction_id']
Expand All @@ -1082,7 +1082,7 @@ def test_successful_recurring_first_stored_credential_v2

def test_successful_follow_on_recurring_first_cit_stored_credential_v2
creds_options = stored_credential_options(:cardholder, :recurring, id: '020190722142652')
response = @gateway.purchase(@amount, credit_card('4111111111111111'), @options.merge(stored_credential: creds_options, stored_credentials_v2: true))
response = @gateway.purchase(@amount, credit_card('4111111111111111'), @options.merge(stored_credential: creds_options))
assert_success response
assert_equal '1000 Approved', response.message
assert_not_nil response.params['braintree_transaction']['network_transaction_id']
Expand All @@ -1091,7 +1091,7 @@ def test_successful_follow_on_recurring_first_cit_stored_credential_v2

def test_successful_follow_on_recurring_first_mit_stored_credential_v2
creds_options = stored_credential_options(:merchant, :recurring, id: '020190722142652')
response = @gateway.purchase(@amount, credit_card('4111111111111111'), @options.merge(stored_credential: creds_options, stored_credentials_v2: true))
response = @gateway.purchase(@amount, credit_card('4111111111111111'), @options.merge(stored_credential: creds_options))
assert_success response
assert_equal '1000 Approved', response.message
assert_not_nil response.params['braintree_transaction']['network_transaction_id']
Expand All @@ -1100,7 +1100,7 @@ def test_successful_follow_on_recurring_first_mit_stored_credential_v2

def test_successful_one_time_mit_stored_credential_v2
creds_options = stored_credential_options(:merchant, id: '020190722142652')
response = @gateway.purchase(@amount, credit_card('4111111111111111'), @options.merge(stored_credential: creds_options, stored_credentials_v2: true))
response = @gateway.purchase(@amount, credit_card('4111111111111111'), @options.merge(stored_credential: creds_options))

assert_success response
assert_equal '1000 Approved', response.message
Expand Down
30 changes: 15 additions & 15 deletions test/unit/gateways/braintree_blue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ def test_stored_credential_recurring_cit_initial
external_vault: {
status: 'will_vault'
},
transaction_source: ''
transaction_source: 'recurring_first'
}
)
).returns(braintree_result)
Expand All @@ -1181,7 +1181,7 @@ def test_stored_credential_recurring_cit_used
status: 'vaulted',
previous_network_transaction_id: '123ABC'
},
transaction_source: ''
transaction_source: 'recurring'
}
)
).returns(braintree_result)
Expand All @@ -1197,7 +1197,7 @@ def test_stored_credential_prefers_options_for_ntid
status: 'vaulted',
previous_network_transaction_id: '321XYZ'
},
transaction_source: ''
transaction_source: 'recurring'
}
)
).returns(braintree_result)
Expand All @@ -1212,7 +1212,7 @@ def test_stored_credential_recurring_mit_initial
external_vault: {
status: 'will_vault'
},
transaction_source: 'recurring'
transaction_source: 'recurring_first'
}
)
).returns(braintree_result)
Expand Down Expand Up @@ -1243,7 +1243,7 @@ def test_stored_credential_installment_cit_initial
external_vault: {
status: 'will_vault'
},
transaction_source: ''
transaction_source: 'installment_first'
}
)
).returns(braintree_result)
Expand All @@ -1259,7 +1259,7 @@ def test_stored_credential_installment_cit_used
status: 'vaulted',
previous_network_transaction_id: '123ABC'
},
transaction_source: ''
transaction_source: 'installment'
}
)
).returns(braintree_result)
Expand All @@ -1274,7 +1274,7 @@ def test_stored_credential_installment_mit_initial
external_vault: {
status: 'will_vault'
},
transaction_source: 'recurring'
transaction_source: 'installment_first'
}
)
).returns(braintree_result)
Expand All @@ -1290,7 +1290,7 @@ def test_stored_credential_installment_mit_used
status: 'vaulted',
previous_network_transaction_id: '123ABC'
},
transaction_source: 'recurring'
transaction_source: 'installment'
}
)
).returns(braintree_result)
Expand Down Expand Up @@ -1387,7 +1387,7 @@ def test_stored_credential_v2_recurring_first_cit_initial
)
).returns(braintree_result)

@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credentials_v2: true, stored_credential: { initiator: 'merchant', reason_type: 'recurring_first', initial_transaction: true } })
@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credential: { initiator: 'merchant', reason_type: 'recurring_first', initial_transaction: true } })
end

def test_stored_credential_moto_cit_initial
Expand Down Expand Up @@ -1417,7 +1417,7 @@ def test_stored_credential_v2_recurring_first
)
).returns(braintree_result)

@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credentials_v2: true, stored_credential: stored_credential(:cardholder, :recurring, :initial) })
@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credential: stored_credential(:cardholder, :recurring, :initial) })
end

def test_stored_credential_v2_follow_on_recurring_first
Expand All @@ -1433,7 +1433,7 @@ def test_stored_credential_v2_follow_on_recurring_first
)
).returns(braintree_result)

@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credentials_v2: true, stored_credential: stored_credential(:merchant, :recurring, id: '123ABC') })
@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credential: stored_credential(:merchant, :recurring, id: '123ABC') })
end

def test_stored_credential_v2_installment_first
Expand All @@ -1448,7 +1448,7 @@ def test_stored_credential_v2_installment_first
)
).returns(braintree_result)

@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credentials_v2: true, stored_credential: stored_credential(:cardholder, :installment, :initial) })
@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credential: stored_credential(:cardholder, :installment, :initial) })
end

def test_stored_credential_v2_follow_on_installment_first
Expand All @@ -1464,7 +1464,7 @@ def test_stored_credential_v2_follow_on_installment_first
)
).returns(braintree_result)

@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credentials_v2: true, stored_credential: stored_credential(:merchant, :installment, id: '123ABC') })
@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credential: stored_credential(:merchant, :installment, id: '123ABC') })
end

def test_stored_credential_v2_unscheduled_cit_initial
Expand All @@ -1479,7 +1479,7 @@ def test_stored_credential_v2_unscheduled_cit_initial
)
).returns(braintree_result)

@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credentials_v2: true, stored_credential: stored_credential(:cardholder, :unscheduled, :initial) })
@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credential: stored_credential(:cardholder, :unscheduled, :initial) })
end

def test_stored_credential_v2_unscheduled_mit_initial
Expand All @@ -1494,7 +1494,7 @@ def test_stored_credential_v2_unscheduled_mit_initial
)
).returns(braintree_result)

@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credentials_v2: true, stored_credential: stored_credential(:merchant, :unscheduled, :initial) })
@gateway.purchase(100, credit_card('41111111111111111111'), { test: true, order_id: '1', stored_credential: stored_credential(:merchant, :unscheduled, :initial) })
end

def test_raises_exeption_when_adding_bank_account_to_customer_without_billing_address
Expand Down
Loading