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

BraintreeBlue: Support Apple Pay recurring #5248

Closed
wants to merge 1 commit into from
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
69 changes: 47 additions & 22 deletions lib/active_merchant/billing/gateways/braintree_blue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,9 @@ def add_payment_method(parameters, credit_card_or_vault_id, options)
if credit_card_or_vault_id.is_a?(NetworkTokenizationCreditCard)
case credit_card_or_vault_id.source
when :apple_pay
add_apple_pay(parameters, credit_card_or_vault_id)
add_apple_pay(parameters, credit_card_or_vault_id, options)
when :google_pay
add_google_pay(parameters, credit_card_or_vault_id)
add_google_pay(parameters, credit_card_or_vault_id, options)
else
add_network_tokenization_card(parameters, credit_card_or_vault_id)
end
Expand Down Expand Up @@ -991,29 +991,54 @@ def add_credit_card(parameters, payment_method)
}
end

def add_apple_pay(parameters, payment_method)
parameters[:apple_pay_card] = {
number: payment_method.number,
expiration_month: payment_method.month.to_s.rjust(2, '0'),
expiration_year: payment_method.year.to_s,
cardholder_name: payment_method.name,
cryptogram: payment_method.payment_cryptogram,
eci_indicator: payment_method.eci
}
def add_apple_pay(parameters, payment_method, options)
# parameters/params -> what we send to the gateway
# payment_method -> the data associated with the payment method
# options -> data provided by the caller (spreedly) to active merchant
if options.dig(:stored_credential, :initiator) == 'merchant'
parameters[:apple_pay_card] = {
number: payment_method.number,
expiration_month: payment_method.month.to_s.rjust(2, '0'),
expiration_year: payment_method.year.to_s,
cardholder_name: payment_method.name,
eci_indicator: payment_method.eci
}
else
parameters[:apple_pay_card] = {
number: payment_method.number,
expiration_month: payment_method.month.to_s.rjust(2, '0'),
expiration_year: payment_method.year.to_s,
cardholder_name: payment_method.name,
cryptogram: payment_method.payment_cryptogram,
eci_indicator: payment_method.eci
}
end
end

def add_google_pay(parameters, payment_method)
def add_google_pay(parameters, payment_method, options)
Braintree::Version::Major < 3 ? pay_card = :android_pay_card : pay_card = :google_pay_card
parameters[pay_card] = {
number: payment_method.number,
cryptogram: payment_method.payment_cryptogram,
expiration_month: payment_method.month.to_s.rjust(2, '0'),
expiration_year: payment_method.year.to_s,
google_transaction_id: payment_method.transaction_id,
source_card_type: payment_method.brand,
source_card_last_four: payment_method.last_digits,
eci_indicator: payment_method.eci
}
if options.dig(:stored_credential, :initiator) == 'merchant'
parameters[pay_card] = {
number: payment_method.number,
expiration_month: payment_method.month.to_s.rjust(2, '0'),
expiration_year: payment_method.year.to_s,
google_transaction_id: payment_method.transaction_id,
source_card_type: payment_method.brand,
source_card_last_four: payment_method.last_digits,
eci_indicator: payment_method.eci
}
else
parameters[pay_card] = {
number: payment_method.number,
cryptogram: payment_method.payment_cryptogram,
expiration_month: payment_method.month.to_s.rjust(2, '0'),
expiration_year: payment_method.year.to_s,
google_transaction_id: payment_method.transaction_id,
source_card_type: payment_method.brand,
source_card_last_four: payment_method.last_digits,
eci_indicator: payment_method.eci
}
end
end

def add_network_tokenization_card(parameters, payment_method)
Expand Down
40 changes: 39 additions & 1 deletion test/unit/gateways/braintree_blue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1052,13 +1052,51 @@ def test_apple_pay_card
brand: 'visa',
transaction_id: '123',
eci: '05',
payment_cryptogram: '111111111100cryptogram'
payment_cryptogram: '111111111100cryptogram',
source: :apple_pay
)

response = @gateway.authorize(100, credit_card, test: true, order_id: '1')
assert_equal 'transaction_id', response.authorization
end

def test_apple_pay_card_recurring
Braintree::TransactionGateway.any_instance.expects(:sale).
with(
amount: '1.00',
order_id: '1',
customer: { id: nil, email: nil, phone: nil,
first_name: 'Longbob', last_name: 'Longsen' },
options: { store_in_vault: false, submit_for_settlement: nil, hold_in_escrow: nil },
custom_fields: nil,
apple_pay_card: {
number: '4111111111111111',
expiration_month: '09',
expiration_year: (Time.now.year + 1).to_s,
cardholder_name: 'Longbob Longsen',
eci_indicator: '05'
},
external_vault: {
status: 'vaulted',
previous_network_transaction_id: '123ABC'
},
transaction_source: 'recurring'
).
returns(braintree_result(id: 'transaction_id'))

apple_pay = network_tokenization_credit_card(
'4111111111111111',
brand: 'visa',
transaction_id: '123',
eci: '05',
payment_cryptogram: '111111111100cryptogram',
source: :apple_pay
)

response = @gateway.authorize(100, apple_pay, { test: true, order_id: '1', stored_credential: stored_credential(:merchant, :recurring, id: '123ABC') })
assert_equal 'transaction_id', response.authorization
end

def test_google_pay_card
Braintree::TransactionGateway.any_instance.expects(:sale).
with(
Expand Down
Loading