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

CyberSource: update NT methods to allow for recurring AP #4817

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
18 changes: 13 additions & 5 deletions lib/active_merchant/billing/gateways/cyber_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -799,23 +799,31 @@ def add_auth_network_tokenization(xml, payment_method, options)

brand = card_brand(payment_method).to_sym

# stored_credential_overrides is not documented on the gateway guide in docs
# I think the easiest way to solve for apple pay recurring is to create a new field within the hash
# commerce_indicator can be passed in as 'internet' but is assigned that value in an earlier method so will be overwritten by the card brand if there is not something done within this method
commerce_indicator = 'internet' if options.dig(:stored_credential_overrides, :type) == 'apple_pay'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you envisioning the merchant passing in this GSF or adding when we build the params in the gateway class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a thought, but this was more of a means to an end to see if I could get a passing remote test. I'm open to other options.


case brand
when :visa
xml.tag! 'ccAuthService', { 'run' => 'true' } do
xml.tag!('cavv', payment_method.payment_cryptogram)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we removing the cryptogram fields entirely or only for recurring transactions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for recurring Apple Pay transactions. That's why I said the guard clauses should probably be revisited, but this was more of a draft/means to get getting a passing test.

xml.tag!('commerceIndicator', ECI_BRAND_MAPPING[brand])
xml.tag!('xid', payment_method.payment_cryptogram)
# these guard clauses need more consideration but work for the needs of this edge case remote test
xml.tag!('cavv', payment_method.payment_cryptogram) unless options[:stored_credential_overrides]
xml.commerceIndicator commerce_indicator.nil? ? ECI_BRAND_MAPPING[brand] : commerce_indicator
xml.tag!('xid', payment_method.payment_cryptogram) unless options[:stored_credential_overrides]
xml.tag!('reconciliationID', options[:reconciliation_id]) if options[:reconciliation_id]
end
when :master
# mastercard is more finicky, has different fields required. no passing test yet.
xml.tag! 'ucaf' do
xml.tag!('authenticationData', payment_method.payment_cryptogram)
xml.tag!('authenticationData', payment_method.payment_cryptogram) unless options[:stored_credential_overrides]
xml.tag!('collectionIndicator', DEFAULT_COLLECTION_INDICATOR)
end
xml.tag! 'ccAuthService', { 'run' => 'true' } do
xml.tag!('commerceIndicator', ECI_BRAND_MAPPING[brand])
xml.commerceIndicator commerce_indicator.nil? ? ECI_BRAND_MAPPING[brand] : commerce_indicator
xml.tag!('reconciliationID', options[:reconciliation_id]) if options[:reconciliation_id]
end
# AmEx isn't part of NTID scheme so not sure if this will work with AP that is underlying AmEx
when :american_express
cryptogram = Base64.decode64(payment_method.payment_cryptogram)
xml.tag! 'ccAuthService', { 'run' => 'true' } do
Expand Down
20 changes: 20 additions & 0 deletions test/remote/gateways/remote_cyber_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,26 @@ def test_purchase_with_network_tokenization_with_amex_cc
assert_successful_response(auth)
end

def test_purchase_with_apple_pay_network_tokenization
credit_card = network_tokenization_credit_card('4111111111111111',
brand: 'visa',
eci: '05',
source: :apple_pay,
payment_cryptogram: 'EHuWW9PiBkWvqE5juRwDzAUFBAk=')
@options[:stored_credential_overrides] = {
subsequent_auth_stored_credential: true,
type: 'apple_pay'
}
@options[:stored_credential] = {
initiator: 'merchant',
reason_type: 'unscheduled',
network_transaction_id: '016150703802094'
}

assert auth = @gateway.purchase(@amount, credit_card, @options)
assert_successful_response(auth)
end

def test_successful_authorize_with_mdd_fields
(1..20).each { |e| @options["mdd_field_#{e}".to_sym] = "value #{e}" }

Expand Down