diff --git a/CHANGELOG b/CHANGELOG index f45c855f739..bbab88f6888 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,10 @@ = ActiveMerchant CHANGELOG == HEAD + += Version 1.137.0 (August 2, 2024) + +* Unlock dependency on `rexml` to allow fixing a CVE (#5181). * Bump Ruby version to 3.1 [dustinhaefele] #5104 * FlexCharge: Update inquire method to use the new orders end-point * Worldpay: Prefer options for network_transaction_id [aenand] #5129 @@ -26,6 +30,10 @@ * Braintree Blue: Pass overridden mid into client token for GS 3DS [sinourain] #5166 * Moneris: Update crypt_type for 3DS [almalee24] #5162 * CheckoutV2: Update 3DS message & error code [almalee24] #5177 +* DecicirPlus: Update error_message to add safety navigator [almalee24] #5187 +* Elavon: Add updated stored credential version [almalee24] #5170 +* Adyen: Add header fields to response body [yunnydang] #5184 +* Stripe and Stripe PI: Add header fields to response body [yunnydang] #5185 == Version 1.136.0 (June 3, 2024) * Shift4V2: Add new gateway based on SecurionPay adapter [heavyblade] #4860 diff --git a/activemerchant.gemspec b/activemerchant.gemspec index 78484f81232..115de333e9e 100644 --- a/activemerchant.gemspec +++ b/activemerchant.gemspec @@ -26,7 +26,7 @@ Gem::Specification.new do |s| s.add_dependency('builder', '>= 2.1.2', '< 4.0.0') s.add_dependency('i18n', '>= 0.6.9') s.add_dependency('nokogiri', '~> 1.4') - s.add_dependency('rexml', '~> 3.2.5') + s.add_dependency('rexml', '~> 3.3', '>= 3.3.4') s.add_development_dependency('mocha', '~> 1') s.add_development_dependency('pry') diff --git a/lib/active_merchant/billing/gateways/adyen.rb b/lib/active_merchant/billing/gateways/adyen.rb index 6adae2748bb..e0671df64ba 100644 --- a/lib/active_merchant/billing/gateways/adyen.rb +++ b/lib/active_merchant/billing/gateways/adyen.rb @@ -766,10 +766,34 @@ def add_metadata(post, options = {}) post[:metadata].merge!(options[:metadata]) if options[:metadata] end + def add_header_fields(response) + return unless @response_headers.present? + + headers = {} + headers['response_headers'] = {} + headers['response_headers']['transient_error'] = @response_headers['transient-error'] if @response_headers['transient-error'] + + response.merge!(headers) + end + def parse(body) return {} if body.blank? - JSON.parse(body) + response = JSON.parse(body) + add_header_fields(response) + response + end + + # Override the regular handle response so we can access the headers + # set header fields and values so we can add them to the response body + def handle_response(response) + @response_headers = response.each_header.to_h if response.respond_to?(:header) + case response.code.to_i + when 200...300 + response.body + else + raise ResponseError.new(response) + end end def commit(action, parameters, options) diff --git a/lib/active_merchant/billing/gateways/datatrans.rb b/lib/active_merchant/billing/gateways/datatrans.rb index c4b53a4586c..0b7042d0658 100644 --- a/lib/active_merchant/billing/gateways/datatrans.rb +++ b/lib/active_merchant/billing/gateways/datatrans.rb @@ -90,7 +90,7 @@ def store(payment_method, options = {}) end def unstore(authorization, options = {}) - data_alias = authorization.split('|')[2].split('-')[0] + data_alias = authorization.split('|')[2] commit('delete_alias', {}, { alias_id: data_alias }, :delete) end @@ -110,7 +110,7 @@ def scrub(transcript) def add_payment_method(post, payment_method) case payment_method when String - token, exp_month, exp_year = payment_method.split('|')[2].split('-') + token, exp_month, exp_year = payment_method.split('|')[2..4] card = { type: 'ALIAS', alias: token, @@ -250,9 +250,9 @@ def success_from(action, response) end def authorization_from(response, action, options) - string = [response.dig('responses', 0, 'alias'), options[:expiry_month], options[:expiry_year]].join('-') if action == 'tokenize' + token_array = [response.dig('responses', 0, 'alias'), options[:expiry_month], options[:expiry_year]].join('|') if action == 'tokenize' - auth = [response['transactionId'], response['acquirerAuthorizationCode'], string].join('|') + auth = [response['transactionId'], response['acquirerAuthorizationCode'], token_array].join('|') return auth unless auth == '||' end diff --git a/lib/active_merchant/billing/gateways/decidir_plus.rb b/lib/active_merchant/billing/gateways/decidir_plus.rb index 5cefebf92e5..9a7477bd6cb 100644 --- a/lib/active_merchant/billing/gateways/decidir_plus.rb +++ b/lib/active_merchant/billing/gateways/decidir_plus.rb @@ -321,8 +321,11 @@ def error_message(response) return error_code_from(response) unless validation_errors = response.dig('validation_errors') validation_errors = validation_errors[0] + message = "#{validation_errors&.dig('code')}: #{validation_errors&.dig('param')}" + return message unless message == ': ' - "#{validation_errors.dig('code')}: #{validation_errors.dig('param')}" + errors = response['validation_errors'].map { |k, v| "#{k}: #{v}" }.join(', ') + "#{response['error_type']} - #{errors}" end def rejected?(response) diff --git a/lib/active_merchant/billing/gateways/elavon.rb b/lib/active_merchant/billing/gateways/elavon.rb index f7f5e678575..fa4892618da 100644 --- a/lib/active_merchant/billing/gateways/elavon.rb +++ b/lib/active_merchant/billing/gateways/elavon.rb @@ -51,7 +51,7 @@ def purchase(money, payment_method, options = {}) add_customer_email(xml, options) add_test_mode(xml, options) add_ip(xml, options) - add_auth_purchase_params(xml, options) + add_auth_purchase_params(xml, payment_method, options) add_level_3_fields(xml, options) if options[:level_3_data] end commit(request) @@ -70,7 +70,7 @@ def authorize(money, payment_method, options = {}) add_customer_email(xml, options) add_test_mode(xml, options) add_ip(xml, options) - add_auth_purchase_params(xml, options) + add_auth_purchase_params(xml, payment_method, options) add_level_3_fields(xml, options) if options[:level_3_data] end commit(request) @@ -86,7 +86,7 @@ def capture(money, authorization, options = {}) add_salestax(xml, options) add_approval_code(xml, authorization) add_invoice(xml, options) - add_creditcard(xml, options[:credit_card]) + add_creditcard(xml, options[:credit_card], options) add_currency(xml, money, options) add_address(xml, options) add_customer_email(xml, options) @@ -133,7 +133,7 @@ def credit(money, creditcard, options = {}) xml.ssl_transaction_type self.actions[:credit] xml.ssl_amount amount(money) add_invoice(xml, options) - add_creditcard(xml, creditcard) + add_creditcard(xml, creditcard, options) add_currency(xml, money, options) add_address(xml, options) add_customer_email(xml, options) @@ -146,7 +146,7 @@ def verify(credit_card, options = {}) request = build_xml_request do |xml| xml.ssl_vendor_id @options[:ssl_vendor_id] || options[:ssl_vendor_id] xml.ssl_transaction_type self.actions[:verify] - add_creditcard(xml, credit_card) + add_creditcard(xml, credit_card, options) add_address(xml, options) add_test_mode(xml, options) add_ip(xml, options) @@ -159,7 +159,7 @@ def store(creditcard, options = {}) xml.ssl_vendor_id @options[:ssl_vendor_id] || options[:ssl_vendor_id] xml.ssl_transaction_type self.actions[:store] xml.ssl_add_token 'Y' - add_creditcard(xml, creditcard) + add_creditcard(xml, creditcard, options) add_address(xml, options) add_customer_email(xml, options) add_test_mode(xml, options) @@ -172,8 +172,8 @@ def update(token, creditcard, options = {}) request = build_xml_request do |xml| xml.ssl_vendor_id @options[:ssl_vendor_id] || options[:ssl_vendor_id] xml.ssl_transaction_type self.actions[:update] - add_token(xml, token) - add_creditcard(xml, creditcard) + xml.ssl_token token + add_creditcard(xml, creditcard, options) add_address(xml, options) add_customer_email(xml, options) add_test_mode(xml, options) @@ -195,12 +195,12 @@ def scrub(transcript) private def add_payment(xml, payment, options) - if payment.is_a?(String) - xml.ssl_token payment + if payment.is_a?(String) || options[:ssl_token] + xml.ssl_token options[:ssl_token] || payment elsif payment.is_a?(NetworkTokenizationCreditCard) add_network_token(xml, payment) else - add_creditcard(xml, payment) + add_creditcard(xml, payment, options) end end @@ -227,11 +227,11 @@ def add_network_token(xml, payment_method) end end - def add_creditcard(xml, creditcard) + def add_creditcard(xml, creditcard, options) xml.ssl_card_number creditcard.number xml.ssl_exp_date expdate(creditcard) - add_verification_value(xml, creditcard) if creditcard.verification_value? + add_verification_value(xml, creditcard, options) xml.ssl_first_name url_encode_truncate(creditcard.first_name, 20) xml.ssl_last_name url_encode_truncate(creditcard.last_name, 30) @@ -244,12 +244,12 @@ def add_currency(xml, money, options) xml.ssl_transaction_currency currency end - def add_token(xml, token) - xml.ssl_token token - end + def add_verification_value(xml, credit_card, options) + return unless credit_card.verification_value? + # Don't add cvv if this is a non-initial stored credential transaction + return if options[:stored_credential] && !options.dig(:stored_credential, :initial_transaction) && options[:stored_cred_v2] - def add_verification_value(xml, creditcard) - xml.ssl_cvv2cvc2 creditcard.verification_value + xml.ssl_cvv2cvc2 credit_card.verification_value xml.ssl_cvv2cvc2_indicator 1 end @@ -308,16 +308,20 @@ def add_ip(xml, options) end # add_recurring_token is a field that can be sent in to obtain a token from Elavon for use with their tokenization program - def add_auth_purchase_params(xml, options) + def add_auth_purchase_params(xml, payment_method, options) xml.ssl_dynamic_dba options[:dba] if options.has_key?(:dba) xml.ssl_merchant_initiated_unscheduled merchant_initiated_unscheduled(options) if merchant_initiated_unscheduled(options) xml.ssl_add_token options[:add_recurring_token] if options.has_key?(:add_recurring_token) - xml.ssl_token options[:ssl_token] if options[:ssl_token] xml.ssl_customer_code options[:customer] if options.has_key?(:customer) xml.ssl_customer_number options[:customer_number] if options.has_key?(:customer_number) - xml.ssl_entry_mode entry_mode(options) if entry_mode(options) + xml.ssl_entry_mode entry_mode(payment_method, options) if entry_mode(payment_method, options) add_custom_fields(xml, options) if options[:custom_fields] - add_stored_credential(xml, options) if options[:stored_credential] + if options[:stored_cred_v2] + add_stored_credential_v2(xml, payment_method, options) + add_installment_fields(xml, options) + else + add_stored_credential(xml, options) + end end def add_custom_fields(xml, options) @@ -367,6 +371,8 @@ def add_line_items(xml, level_3_data) end def add_stored_credential(xml, options) + return unless options[:stored_credential] + network_transaction_id = options.dig(:stored_credential, :network_transaction_id) case when network_transaction_id.nil? @@ -382,14 +388,60 @@ def add_stored_credential(xml, options) end end + def add_stored_credential_v2(xml, payment_method, options) + return unless options[:stored_credential] + + network_transaction_id = options.dig(:stored_credential, :network_transaction_id) + xml.ssl_recurring_flag recurring_flag(options) if recurring_flag(options) + xml.ssl_par_value options[:par_value] if options[:par_value] + xml.ssl_association_token_data options[:association_token_data] if options[:association_token_data] + + unless payment_method.is_a?(String) || options[:ssl_token].present? + xml.ssl_approval_code options[:approval_code] if options[:approval_code] + if network_transaction_id.to_s.include?('|') + oar_data, ps2000_data = network_transaction_id.split('|') + xml.ssl_oar_data oar_data unless oar_data.blank? + xml.ssl_ps2000_data ps2000_data unless ps2000_data.blank? + elsif network_transaction_id.to_s.length > 22 + xml.ssl_oar_data network_transaction_id + elsif network_transaction_id.present? + xml.ssl_ps2000_data network_transaction_id + end + end + end + + def recurring_flag(options) + return unless reason = options.dig(:stored_credential, :reason_type) + return 1 if reason == 'recurring' + return 2 if reason == 'installment' + end + def merchant_initiated_unscheduled(options) return options[:merchant_initiated_unscheduled] if options[:merchant_initiated_unscheduled] - return 'Y' if options.dig(:stored_credential, :initiator) == 'merchant' && options.dig(:stored_credential, :reason_type) == 'unscheduled' || options.dig(:stored_credential, :reason_type) == 'recurring' + return 'Y' if options.dig(:stored_credential, :initiator) == 'merchant' && merchant_reason_type(options) + end + + def merchant_reason_type(options) + if options[:stored_cred_v2] + options.dig(:stored_credential, :reason_type) == 'unscheduled' + else + options.dig(:stored_credential, :reason_type) == 'unscheduled' || options.dig(:stored_credential, :reason_type) == 'recurring' + end end - def entry_mode(options) + def add_installment_fields(xml, options) + return unless options.dig(:stored_credential, :reason_type) == 'installment' + + xml.ssl_payment_number options[:payment_number] + xml.ssl_payment_count options[:installments] + end + + def entry_mode(payment_method, options) return options[:entry_mode] if options[:entry_mode] - return 12 if options[:stored_credential] + return 12 if options[:stored_credential] && options[:stored_cred_v2] != true + + return if payment_method.is_a?(String) || options[:ssl_token] + return 12 if options.dig(:stored_credential, :reason_type) == 'unscheduled' end def build_xml_request diff --git a/lib/active_merchant/billing/gateways/fat_zebra.rb b/lib/active_merchant/billing/gateways/fat_zebra.rb index 0d534db434c..3a9f11b656f 100644 --- a/lib/active_merchant/billing/gateways/fat_zebra.rb +++ b/lib/active_merchant/billing/gateways/fat_zebra.rb @@ -151,7 +151,7 @@ def add_three_ds(post, options) par: three_d_secure[:authentication_response_status], ver: formatted_enrollment(three_d_secure[:enrolled]), threeds_version: three_d_secure[:version], - ds_transaction_id: three_d_secure[:ds_transaction_id] + directory_server_txn_id: three_d_secure[:ds_transaction_id] }.compact end diff --git a/lib/active_merchant/billing/gateways/rapyd.rb b/lib/active_merchant/billing/gateways/rapyd.rb index e99b8c10eb7..8ab61b0d5c8 100644 --- a/lib/active_merchant/billing/gateways/rapyd.rb +++ b/lib/active_merchant/billing/gateways/rapyd.rb @@ -243,6 +243,7 @@ def add_ewallet(post, options) def add_payment_fields(post, options) post[:description] = options[:description] if options[:description] post[:statement_descriptor] = options[:statement_descriptor] if options[:statement_descriptor] + post[:save_payment_method] = options[:save_payment_method] if options[:save_payment_method] end def add_payment_urls(post, options, action = '') diff --git a/lib/active_merchant/billing/gateways/stripe.rb b/lib/active_merchant/billing/gateways/stripe.rb index 17bc8c5035c..579735cefe9 100644 --- a/lib/active_merchant/billing/gateways/stripe.rb +++ b/lib/active_merchant/billing/gateways/stripe.rb @@ -617,8 +617,21 @@ def add_radar_data(post, options = {}) post[:radar_options] = radar_options unless radar_options.empty? end + def add_header_fields(response) + return unless @response_headers.present? + + headers = {} + headers['response_headers'] = {} + headers['response_headers']['idempotent_replayed'] = @response_headers['idempotent-replayed'] if @response_headers['idempotent-replayed'] + headers['response_headers']['stripe_should_retry'] = @response_headers['stripe-should-retry'] if @response_headers['stripe-should-retry'] + + response.merge!(headers) + end + def parse(body) - JSON.parse(body) + response = JSON.parse(body) + add_header_fields(response) + response end def post_data(params) @@ -752,6 +765,18 @@ def success_from(response, options) !response.key?('error') && response['status'] != 'failed' end + # Override the regular handle response so we can access the headers + # set header fields and values so we can add them to the response body + def handle_response(response) + @response_headers = response.each_header.to_h if response.respond_to?(:header) + case response.code.to_i + when 200...300 + response.body + else + raise ResponseError.new(response) + end + end + def response_error(raw_response) parse(raw_response) rescue JSON::ParserError diff --git a/lib/active_merchant/version.rb b/lib/active_merchant/version.rb index 2a2845e4371..0f14bccd30b 100644 --- a/lib/active_merchant/version.rb +++ b/lib/active_merchant/version.rb @@ -1,3 +1,3 @@ module ActiveMerchant - VERSION = '1.136.0' + VERSION = '1.137.0' end diff --git a/test/remote/gateways/remote_elavon_test.rb b/test/remote/gateways/remote_elavon_test.rb index 6ad3e3c6097..2be919c0efd 100644 --- a/test/remote/gateways/remote_elavon_test.rb +++ b/test/remote/gateways/remote_elavon_test.rb @@ -8,14 +8,14 @@ def setup @multi_currency_gateway = ElavonGateway.new(fixtures(:elavon_multi_currency)) @credit_card = credit_card('4000000000000002') + @mastercard = credit_card('5121212121212124') @bad_credit_card = credit_card('invalid') @options = { email: 'paul@domain.com', description: 'Test Transaction', billing_address: address, - ip: '203.0.113.0', - merchant_initiated_unscheduled: 'N' + ip: '203.0.113.0' } @shipping_address = { address1: '733 Foster St.', @@ -207,32 +207,184 @@ def test_authorize_and_successful_void assert response.authorization end - def test_successful_auth_and_capture_with_recurring_stored_credential - stored_credential_params = { - initial_transaction: true, - reason_type: 'recurring', - initiator: 'merchant', - network_transaction_id: nil + def test_stored_credentials_with_pass_in_card + # Initial CIT authorize + initial_params = { + stored_cred_v2: true, + stored_credential: { + initial_transaction: true, + reason_type: 'recurring', + initiator: 'cardholder', + network_transaction_id: nil + } } - assert auth = @gateway.authorize(@amount, @credit_card, @options.merge({ stored_credential: stored_credential_params })) - assert_success auth - assert auth.authorization - - assert capture = @gateway.capture(@amount, auth.authorization, authorization_validated: true) - assert_success capture - - @options[:stored_credential] = { - initial_transaction: false, - reason_type: 'recurring', - initiator: 'merchant', - network_transaction_id: auth.network_transaction_id + # X.16 amount invokes par_value and association_token_data in response + assert initial = @gateway.authorize(116, @mastercard, @options.merge(initial_params)) + assert_success initial + approval_code = initial.authorization.split(';').first + ntid = initial.network_transaction_id + par_value = initial.params['par_value'] + association_token_data = initial.params['association_token_data'] + + # Subsequent unscheduled MIT purchase, with additional data + unscheduled_params = { + approval_code: approval_code, + par_value: par_value, + association_token_data: association_token_data, + stored_credential: { + reason_type: 'unscheduled', + initiator: 'merchant', + network_transaction_id: ntid + } } - - assert next_auth = @gateway.authorize(@amount, @credit_card, @options) - assert next_auth.authorization - - assert capture = @gateway.capture(@amount, next_auth.authorization, authorization_validated: true) - assert_success capture + assert unscheduled = @gateway.purchase(@amount, @mastercard, @options.merge(unscheduled_params)) + assert_success unscheduled + + # Subsequent recurring MIT purchase + recurring_params = { + approval_code: approval_code, + stored_credential: { + reason_type: 'recurring', + initiator: 'merchant', + network_transaction_id: ntid + } + } + assert recurring = @gateway.purchase(@amount, @mastercard, @options.merge(recurring_params)) + assert_success recurring + + # Subsequent installment MIT purchase + installment_params = { + installments: '4', + payment_number: '2', + approval_code: approval_code, + stored_credential: { + reason_type: 'installment', + initiator: 'merchant', + network_transaction_id: ntid + } + } + assert installment = @gateway.purchase(@amount, @mastercard, @options.merge(installment_params)) + assert_success installment + end + + def test_stored_credentials_with_tokenized_card + # Store card + assert store = @tokenization_gateway.store(@mastercard, @options) + assert_success store + stored_card = store.authorization + + # Initial CIT authorize + initial_params = { + stored_cred_v2: true, + stored_credential: { + initial_transaction: true, + reason_type: 'recurring', + initiator: 'cardholder', + network_transaction_id: nil + } + } + assert initial = @tokenization_gateway.authorize(116, stored_card, @options.merge(initial_params)) + assert_success initial + ntid = initial.network_transaction_id + par_value = initial.params['par_value'] + association_token_data = initial.params['association_token_data'] + + # Subsequent unscheduled MIT purchase, with additional data + unscheduled_params = { + par_value: par_value, + association_token_data: association_token_data, + stored_credential: { + reason_type: 'unscheduled', + initiator: 'merchant', + network_transaction_id: ntid + } + } + assert unscheduled = @tokenization_gateway.purchase(@amount, stored_card, @options.merge(unscheduled_params)) + assert_success unscheduled + + # Subsequent recurring MIT purchase + recurring_params = { + stored_credential: { + reason_type: 'recurring', + initiator: 'merchant', + network_transaction_id: ntid + } + } + assert recurring = @tokenization_gateway.purchase(@amount, stored_card, @options.merge(recurring_params)) + assert_success recurring + + # Subsequent installment MIT purchase + installment_params = { + installments: '4', + payment_number: '2', + stored_credential: { + reason_type: 'installment', + initiator: 'merchant', + network_transaction_id: ntid + } + } + assert installment = @tokenization_gateway.purchase(@amount, stored_card, @options.merge(installment_params)) + assert_success installment + end + + def test_stored_credentials_with_manual_token + # Initial CIT get token request + get_token_params = { + stored_cred_v2: true, + add_recurring_token: 'Y', + stored_credential: { + initial_transaction: true, + reason_type: 'recurring', + initiator: 'cardholder', + network_transaction_id: nil + } + } + assert get_token = @tokenization_gateway.authorize(116, @mastercard, @options.merge(get_token_params)) + assert_success get_token + ntid = get_token.network_transaction_id + token = get_token.params['token'] + par_value = get_token.params['par_value'] + association_token_data = get_token.params['association_token_data'] + + # Subsequent unscheduled MIT purchase, with additional data + unscheduled_params = { + ssl_token: token, + par_value: par_value, + association_token_data: association_token_data, + stored_credential: { + reason_type: 'unscheduled', + initiator: 'merchant', + network_transaction_id: ntid + } + } + assert unscheduled = @tokenization_gateway.purchase(@amount, @credit_card, @options.merge(unscheduled_params)) + assert_success unscheduled + + # Subsequent recurring MIT purchase + recurring_params = { + ssl_token: token, + stored_credential: { + reason_type: 'recurring', + initiator: 'merchant', + network_transaction_id: ntid + } + } + assert recurring = @tokenization_gateway.purchase(@amount, @credit_card, @options.merge(recurring_params)) + assert_success recurring + + # Subsequent installment MIT purchase + installment_params = { + ssl_token: token, + installments: '4', + payment_number: '2', + stored_credential: { + reason_type: 'installment', + initiator: 'merchant', + network_transaction_id: ntid + } + } + assert installment = @tokenization_gateway.purchase(@amount, @credit_card, @options.merge(installment_params)) + assert_success installment end def test_successful_purchase_with_recurring_token @@ -273,62 +425,6 @@ def test_successful_purchase_with_ssl_token assert_equal 'APPROVAL', purchase.message end - def test_successful_auth_and_capture_with_unscheduled_stored_credential - stored_credential_params = { - initial_transaction: true, - reason_type: 'unscheduled', - initiator: 'merchant', - network_transaction_id: nil - } - assert auth = @gateway.authorize(@amount, @credit_card, @options.merge({ stored_credential: stored_credential_params })) - assert_success auth - assert auth.authorization - - assert capture = @gateway.capture(@amount, auth.authorization, authorization_validated: true) - assert_success capture - - @options[:stored_credential] = { - initial_transaction: false, - reason_type: 'unscheduled', - initiator: 'merchant', - network_transaction_id: auth.network_transaction_id - } - - assert next_auth = @gateway.authorize(@amount, @credit_card, @options) - assert next_auth.authorization - - assert capture = @gateway.capture(@amount, next_auth.authorization, authorization_validated: true) - assert_success capture - end - - def test_successful_auth_and_capture_with_installment_stored_credential - stored_credential_params = { - initial_transaction: true, - reason_type: 'installment', - initiator: 'merchant', - network_transaction_id: nil - } - assert auth = @gateway.authorize(@amount, @credit_card, @options.merge({ stored_credential: stored_credential_params })) - assert_success auth - assert auth.authorization - - assert capture = @gateway.capture(@amount, auth.authorization, authorization_validated: true) - assert_success capture - - @options[:stored_credential] = { - initial_transaction: false, - reason_type: 'installment', - initiator: 'merchant', - network_transaction_id: auth.network_transaction_id - } - - assert next_auth = @gateway.authorize(@amount, @credit_card, @options) - assert next_auth.authorization - - assert capture = @gateway.capture(@amount, next_auth.authorization, authorization_validated: true) - assert_success capture - end - def test_successful_store_without_verify assert response = @tokenization_gateway.store(@credit_card, @options) assert_success response @@ -390,6 +486,16 @@ def test_failed_purchase_with_token assert_match %r{invalid}i, response.message end + def test_successful_authorize_with_token + store_response = @tokenization_gateway.store(@credit_card, @options) + token = store_response.params['token'] + assert response = @tokenization_gateway.authorize(@amount, token, @options) + assert_success response + assert response.test? + assert_not_empty response.params['token'] + assert_equal 'APPROVAL', response.message + end + def test_successful_purchase_with_custom_fields assert response = @gateway.purchase(@amount, @credit_card, @options.merge(custom_fields: { my_field: 'a value' })) diff --git a/test/remote/gateways/remote_fat_zebra_test.rb b/test/remote/gateways/remote_fat_zebra_test.rb index 17da0b1c94d..8e85b032369 100644 --- a/test/remote/gateways/remote_fat_zebra_test.rb +++ b/test/remote/gateways/remote_fat_zebra_test.rb @@ -233,7 +233,7 @@ def test_successful_purchase_with_3DS version: '2.0', cavv: '3q2+78r+ur7erb7vyv66vv\/\/\/\/8=', eci: '05', - ds_transaction_id: 'ODUzNTYzOTcwODU5NzY3Qw==', + ds_transaction_id: 'f25084f0-5b16-4c0a-ae5d-b24808a95e4b', enrolled: 'true', authentication_response_status: 'Y' } diff --git a/test/remote/gateways/remote_rapyd_test.rb b/test/remote/gateways/remote_rapyd_test.rb index 40e9564cc17..e90ab2de357 100644 --- a/test/remote/gateways/remote_rapyd_test.rb +++ b/test/remote/gateways/remote_rapyd_test.rb @@ -145,6 +145,14 @@ def test_successful_purchase_with_reccurence_type assert_equal 'SUCCESS', response.message end + def test_successful_purchase_with_save_payment_method + @options[:pm_type] = 'gb_visa_mo_card' + response = @gateway.purchase(@amount, @credit_card, @options.merge(save_payment_method: true)) + assert_success response + assert_equal 'SUCCESS', response.message + assert_equal true, response.params['data']['save_payment_method'] + end + def test_successful_purchase_with_address billing_address = address(name: 'Henry Winkler', address1: '123 Happy Days Lane') @@ -182,7 +190,7 @@ def test_successful_purchase_with_options def test_failed_purchase response = @gateway.purchase(@amount, @declined_card, @options) assert_failure response - assert_equal 'Do Not Honor', response.message + assert_equal 'The request attempted an operation that requires a card number, but the number was not recognized. The request was rejected. Corrective action: Use the card number of a valid card.', response.message end def test_successful_authorize_and_capture @@ -197,7 +205,7 @@ def test_successful_authorize_and_capture def test_failed_authorize response = @gateway.authorize(@amount, @declined_card, @options) assert_failure response - assert_equal 'Do Not Honor', response.message + assert_equal 'The request attempted an operation that requires a card number, but the number was not recognized. The request was rejected. Corrective action: Use the card number of a valid card.', response.message end def test_partial_capture @@ -275,7 +283,7 @@ def test_failed_purchase_with_zero_amount def test_failed_void response = @gateway.void('') assert_failure response - assert_equal 'NOT_FOUND', response.message + assert_equal 'UNAUTHORIZED_API_CALL', response.message end def test_successful_verify @@ -295,7 +303,7 @@ def test_successful_verify_with_peso def test_failed_verify response = @gateway.verify(@declined_card, @options) assert_failure response - assert_equal 'Do Not Honor', response.message + assert_equal 'The request attempted an operation that requires a card number, but the number was not recognized. The request was rejected. Corrective action: Use the card number of a valid card.', response.message end def test_successful_store_and_purchase @@ -334,7 +342,7 @@ def test_failed_unstore unstore = @gateway.unstore('') assert_failure unstore - assert_equal 'NOT_FOUND', unstore.message + assert_equal 'UNAUTHORIZED_API_CALL', unstore.message end def test_invalid_login diff --git a/test/remote/gateways/remote_stripe_payment_intents_test.rb b/test/remote/gateways/remote_stripe_payment_intents_test.rb index 730f00dd1cb..2b7d5fa2120 100644 --- a/test/remote/gateways/remote_stripe_payment_intents_test.rb +++ b/test/remote/gateways/remote_stripe_payment_intents_test.rb @@ -380,6 +380,17 @@ def test_unsuccessful_purchase refute purchase.params.dig('error', 'payment_intent', 'charges', 'data')[0]['captured'] end + def test_unsuccessful_purchase_returns_header_response + options = { + currency: 'GBP', + customer: @customer + } + assert purchase = @gateway.purchase(@amount, @declined_payment_method, options) + + assert_equal 'Your card was declined.', purchase.message + assert_not_nil purchase.params['response_headers']['stripe_should_retry'] + end + def test_successful_purchase_with_external_auth_data_3ds_1 options = { currency: 'GBP', diff --git a/test/remote/gateways/remote_stripe_test.rb b/test/remote/gateways/remote_stripe_test.rb index 85417f3c583..90f0323ecf9 100644 --- a/test/remote/gateways/remote_stripe_test.rb +++ b/test/remote/gateways/remote_stripe_test.rb @@ -207,6 +207,14 @@ def test_unsuccessful_purchase assert_match(/ch_[a-zA-Z\d]+/, response.authorization) end + def test_unsuccessful_purchase_returns_response_headers + assert response = @gateway.purchase(@amount, @declined_card, @options) + assert_failure response + assert_match %r{Your card was declined}, response.message + assert_match Gateway::STANDARD_ERROR_CODE[:card_declined], response.error_code + assert_not_nil response.params['response_headers']['stripe_should_retry'] + end + def test_unsuccessful_purchase_with_destination_and_amount destination = fixtures(:stripe_destination)[:stripe_user_id] custom_options = @options.merge(destination: destination, destination_amount: @amount + 20) diff --git a/test/unit/gateways/adyen_test.rb b/test/unit/gateways/adyen_test.rb index f88804a2178..7bbe1dc4c25 100644 --- a/test/unit/gateways/adyen_test.rb +++ b/test/unit/gateways/adyen_test.rb @@ -262,6 +262,16 @@ def test_failed_authorize assert_failure response end + def test_failure_authorize_with_transient_error + @gateway.instance_variable_set(:@response_headers, { 'transient-error' => 'error_will_robinson' }) + @gateway.expects(:ssl_post).returns(failed_authorize_response) + + response = @gateway.authorize(@amount, @credit_card, @options) + assert_failure response + assert response.params['response_headers']['transient_error'], 'error_will_robinson' + assert response.test? + end + def test_standard_error_code_mapping @gateway.expects(:ssl_post).returns(failed_billing_field_response) diff --git a/test/unit/gateways/datatrans_test.rb b/test/unit/gateways/datatrans_test.rb index e66f9cd6ccd..0c249bf6777 100644 --- a/test/unit/gateways/datatrans_test.rb +++ b/test/unit/gateways/datatrans_test.rb @@ -325,9 +325,9 @@ def test_authorization_from assert_equal '|9248|', @gateway.send(:authorization_from, { 'acquirerAuthorizationCode' => '9248' }, '', {}) assert_equal nil, @gateway.send(:authorization_from, {}, '', {}) # tes for store - assert_equal '||any_alias-any_month-any_year', @gateway.send(:authorization_from, { 'responses' => [{ 'alias' => 'any_alias' }] }, 'tokenize', { expiry_month: 'any_month', expiry_year: 'any_year' }) + assert_equal '||any_alias|any_month|any_year', @gateway.send(:authorization_from, { 'responses' => [{ 'alias' => 'any_alias' }] }, 'tokenize', { expiry_month: 'any_month', expiry_year: 'any_year' }) # handle nil responses or missing keys - assert_equal '||-any_month-any_year', @gateway.send(:authorization_from, {}, 'tokenize', { expiry_month: 'any_month', expiry_year: 'any_year' }) + assert_equal '|||any_month|any_year', @gateway.send(:authorization_from, {}, 'tokenize', { expiry_month: 'any_month', expiry_year: 'any_year' }) end def test_parse diff --git a/test/unit/gateways/decidir_plus_test.rb b/test/unit/gateways/decidir_plus_test.rb index 26a783a2984..0d05c967e7b 100644 --- a/test/unit/gateways/decidir_plus_test.rb +++ b/test/unit/gateways/decidir_plus_test.rb @@ -77,6 +77,15 @@ def test_successful_capture end.respond_with(successful_purchase_response) end + def test_failed_refund_for_validation_errors + response = stub_comms(@gateway, :ssl_request) do + @gateway.refund(@amount, '12420186') + end.respond_with(failed_credit_message_response) + + assert_failure response + assert_equal('invalid_status_error - status: refunded', response.message) + end + def test_failed_authorize response = stub_comms(@gateway, :ssl_request) do @gateway.authorize(@amount, @credit_card, @options) @@ -336,6 +345,12 @@ def failed_purchase_message_response } end + def failed_credit_message_response + %{ + {\"error_type\":\"invalid_status_error\",\"validation_errors\":{\"status\":\"refunded\"}} + } + end + def successful_refund_response %{ {\"id\":417921,\"amount\":100,\"sub_payments\":null,\"error\":null,\"status\":\"approved\",\"status_details\":{\"ticket\":\"4589\",\"card_authorization_code\":\"173711\",\"address_validation_code\":\"VTE0011\",\"error\":null}} diff --git a/test/unit/gateways/elavon_test.rb b/test/unit/gateways/elavon_test.rb index 49f8ca8c207..760d210e927 100644 --- a/test/unit/gateways/elavon_test.rb +++ b/test/unit/gateways/elavon_test.rb @@ -26,6 +26,7 @@ def setup @credit_card = credit_card @amount = 100 + @stored_card = '4421912014039990' @options = { order_id: '1', @@ -45,9 +46,12 @@ def setup end def test_successful_purchase - @gateway.expects(:ssl_post).returns(successful_purchase_response) + response = stub_comms do + @gateway.purchase(@amount, @credit_card, @options.merge!(stored_cred_v2: true)) + end.check_request do |_endpoint, data, _headers| + assert_match(/123<\/ssl_cvv2cvc2>/, data) + end.respond_with(successful_purchase_response) - assert response = @gateway.purchase(@amount, @credit_card, @options) assert_success response assert_equal '093840;180820AD3-27AEE6EF-8CA7-4811-8D1F-E420C3B5041E', response.authorization assert response.test? @@ -182,13 +186,23 @@ def test_sends_ssl_add_token_field end def test_sends_ssl_token_field - response = stub_comms do + purchase_response = stub_comms do @gateway.purchase(@amount, @credit_card, @options.merge(ssl_token: '8675309')) end.check_request do |_endpoint, data, _headers| assert_match(/8675309<\/ssl_token>/, data) + refute_match(/8675309<\/ssl_token>/, data) + refute_match(/#{oar_data}<\/ssl_oar_data>/, data) assert_match(/#{ps2000_data}<\/ssl_ps2000_data>/, data) @@ -386,10 +400,276 @@ def test_oar_only_network_transaction_id ps2000_data = nil network_transaction_id = "#{oar_data}|#{ps2000_data}" stub_comms do - @gateway.purchase(@amount, @credit_card, @options.merge(stored_credential: { network_transaction_id: network_transaction_id })) + @gateway.purchase(@amount, @credit_card, @options.merge(stored_credential: { initiator: 'merchant', reason_type: 'recurring', network_transaction_id: network_transaction_id })) end.check_request do |_endpoint, data, _headers| assert_match(/#{oar_data}<\/ssl_oar_data>/, data) - refute_match(//, data) + refute_match(/123<\/ssl_cvv2cvc2>/, data) + assert_match(/1<\/ssl_recurring_flag>/, data) + refute_match(/A7540295892588345510A<\/ssl_ps2000_data>/, data) + assert_match(/010012130901291622040000047554200000000000155836402916121309<\/ssl_oar_data>/, data) + assert_match(/1234566<\/ssl_approval_code>/, data) + assert_match(/1<\/ssl_recurring_flag>/, data) + refute_match(/A7540295892588345510A<\/ssl_ps2000_data>/, data) + assert_match(/010012130901291622040000047554200000000000155836402916121309<\/ssl_oar_data>/, data) + assert_match(/1234566<\/ssl_approval_code>/, data) + assert_match(/2<\/ssl_recurring_flag>/, data) + assert_match(/2<\/ssl_payment_number>/, data) + assert_match(/4<\/ssl_payment_count>/, data) + refute_match(/A7540295892588345510A<\/ssl_ps2000_data>/, data) + assert_match(/010012130901291622040000047554200000000000155836402916121309<\/ssl_oar_data>/, data) + assert_match(/1234566<\/ssl_approval_code>/, data) + assert_match(/Y<\/ssl_merchant_initiated_unscheduled>/, data) + assert_match(/12<\/ssl_entry_mode>/, data) + assert_match(/1234567890<\/ssl_par_value>/, data) + assert_match(/1<\/ssl_association_token_data>/, data) + refute_match(/1<\/ssl_recurring_flag>/, data) + refute_match(/1<\/ssl_recurring_flag>/, data) + refute_match(/2<\/ssl_recurring_flag>/, data) + assert_match(/2<\/ssl_payment_number>/, data) + assert_match(/4<\/ssl_payment_count>/, data) + refute_match(/Y<\/ssl_merchant_initiated_unscheduled>/, data) + assert_match(/1234567890<\/ssl_par_value>/, data) + assert_match(/1<\/ssl_association_token_data>/, data) + refute_match(/1<\/ssl_recurring_flag>/, data) + refute_match(/2<\/ssl_recurring_flag>/, data) + assert_match(/2<\/ssl_payment_number>/, data) + assert_match(/4<\/ssl_payment_count>/, data) + refute_match(/Y<\/ssl_merchant_initiated_unscheduled>/, data) + assert_match(/1234567890<\/ssl_par_value>/, data) + assert_match(/1<\/ssl_association_token_data>/, data) + refute_match(//, data) + refute_match(/#{ps2000_data}<\/ssl_ps2000_data>/, data) end.respond_with(successful_purchase_response) end @@ -408,19 +688,19 @@ def test_ps2000_only_network_transaction_id def test_oar_transaction_id_without_pipe oar_data = '010012318808182231420000047554200000000000093840023122123188' stub_comms do - @gateway.purchase(@amount, @credit_card, @options.merge(stored_credential: { network_transaction_id: oar_data })) + @gateway.purchase(@amount, @credit_card, @options.merge(stored_credential: { initiator: 'merchant', reason_type: 'recurring', network_transaction_id: oar_data })) end.check_request do |_endpoint, data, _headers| assert_match(/#{oar_data}<\/ssl_oar_data>/, data) - refute_match(//, data) + refute_match(//, data) + refute_match(/#{ps2000_data}<\/ssl_ps2000_data>/, data) end.respond_with(successful_purchase_response) end diff --git a/test/unit/gateways/fat_zebra_test.rb b/test/unit/gateways/fat_zebra_test.rb index 3caf94852dc..dfb33d78355 100644 --- a/test/unit/gateways/fat_zebra_test.rb +++ b/test/unit/gateways/fat_zebra_test.rb @@ -25,6 +25,7 @@ def setup eci: '05', xid: 'ODUzNTYzOTcwODU5NzY3Qw==', enrolled: 'true', + ds_transaction_id: 'f25084f0-5b16-4c0a-ae5d-b24808a95e4b', authentication_response_status: 'Y' } end @@ -235,7 +236,7 @@ def test_three_ds_v2_object_construction assert_equal ds_options[:cavv], ds_data[:cavv] assert_equal ds_options[:eci], ds_data[:sli] assert_equal ds_options[:xid], ds_data[:xid] - assert_equal ds_options[:ds_transaction_id], ds_data[:ds_transaction_id] + assert_equal ds_options[:ds_transaction_id], ds_data[:directory_server_txn_id] assert_equal 'Y', ds_data[:ver] assert_equal ds_options[:authentication_response_status], ds_data[:par] end diff --git a/test/unit/gateways/mercury_test.rb b/test/unit/gateways/mercury_test.rb index d9b2e8d9cd0..5defed1713e 100644 --- a/test/unit/gateways/mercury_test.rb +++ b/test/unit/gateways/mercury_test.rb @@ -126,7 +126,7 @@ def test_transcript_scrubbing def successful_purchase_response <<~RESPONSE - + Processor @@ -163,7 +163,7 @@ def successful_purchase_response def failed_purchase_response <<~RESPONSE - + Server @@ -179,7 +179,7 @@ def failed_purchase_response def successful_refund_response <<~RESPONSE - + Processor diff --git a/test/unit/gateways/paypal_test.rb b/test/unit/gateways/paypal_test.rb index db9f5c760a0..7f8bd050e1f 100644 --- a/test/unit/gateways/paypal_test.rb +++ b/test/unit/gateways/paypal_test.rb @@ -1312,7 +1312,7 @@ def failed_create_profile_paypal_response - " + RESPONSE end diff --git a/test/unit/gateways/rapyd_test.rb b/test/unit/gateways/rapyd_test.rb index 43f93789952..cb60bdae4a5 100644 --- a/test/unit/gateways/rapyd_test.rb +++ b/test/unit/gateways/rapyd_test.rb @@ -182,6 +182,16 @@ def test_success_purchase_with_recurrence_type end.respond_with(successful_purchase_response) end + def test_successful_purchase_with_save_payment_method + response = stub_comms(@gateway, :ssl_request) do + @gateway.purchase(@amount, @credit_card, @options.merge({ save_payment_method: true })) + end.check_request do |_method, _endpoint, data, _headers| + assert_match(/"save_payment_method":true/, data) + end.respond_with(successful_authorize_response) + + assert_success response + end + def test_successful_purchase_with_3ds_global @options[:three_d_secure] = { required: true, diff --git a/test/unit/gateways/stripe_payment_intents_test.rb b/test/unit/gateways/stripe_payment_intents_test.rb index 241977f0550..989b19096b3 100644 --- a/test/unit/gateways/stripe_payment_intents_test.rb +++ b/test/unit/gateways/stripe_payment_intents_test.rb @@ -315,6 +315,15 @@ def test_successful_purchase end.respond_with(successful_create_intent_response) end + def test_failed_authorize_with_idempotent_replayed + @gateway.instance_variable_set(:@response_headers, { 'idempotent-replayed' => 'true' }) + @gateway.expects(:ssl_request).returns(failed_payment_method_response) + + response = @gateway.authorize(@amount, @credit_card, @options) + assert_failure response + assert response.params['response_headers']['idempotent_replayed'], 'true' + end + def test_failed_error_on_requires_action @gateway.expects(:ssl_request).returns(failed_with_set_error_on_requires_action_response) diff --git a/test/unit/gateways/stripe_test.rb b/test/unit/gateways/stripe_test.rb index 1ce0e52c96c..36af54cb72c 100644 --- a/test/unit/gateways/stripe_test.rb +++ b/test/unit/gateways/stripe_test.rb @@ -835,6 +835,19 @@ def test_declined_request assert_equal 'ch_test_charge', response.authorization end + def test_declined_request_returns_header_response + @gateway.instance_variable_set(:@response_headers, { 'idempotent-replayed' => 'true' }) + @gateway.expects(:ssl_request).returns(declined_purchase_response) + + assert response = @gateway.purchase(@amount, @credit_card, @options) + assert_failure response + + assert_equal Gateway::STANDARD_ERROR_CODE[:card_declined], response.error_code + refute response.test? # unsuccessful request defaults to live + assert_equal 'ch_test_charge', response.authorization + assert response.params['response_headers']['idempotent_replayed'], 'true' + end + def test_declined_request_advanced_decline_codes @gateway.expects(:ssl_request).returns(declined_call_issuer_purchase_response) diff --git a/test/unit/gateways/trans_first_test.rb b/test/unit/gateways/trans_first_test.rb index d8a2ca93ed2..94b5fdeff38 100644 --- a/test/unit/gateways/trans_first_test.rb +++ b/test/unit/gateways/trans_first_test.rb @@ -15,16 +15,6 @@ def setup @amount = 100 end - def test_missing_field_response - @gateway.stubs(:ssl_post).returns(missing_field_response) - - response = @gateway.purchase(@amount, @credit_card, @options) - - assert_failure response - assert response.test? - assert_equal 'Missing parameter: UserId.', response.message - end - def test_successful_purchase @gateway.stubs(:ssl_post).returns(successful_purchase_response)