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

Plexo: Update Network Token implementation #5169

Merged
merged 1 commit into from
Jul 16, 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
49 changes: 39 additions & 10 deletions lib/active_merchant/billing/gateways/plexo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,48 @@ def add_invoice_number(post, options)
end

def add_payment_method(post, payment, options)
javierpedrozaing marked this conversation as resolved.
Show resolved Hide resolved
post[:paymentMethod] = {}
payment_method = build_payment_method(payment)

if payment&.is_a?(CreditCard)
post[:paymentMethod][:type] = 'card'
post[:paymentMethod][:Card] = {}
post[:paymentMethod][:Card][:Number] = payment.number
post[:paymentMethod][:Card][:ExpMonth] = format(payment.month, :two_digits) if payment.month
post[:paymentMethod][:Card][:ExpYear] = format(payment.year, :two_digits) if payment.year
post[:paymentMethod][:Card][:Cvc] = payment.verification_value if payment.verification_value
if payment_method.present?
add_card_holder(payment_method[:NetworkToken] || payment_method[:Card], payment, options)
post[:paymentMethod] = payment_method
end
end

add_card_holder(post[:paymentMethod][:Card], payment, options)
def build_payment_method(payment)
case payment
when NetworkTokenizationCreditCard
{
source: 'network-token',
id: payment.brand,
NetworkToken: {
Number: payment.number,
Bin: get_last_eight_digits(payment.number),
Last4: get_last_four_digits(payment.number),
ExpMonth: (format(payment.month, :two_digits) if payment.month),
ExpYear: (format(payment.year, :two_digits) if payment.year),
Cryptogram: payment.payment_cryptogram
}
}
when CreditCard
{
type: 'card',
Card: {
Number: payment.number,
ExpMonth: (format(payment.month, :two_digits) if payment.month),
ExpYear: (format(payment.year, :two_digits) if payment.year),
Cvc: payment.verification_value
}
}
end
post[:paymentMethod][:Card][:Cryptogram] = payment.payment_cryptogram if payment&.is_a?(NetworkTokenizationCreditCard)
end

def get_last_eight_digits(number)
number[-8..-1]
end

def get_last_four_digits(number)
number[-4..-1]
end

def add_card_holder(card, payment, options)
Expand Down
17 changes: 15 additions & 2 deletions test/remote/gateways/remote_plexo_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def setup
},
identification_type: '1',
identification_value: '123456',
billing_address: address
billing_address: address,
invoice_number: '12345abcde'
}

@cancel_options = {
Expand All @@ -41,10 +42,22 @@ def setup
month: '12',
year: Time.now.year
})

@decrypted_network_token = NetworkTokenizationCreditCard.new(
{
first_name: 'Joe', last_name: 'Doe',
brand: 'visa',
payment_cryptogram: 'UnVBR0RlYm42S2UzYWJKeWJBdWQ=',
number: '5555555555554444',
source: :network_token,
month: '12',
year: Time.now.year
}
)
end

def test_successful_purchase_with_network_token
response = @gateway.purchase(@amount, @network_token_credit_card, @options.merge({ invoice_number: '12345abcde' }))
response = @gateway.purchase(@amount, @decrypted_network_token, @options.merge({ invoice_number: '12345abcde' }))
assert_success response
assert_equal 'You have been mocked.', response.message
end
Expand Down
6 changes: 3 additions & 3 deletions test/unit/gateways/plexo_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ def test_purchase_with_network_token
assert_equal request['Amount']['Currency'], 'UYU'
assert_equal request['Amount']['Details']['TipAmount'], '5'
assert_equal request['Flow'], 'direct'
assert_equal @network_token_credit_card.number, request['paymentMethod']['Card']['Number']
assert_equal @network_token_credit_card.payment_cryptogram, request['paymentMethod']['Card']['Cryptogram']
assert_equal @network_token_credit_card.first_name, request['paymentMethod']['Card']['Cardholder']['FirstName']
assert_equal @network_token_credit_card.number, request['paymentMethod']['NetworkToken']['Number']
assert_equal @network_token_credit_card.payment_cryptogram, request['paymentMethod']['NetworkToken']['Cryptogram']
assert_equal @network_token_credit_card.first_name, request['paymentMethod']['NetworkToken']['Cardholder']['FirstName']
end.respond_with(successful_network_token_response)

assert_success purchase
Expand Down
Loading