Skip to content

Commit

Permalink
HPs: Update NetworkTokenizationCreditCard flow
Browse files Browse the repository at this point in the history
Update NetworkTokenizationCreditCArd flow to now be under
WalletData.

Remote
58 tests, 155 assertions, 2 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
96.5517% passed

Unit
61 tests, 295 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
  • Loading branch information
Alma Malambo committed Jul 15, 2024
1 parent dfaccf4 commit b884fe9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
58 changes: 31 additions & 27 deletions lib/active_merchant/billing/gateways/hps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ def initialize(options = {})
super
end

def authorize(money, card_or_token, options = {})
def authorize(money, payment_method, options = {})
commit('CreditAuth') do |xml|
add_amount(xml, money)
add_allow_dup(xml)
add_card_or_token_customer_data(xml, card_or_token, options)
add_card_or_token_customer_data(xml, payment_method, options)
add_details(xml, options)
add_descriptor_name(xml, options)
add_card_or_token_payment(xml, card_or_token, options)
add_three_d_secure(xml, card_or_token, options)
add_card_or_token_payment(xml, payment_method, options)
add_wallet_data(xml, payment_method, options)
add_three_d_secure(xml, payment_method, options)
add_stored_credentials(xml, options)
end
end
Expand Down Expand Up @@ -110,7 +111,8 @@ def scrub(transcript)
gsub(%r((<hps:SecretAPIKey>)[^<]*(<\/hps:SecretAPIKey>))i, '\1[FILTERED]\2').
gsub(%r((<hps:PaymentData>)[^<]*(<\/hps:PaymentData>))i, '\1[FILTERED]\2').
gsub(%r((<hps:RoutingNumber>)[^<]*(<\/hps:RoutingNumber>))i, '\1[FILTERED]\2').
gsub(%r((<hps:AccountNumber>)[^<]*(<\/hps:AccountNumber>))i, '\1[FILTERED]\2')
gsub(%r((<hps:AccountNumber>)[^<]*(<\/hps:AccountNumber>))i, '\1[FILTERED]\2').
gsub(%r((<hps:Cryptogram>)[^<]*(<\/hps:Cryptogram>))i, '\1[FILTERED]\2')
end

private
Expand All @@ -125,28 +127,30 @@ def commit_check_sale(money, check, options)
end
end

def commit_credit_sale(money, card_or_token, options)
def commit_credit_sale(money, payment_method, options)
commit('CreditSale') do |xml|
add_amount(xml, money)
add_allow_dup(xml)
add_card_or_token_customer_data(xml, card_or_token, options)
add_card_or_token_customer_data(xml, payment_method, options)
add_details(xml, options)
add_descriptor_name(xml, options)
add_card_or_token_payment(xml, card_or_token, options)
add_three_d_secure(xml, card_or_token, options)
add_card_or_token_payment(xml, payment_method, options)
add_wallet_data(xml, payment_method, options)
add_three_d_secure(xml, payment_method, options)
add_stored_credentials(xml, options)
end
end

def commit_recurring_billing_sale(money, card_or_token, options)
def commit_recurring_billing_sale(money, payment_method, options)
commit('RecurringBilling') do |xml|
add_amount(xml, money)
add_allow_dup(xml)
add_card_or_token_customer_data(xml, card_or_token, options)
add_card_or_token_customer_data(xml, payment_method, options)
add_details(xml, options)
add_descriptor_name(xml, options)
add_card_or_token_payment(xml, card_or_token, options)
add_three_d_secure(xml, card_or_token, options)
add_card_or_token_payment(xml, payment_method, options)
add_wallet_data(xml, payment_method, options)
add_three_d_secure(xml, payment_method, options)
add_stored_credentials(xml, options)
add_stored_credentials_for_recurring_billing(xml, options)
end
Expand Down Expand Up @@ -254,27 +258,27 @@ def add_descriptor_name(xml, options)
xml.hps :TxnDescriptor, options[:descriptor_name] if options[:descriptor_name]
end

def add_three_d_secure(xml, card_or_token, options)
if card_or_token.is_a?(NetworkTokenizationCreditCard)
build_three_d_secure(xml, {
source: card_or_token.source,
cavv: card_or_token.payment_cryptogram,
eci: card_or_token.eci,
xid: card_or_token.transaction_id
})
elsif options[:three_d_secure]
options[:three_d_secure][:source] ||= card_brand(card_or_token)
build_three_d_secure(xml, options[:three_d_secure])
def add_wallet_data(xml, payment_method, options)
return unless payment_method.is_a?(NetworkTokenizationCreditCard)

xml.hps :WalletData do
xml.hps :PaymentSource, PAYMENT_DATA_SOURCE_MAPPING[payment_method.source]
xml.hps :Cryptogram, payment_method.payment_cryptogram
xml.hps :ECI, payment_method.eci&.to_s&.sub!(/^0/, '') if payment_method.eci
end
end

def build_three_d_secure(xml, three_d_secure)
def add_three_d_secure(xml, card_or_token, options)
# PaymentDataSource is required when supplying the SecureECommerce data group,
# and the gateway currently only allows the values within the mapping
return unless PAYMENT_DATA_SOURCE_MAPPING[three_d_secure[:source].to_sym]
return unless (three_d_secure = options[:three_d_secure])

three_d_secure[:source] ||= card_brand(card_or_token)

return unless (source = PAYMENT_DATA_SOURCE_MAPPING[three_d_secure[:source].to_sym])

xml.hps :SecureECommerce do
xml.hps :PaymentDataSource, PAYMENT_DATA_SOURCE_MAPPING[three_d_secure[:source].to_sym]
xml.hps :PaymentDataSource, source
xml.hps :TypeOfPaymentData, '3DSecure' # Only type currently supported
xml.hps :PaymentData, three_d_secure[:cavv] if three_d_secure[:cavv]
# the gateway only allows a single character for the ECI
Expand Down
1 change: 0 additions & 1 deletion test/remote/gateways/remote_hps_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ def test_transcript_scrubbing_with_cryptogram
credit_card = network_tokenization_credit_card(
'4242424242424242',
payment_cryptogram: 'EHuWW9PiBkWvqE5juRwDzAUFBAk=',
verification_value: nil,
eci: '05',
source: :apple_pay
)
Expand Down

0 comments on commit b884fe9

Please sign in to comment.