From 21d987dcaaa5d2401eaecf9430d707b157130584 Mon Sep 17 00:00:00 2001 From: Alma Malambo Date: Fri, 28 Jul 2023 09:39:47 -0500 Subject: [PATCH] Cybersource: Add merchant_id Set the merchantId filed to options[:merchant_id] instead of @options[:login] if available. Cybersource Unit: 136 tests, 641 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 100% passed CybersourceRest Unit: 30 tests, 144 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 100% passed --- CHANGELOG | 1 + lib/active_merchant/billing/gateways/cyber_source.rb | 2 +- lib/active_merchant/billing/gateways/cyber_source_rest.rb | 6 +++--- test/unit/gateways/cyber_source_rest_test.rb | 5 +++-- test/unit/gateways/cyber_source_test.rb | 3 ++- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 183c18ef217..de02f873158 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ * Braintree: Support third party Network Tokens [aenand] #4775 * Kushki: Fix add amount default method for subtotalIva and subtotalIva0 [yunnydang] #4845 * Rapyd: Add customer object to requests [aenand] #4838 +* CyberSource: Add merchant_id [almalee24] #4844 == Version 1.134.0 (July 25, 2023) * Update required Ruby version [almalee24] #4823 diff --git a/lib/active_merchant/billing/gateways/cyber_source.rb b/lib/active_merchant/billing/gateways/cyber_source.rb index dce4ed14941..ec015454ddc 100644 --- a/lib/active_merchant/billing/gateways/cyber_source.rb +++ b/lib/active_merchant/billing/gateways/cyber_source.rb @@ -556,7 +556,7 @@ def add_line_item_data(xml, options) end def add_merchant_data(xml, options) - xml.tag! 'merchantID', @options[:login] + xml.tag! 'merchantID', options[:merchant_id] || @options[:login] xml.tag! 'merchantReferenceCode', options[:order_id] || generate_unique_id xml.tag! 'clientLibrary', 'Ruby Active Merchant' xml.tag! 'clientLibraryVersion', VERSION diff --git a/lib/active_merchant/billing/gateways/cyber_source_rest.rb b/lib/active_merchant/billing/gateways/cyber_source_rest.rb index b4e58bdd635..28c4d9d6f12 100644 --- a/lib/active_merchant/billing/gateways/cyber_source_rest.rb +++ b/lib/active_merchant/billing/gateways/cyber_source_rest.rb @@ -330,7 +330,7 @@ def commit(action, post, options = {}) add_reconciliation_id(post, options) add_sec_code(post, options) add_invoice_number(post, options) - response = parse(ssl_post(url(action), post.to_json, auth_headers(action, post))) + response = parse(ssl_post(url(action), post.to_json, auth_headers(action, options, post))) Response.new( success_from(response), message_from(response), @@ -396,14 +396,14 @@ def sign_payload(payload) Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', decoded_key, payload)) end - def auth_headers(action, post, http_method = 'post') + def auth_headers(action, options, post, http_method = 'post') digest = "SHA-256=#{Digest::SHA256.base64digest(post.to_json)}" if post.present? date = Time.now.httpdate { 'Accept' => 'application/hal+json;charset=utf-8', 'Content-Type' => 'application/json;charset=utf-8', - 'V-C-Merchant-Id' => @options[:merchant_id], + 'V-C-Merchant-Id' => options[:merchant_id] || @options[:merchant_id], 'Date' => date, 'Host' => host, 'Signature' => get_http_signature(action, digest, http_method, date), diff --git a/test/unit/gateways/cyber_source_rest_test.rb b/test/unit/gateways/cyber_source_rest_test.rb index 6c9bc3091c5..f6ba1b40eba 100644 --- a/test/unit/gateways/cyber_source_rest_test.rb +++ b/test/unit/gateways/cyber_source_rest_test.rb @@ -204,9 +204,10 @@ def test_authorize_apple_pay_visa def test_authorize_google_pay_master_card stub_comms do - @gateway.authorize(100, @google_pay_mc, @options) - end.check_request do |_endpoint, data, _headers| + @gateway.authorize(100, @google_pay_mc, @options.merge(merchant_id: 'MerchantId')) + end.check_request do |_endpoint, data, headers| request = JSON.parse(data) + assert_equal 'MerchantId', headers['V-C-Merchant-Id'] assert_equal '002', request['paymentInformation']['tokenizedCard']['type'] assert_equal '1', request['paymentInformation']['tokenizedCard']['transactionType'] assert_nil request['paymentInformation']['tokenizedCard']['requestorId'] diff --git a/test/unit/gateways/cyber_source_test.rb b/test/unit/gateways/cyber_source_test.rb index b87a5b8a493..55505cc09a8 100644 --- a/test/unit/gateways/cyber_source_test.rb +++ b/test/unit/gateways/cyber_source_test.rb @@ -66,8 +66,9 @@ def test_successful_credit_card_purchase def test_successful_purchase_with_other_tax_fields stub_comms do - @gateway.purchase(100, @credit_card, @options.merge(national_tax_indicator: 1, vat_tax_rate: 1.01)) + @gateway.purchase(100, @credit_card, @options.merge!(national_tax_indicator: 1, vat_tax_rate: 1.01, merchant_id: 'MerchantId')) end.check_request do |_endpoint, data, _headers| + assert_match(/MerchantId<\/merchantID>/, data) assert_match(/\s+1.01<\/vatTaxRate>\s+1<\/nationalTaxIndicator>\s+<\/otherTax>/m, data) end.respond_with(successful_purchase_response) end