Skip to content

Commit

Permalink
Plexo: Add support to NetworkToken payments
Browse files Browse the repository at this point in the history
SER-140

adding support to make purchase, authorize transaction using network tokens in plexo gateway

Test summary:
Local:
5910 tests, 79650 assertions, 0 failures, 17 errors, 0 pendings, 0 omissions, 0 notifications
99.7124% passed
Unit:
25 tests, 134 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
Remote:
32 tests, 36 assertions, 21 failures, 3 errors, 0 pendings, 3 omissions, 0 notifications
17.2414% passed
  • Loading branch information
edgarv09 committed Jun 6, 2024
1 parent 6d0d996 commit d49571e
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Worldpay: Prefer options for network_transaction_id [aenand] #5129
* 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

== Version 1.136.0 (June 3, 2024)
* Shift4V2: Add new gateway based on SecurionPay adapter [heavyblade] #4860
Expand Down
4 changes: 3 additions & 1 deletion lib/active_merchant/billing/gateways/plexo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def scrub(transcript)
gsub(%r(("Number\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
gsub(%r(("Cvc\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
gsub(%r(("InvoiceNumber\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
gsub(%r(("MerchantId\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]')
gsub(%r(("MerchantId\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
gsub(%r(("Cryptogram\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]')
end

private
Expand Down Expand Up @@ -207,6 +208,7 @@ def add_payment_method(post, payment, options)

add_card_holder(post[:paymentMethod][:Card], payment, options)
end
post[:paymentMethod][:Card][:Cryptogram] = payment.payment_cryptogram if payment&.is_a?(NetworkTokenizationCreditCard)
end

def add_card_holder(card, payment, options)
Expand Down
16 changes: 16 additions & 0 deletions test/remote/gateways/remote_plexo_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ def setup
description: 'Test desc',
reason: 'requested by client'
}

@network_token_credit_card = ActiveMerchant::Billing::NetworkTokenizationCreditCard.new({
first_name: 'Santiago', last_name: 'Navatta',
brand: 'Mastercard',
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' }))
assert_success response
assert_equal 'You have been mocked.', response.message
end

def test_successful_purchase
Expand Down
154 changes: 154 additions & 0 deletions test/unit/gateways/plexo_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ def setup
@amount = 100
@credit_card = credit_card('5555555555554444', month: '12', year: '2024', verification_value: '111', first_name: 'Santiago', last_name: 'Navatta')
@declined_card = credit_card('5555555555554445')
@network_token_credit_card = ActiveMerchant::Billing::NetworkTokenizationCreditCard.new({
first_name: 'Santiago', last_name: 'Navatta',
brand: 'Mastercard',
payment_cryptogram: 'UnVBR0RlYm42S2UzYWJKeWJBdWQ=',
number: '5555555555554444',
source: :network_token,
month: '12',
year: 2020
})
@options = {
email: '[email protected]',
ip: '127.0.0.1',
Expand Down Expand Up @@ -329,6 +338,23 @@ def test_scrub
assert_equal @gateway.scrub(pre_scrubbed), post_scrubbed
end

def test_purchase_with_network_token
purchase = stub_comms do
@gateway.purchase(@amount, @network_token_credit_card, @options)
end.check_request do |_endpoint, data, _headers|
request = JSON.parse(data)
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']
end.respond_with(successful_network_token_response)

assert_success purchase
assert_equal 'You have been mocked.', purchase.message
end

private

def pre_scrubbed
Expand Down Expand Up @@ -917,4 +943,132 @@ def failed_verify_response
}
RESPONSE
end

def successful_network_token_response
<<~RESPONSE
{
"id": "71d4e94a30124a7ba00809c00b7b1149",
"referenceId": "ecca673a4041317aec64e9e823b3c5d9",
"invoiceNumber": "12345abcde",
"status": "approved",
"flow": "direct",
"processingMethod": "api",
"browserDetails": {
"ipAddress": "127.0.0.1"
},
"createdAt": "2024-05-21T20:18:33.072Z",
"updatedAt": "2024-05-21T20:18:33.3896406Z",
"processedAt": "2024-05-21T20:18:33.3896407Z",
"merchant": {
"id": 3243,
"name": "spreedly",
"settings": {
"merchantIdentificationNumber": "98001456",
"metadata": {
"paymentProcessorId": "fiserv"
},
"paymentProcessor": {
"id": 4,
"acquirer": "fiserv"
}
},
"clientId": 221
},
"client": {
"id": 221,
"name": "Spreedly",
"owner": "PLEXO"
},
"paymentMethod": {
"id": "mastercard",
"legacyId": 4,
"name": "MASTERCARD",
"type": "card",
"card": {
"name": "555555XXXXXX4444",
"bin": "555555",
"last4": "4444",
"expMonth": 12,
"expYear": 20,
"cardholder": {
"firstName": "Santiago",
"lastName": "Navatta",
"email": "[email protected]",
"identification": {
"type": 1,
"value": "123456"
},
"billingAddress": {
"city": "Ottawa",
"country": "CA",
"line1": "456 My Street",
"line2": "Apt 1",
"postalCode": "K1C2N6",
"state": "ON"
}
},
"type": "prepaid",
"origin": "uruguay",
"token": "116d03bef91f4e0e8531af47ed34f690",
"issuer": {
"id": 21289,
"name": "",
"shortName": ""
},
"tokenization": {
"type": "temporal"
}
},
"processor": {
"id": 4,
"acquirer": "fiserv"
}
},
"installments": 1,
"amount": {
"currency": "UYU",
"total": 1,
"details": {
"tax": {
"type": "none",
"amount": 0
},
"taxedAmount": 0,
"tipAmount": 5
}
},
"items": [
{
"referenceId": "a6117dae92648552eb83a4ad0548833a",
"name": "prueba",
"description": "prueba desc",
"quantity": 1,
"price": 100,
"discount": 0,
"metadata": {}
}
],
"metadata": {},
"transactions": [
{
"id": "664d019985707cbcfc11f0b2",
"parentId": "71d4e94a30124a7ba00809c00b7b1149",
"traceId": "c7b07c9c-d3c3-466b-8185-973321c6ab70",
"referenceId": "ecca673a4041317aec64e9e823b3c5d9",
"type": "purchase",
"status": "approved",
"createdAt": "2024-05-21T20:18:33.3896404Z",
"processedAt": "2024-05-21T20:18:33.3896397Z",
"resultCode": "0",
"resultMessage": "You have been mocked.",
"authorization": "123456",
"ticket": "02bbae8109fd4ceca0838628692486c6",
"metadata": {},
"amount": 1
}
],
"actions": []
}
RESPONSE
end
end

0 comments on commit d49571e

Please sign in to comment.