Skip to content

Commit

Permalink
Cybersource: Add apple_pay params for discover if flag passed (#5213)
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinHaefele committed Aug 21, 2024
1 parent 654839e commit 5084609
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Iveri: Add AuthReversal for Authorizations [almalee24] #5201
* Decidir & Braintree: Scrub cryptogram and card number [almalee24] #5220
* Naranja: Update valid number check to include luhn10 [DustinHaefele] #5217
* Cybersource: Add apple_pay with discover. [DustinHaefele] #5213

== Version 1.137.0 (August 2, 2024)
* Unlock dependency on `rexml` to allow fixing a CVE (#5181).
Expand Down
19 changes: 14 additions & 5 deletions lib/active_merchant/billing/gateways/cyber_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def initialize(options = {})
end

def authorize(money, payment_method, options = {})
if valid_payment_method?(payment_method)
if valid_payment_method?(payment_method, options)
setup_address_hash(options)
commit(build_auth_request(money, payment_method, options), :authorize, money, options)
else
Expand All @@ -193,7 +193,7 @@ def capture(money, authorization, options = {})
end

def purchase(money, payment_method, options = {})
if valid_payment_method?(payment_method)
if valid_payment_method?(payment_method, options)
setup_address_hash(options)
commit(build_purchase_request(money, payment_method, options), :purchase, money, options)
else
Expand Down Expand Up @@ -233,7 +233,7 @@ def credit(money, creditcard_or_reference, options = {})
# To charge the card while creating a profile, pass
# options[:setup_fee] => money
def store(payment_method, options = {})
if valid_payment_method?(payment_method)
if valid_payment_method?(payment_method, options)
setup_address_hash(options)
commit(build_create_subscription_request(payment_method, options), :store, nil, options)
else
Expand Down Expand Up @@ -321,10 +321,12 @@ def verify_credentials

private

def valid_payment_method?(payment_method)
def valid_payment_method?(payment_method, options)
return true unless payment_method.is_a?(NetworkTokenizationCreditCard)

%w(visa master american_express).include?(card_brand(payment_method))
brands = %w(visa master american_express)
brands << 'discover' if options[:enable_cybs_discover_apple_pay]
brands.include?(card_brand(payment_method))
end

# Create all required address hash key value pairs
Expand Down Expand Up @@ -931,6 +933,13 @@ def add_auth_wallet(xml, payment_method, options)
xml.tag!('xid', Base64.encode64(cryptogram[20...40])) if cryptogram.bytes.count > 20
xml.tag!('reconciliationID', options[:reconciliation_id]) if options[:reconciliation_id]
end
when :discover
return unless options[:enable_cybs_discover_apple_pay]

xml.tag! 'ccAuthService', { 'run' => 'true' } do
xml.tag!('cavv', payment_method.payment_cryptogram) unless commerce_indicator
xml.tag!('commerceIndicator', 'internet')
end
end
end

Expand Down
19 changes: 19 additions & 0 deletions test/unit/gateways/cyber_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def setup
eci: '05',
payment_cryptogram: '111111111100cryptogram',
source: :apple_pay)
@apple_pay_discover = network_tokenization_credit_card('6011111111111117',
brand: 'discover',
transaction_id: '123',
eci: '05',
payment_cryptogram: '111111111100cryptogram',
source: :apple_pay)
@google_pay = network_tokenization_credit_card('4242424242424242', source: :google_pay)
@check = check()

Expand Down Expand Up @@ -563,6 +569,19 @@ def test_successful_apple_pay_purchase_subsequent_auth_mastercard
assert_success response
end

def test_successful_apple_pay_purchase_subsequent_auth_discover
@gateway.expects(:ssl_post).with do |_host, request_body|
assert_match %r'<cavv>', request_body
assert_match %r'<commerceIndicator>internet</commerceIndicator>', request_body
true
end.returns(successful_purchase_response)

options = @options.merge(enable_cybs_discover_apple_pay: true)

assert response = @gateway.purchase(@amount, @apple_pay_discover, options)
assert_success response
end

def test_successful_reference_purchase
@gateway.stubs(:ssl_post).returns(successful_create_subscription_response, successful_purchase_response)

Expand Down

0 comments on commit 5084609

Please sign in to comment.