lib/active_merchant/billing/gateways/adyen.rb in activemerchant-1.79.2 vs lib/active_merchant/billing/gateways/adyen.rb in activemerchant-1.80.0

- old
+ new

@@ -42,11 +42,11 @@ def authorize(money, payment, options={}) requires!(options, :order_id) post = init_post(options) add_invoice(post, money, options) add_payment(post, payment) - add_extra_data(post, options) + add_extra_data(post, payment, options) add_shopper_interaction(post, payment, options) add_address(post, options) add_installments(post, options) if options[:installments] commit('authorise', post) end @@ -74,11 +74,11 @@ def store(credit_card, options={}) requires!(options, :order_id) post = init_post(options) add_invoice(post, 0, options) add_payment(post, credit_card) - add_extra_data(post, options) + add_extra_data(post, credit_card, options) add_recurring_contract(post, options) add_address(post, options) commit('authorise', post) end @@ -95,30 +95,37 @@ def scrub(transcript) transcript. gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]'). gsub(%r(("number\\?":\\?")[^"]*)i, '\1[FILTERED]'). - gsub(%r(("cvc\\?":\\?")[^"]*)i, '\1[FILTERED]') + gsub(%r(("cvc\\?":\\?")[^"]*)i, '\1[FILTERED]'). + gsub(%r(("cavv\\?":\\?")[^"]*)i, '\1[FILTERED]') end private - def add_extra_data(post, options) + NETWORK_TOKENIZATION_CARD_SOURCE = { + 'apple_pay' => 'applepay', + 'android_pay' => 'androidpay', + 'google_pay' => 'paywithgoogle' + } + + def add_extra_data(post, payment, options) post[:shopperEmail] = options[:shopper_email] if options[:shopper_email] post[:shopperIP] = options[:shopper_ip] if options[:shopper_ip] post[:shopperReference] = options[:shopper_reference] if options[:shopper_reference] post[:fraudOffset] = options[:fraud_offset] if options[:fraud_offset] - post[:selectedBrand] = options[:selected_brand] if options[:selected_brand] + post[:selectedBrand] = options[:selected_brand] || NETWORK_TOKENIZATION_CARD_SOURCE[payment.source.to_s] if payment.is_a?(NetworkTokenizationCreditCard) post[:deliveryDate] = options[:delivery_date] if options[:delivery_date] post[:merchantOrderReference] = options[:merchant_order_reference] if options[:merchant_order_reference] end def add_shopper_interaction(post, payment, options={}) - if payment.respond_to?(:verification_value) && payment.verification_value - shopper_interaction = "Ecommerce" + if (payment.respond_to?(:verification_value) && payment.verification_value) || payment.is_a?(NetworkTokenizationCreditCard) + shopper_interaction = 'Ecommerce' else - shopper_interaction = "ContAuth" + shopper_interaction = 'ContAuth' end post[:shopperInteraction] = options[:shopper_interaction] || shopper_interaction end @@ -151,14 +158,15 @@ post[:modificationAmount] = amount end def add_payment(post, payment) if payment.is_a?(String) - _, _, recurring_detail_reference = payment.split("#") + _, _, recurring_detail_reference = payment.split('#') post[:selectedRecurringDetailReference] = recurring_detail_reference add_recurring_contract(post, options) else + add_mpi_data_for_network_tokenization_card(post, payment) if payment.is_a?(NetworkTokenizationCreditCard) add_card(post, payment) end end def add_card(post, credit_card) @@ -174,26 +182,34 @@ requires!(card, :expiryMonth, :expiryYear, :holderName, :number) post[:card] = card end def add_reference(post, authorization, options = {}) - _, psp_reference, _ = authorization.split("#") + _, psp_reference, _ = authorization.split('#') post[:originalReference] = single_reference(authorization) || psp_reference end def add_original_reference(post, authorization, options = {}) - original_psp_reference, _, _ = authorization.split("#") + original_psp_reference, _, _ = authorization.split('#') post[:originalReference] = single_reference(authorization) || original_psp_reference end + def add_mpi_data_for_network_tokenization_card(post, payment) + post[:mpiData] = {} + post[:mpiData][:authenticationResponse] = 'Y' + post[:mpiData][:cavv] = payment.payment_cryptogram + post[:mpiData][:directoryResponse] = 'Y' + post[:mpiData][:eci] = payment.eci || '07' + end + def single_reference(authorization) - authorization if !authorization.include?("#") + authorization if !authorization.include?('#') end def add_recurring_contract(post, options = {}) recurring = { - contract: "RECURRING" + contract: 'RECURRING' } post[:recurring] = recurring end @@ -243,11 +259,11 @@ Base64.strict_encode64("#{@username}:#{@password}") end def request_headers { - "Content-Type" => "application/json", - "Authorization" => "Basic #{basic_auth}" + 'Content-Type' => 'application/json', + 'Authorization' => "Basic #{basic_auth}" } end def success_from(action, response) case action.to_s