Skip to content

Commit

Permalink
Revert "Cybersource: Update NT flow"
Browse files Browse the repository at this point in the history
This reverts commit 39603de.
  • Loading branch information
Alma Malambo committed Apr 19, 2024
1 parent 39603de commit 7034274
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 162 deletions.
1 change: 0 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@
* PayTrace: Always send name in billing_address [almalee24] #5086
* StripePI: Update eci format [almalee24] #5097
* Paymentez: Remove reference_id flag [almalee24] #5081
* CheckoutV2: Update NT flow [almalee24] #5091


== Version 1.135.0 (August 24, 2023)
Expand Down
62 changes: 14 additions & 48 deletions lib/active_merchant/billing/gateways/cyber_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,11 @@ class CyberSourceGateway < Gateway
r703: 'Export hostname_country/ip_country match'
}

@@wallet_payment_solution = {
@@payment_solution = {
apple_pay: '001',
google_pay: '012'
}

NT_PAYMENT_SOLUTION = {
'master' => '014',
'visa' => '015'
}

# These are the options that can be used when creating a new CyberSource
# Gateway object.
#
Expand Down Expand Up @@ -286,8 +281,6 @@ def scrub(transcript)
gsub(%r((<cvNumber>)[^<]*(</cvNumber>))i, '\1[FILTERED]\2').
gsub(%r((<cavv>)[^<]*(</cavv>))i, '\1[FILTERED]\2').
gsub(%r((<xid>)[^<]*(</xid>))i, '\1[FILTERED]\2').
gsub(%r((<networkTokenCryptogram>)[^<]*(</networkTokenCryptogram>))i, '\1[FILTERED]\2').
gsub(%r((<requestorID>)[^<]*(</requestorID>))i, '\1[FILTERED]\2').
gsub(%r((<authenticationData>)[^<]*(</authenticationData>))i, '\1[FILTERED]\2')
end

Expand Down Expand Up @@ -344,8 +337,8 @@ def build_auth_request(money, creditcard_or_reference, options)
add_business_rules_data(xml, creditcard_or_reference, options)
add_airline_data(xml, options)
add_sales_slip_number(xml, options)
add_payment_network_token(xml, creditcard_or_reference, options)
add_payment_solution(xml, creditcard_or_reference)
add_payment_network_token(xml) if network_tokenization?(creditcard_or_reference)
add_payment_solution(xml, creditcard_or_reference.source) if network_tokenization?(creditcard_or_reference)
add_tax_management_indicator(xml, options)
add_stored_credential_subsequent_auth(xml, options)
add_issuer_additional_data(xml, options)
Expand Down Expand Up @@ -417,8 +410,8 @@ def build_purchase_request(money, payment_method_or_reference, options)
add_business_rules_data(xml, payment_method_or_reference, options)
add_airline_data(xml, options)
add_sales_slip_number(xml, options)
add_payment_network_token(xml, payment_method_or_reference, options)
add_payment_solution(xml, payment_method_or_reference)
add_payment_network_token(xml) if network_tokenization?(payment_method_or_reference)
add_payment_solution(xml, payment_method_or_reference.source) if network_tokenization?(payment_method_or_reference)
add_tax_management_indicator(xml, options)
add_stored_credential_subsequent_auth(xml, options)
add_issuer_additional_data(xml, options)
Expand Down Expand Up @@ -506,7 +499,7 @@ def build_create_subscription_request(payment_method, options)
add_check_service(xml)
else
add_purchase_service(xml, payment_method, options)
add_payment_network_token(xml, payment_method, options)
add_payment_network_token(xml) if network_tokenization?(payment_method)
end
end
add_subscription_create_service(xml, options)
Expand Down Expand Up @@ -696,16 +689,10 @@ def add_decision_manager_fields(xml, options)
end
end

def add_payment_solution(xml, payment_method)
return unless network_tokenization?(payment_method)
def add_payment_solution(xml, source)
return unless (payment_solution = @@payment_solution[source])

case payment_method.source
when :network_token
payment_solution = NT_PAYMENT_SOLUTION[payment_method.brand]
xml.tag! 'paymentSolution', payment_solution if payment_solution
when :apple_pay, :google_pay
xml.tag! 'paymentSolution', @@wallet_payment_solution[payment_method.source]
end
xml.tag! 'paymentSolution', payment_solution
end

def add_issuer_additional_data(xml, options)
Expand Down Expand Up @@ -756,11 +743,7 @@ def add_tax_service(xml)

def add_auth_service(xml, payment_method, options)
if network_tokenization?(payment_method)
if payment_method.source == :network_token
add_auth_network_tokenization(xml, payment_method, options)
else
add_auth_wallet(xml, payment_method, options)
end
add_auth_network_tokenization(xml, payment_method, options)
else
xml.tag! 'ccAuthService', { 'run' => 'true' } do
if options[:three_d_secure]
Expand Down Expand Up @@ -852,26 +835,14 @@ def network_tokenization?(payment_method)

def subsequent_nt_apple_pay_auth(source, options)
return unless options[:stored_credential] || options[:stored_credential_overrides]
return unless @@wallet_payment_solution[source]
return unless @@payment_solution[source]

options.dig(:stored_credential_overrides, :subsequent_auth) || options.dig(:stored_credential, :initiator) == 'merchant'
end

def add_auth_network_tokenization(xml, payment_method, options)
brand = card_brand(payment_method).to_sym
case brand
when :visa, :master, :american_express
xml.tag! 'ccAuthService', { 'run' => 'true' } do
xml.tag!('networkTokenCryptogram', payment_method.payment_cryptogram)
xml.tag!('reconciliationID', options[:reconciliation_id]) if options[:reconciliation_id]
xml.tag!('commerceIndicator', 'internet')
end
else
raise ArgumentError.new("Payment method #{brand} is not supported, check https://developer.cybersource.com/docs/cybs/en-us/payments/developer/all/rest/payments/CreatingOnlineAuth/CreatingAuthReqPNT.html")
end
end
return unless network_tokenization?(payment_method)

def add_auth_wallet(xml, payment_method, options)
commerce_indicator = 'internet' if subsequent_nt_apple_pay_auth(payment_method.source, options)

brand = card_brand(payment_method).to_sym
Expand Down Expand Up @@ -904,7 +875,6 @@ def add_auth_wallet(xml, payment_method, options)

def add_mastercard_network_tokenization_ucaf_data(xml, payment_method, options)
return unless network_tokenization?(payment_method) && card_brand(payment_method).to_sym == :master
return if payment_method.source == :network_token

commerce_indicator = 'internet' if subsequent_nt_apple_pay_auth(payment_method.source, options)

Expand All @@ -914,13 +884,9 @@ def add_mastercard_network_tokenization_ucaf_data(xml, payment_method, options)
end
end

def add_payment_network_token(xml, payment_method, options)
return unless network_tokenization?(payment_method)

transaction_type = payment_method.source == :network_token ? '3' : '1'
def add_payment_network_token(xml)
xml.tag! 'paymentNetworkToken' do
xml.tag!('requestorID', options[:trid]) if transaction_type == '3' && options[:trid]
xml.tag!('transactionType', transaction_type)
xml.tag!('transactionType', '1')
end
end

Expand Down
22 changes: 2 additions & 20 deletions test/remote/gateways/remote_cyber_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,13 @@ def setup
'4111111111111111',
brand: 'visa',
eci: '05',
payment_cryptogram: 'EHuWW9PiBkWvqE5juRwDzAUFBAk=',
source: :network_token
payment_cryptogram: 'EHuWW9PiBkWvqE5juRwDzAUFBAk='
)
@amex_network_token = network_tokenization_credit_card(
'378282246310005',
brand: 'american_express',
eci: '05',
payment_cryptogram: 'EHuWW9PiBkWvqE5juRwDzAUFBAk=',
source: :network_token
)

@mastercard_network_token = network_tokenization_credit_card(
'5555555555554444',
brand: 'master',
eci: '05',
payment_cryptogram: 'EHuWW9PiBkWvqE5juRwDzAUFBAk=',
source: :network_token
payment_cryptogram: 'EHuWW9PiBkWvqE5juRwDzAUFBAk='
)

@amount = 100
Expand Down Expand Up @@ -757,14 +747,6 @@ def test_network_tokenization_with_amex_cc_and_basic_cryptogram
assert_successful_response(capture)
end

def test_network_tokenization_with_mastercard
assert auth = @gateway.authorize(@amount, @mastercard_network_token, @options)
assert_successful_response(auth)

assert capture = @gateway.capture(@amount, auth.authorization)
assert_successful_response(capture)
end

def test_network_tokenization_with_amex_cc_longer_cryptogram
# Generate a random 40 bytes binary amex cryptogram => Base64.encode64(Random.bytes(40))
long_cryptogram = "NZwc40C4eTDWHVDXPekFaKkNYGk26w+GYDZmU50cATbjqOpNxR/eYA==\n"
Expand Down
Loading

0 comments on commit 7034274

Please sign in to comment.