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: Add merchant_id #4844

Merged
merged 1 commit into from
Aug 4, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/active_merchant/billing/gateways/cyber_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Contributor

Choose a reason for hiding this comment

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

options vs @options here is interesting. This makes sense, since it looks like @options is a hash for "gateway options" and options is a hash for "request options", so merchant_id is passed after the gateway was originally created.

xml.tag! 'merchantReferenceCode', options[:order_id] || generate_unique_id
xml.tag! 'clientLibrary', 'Ruby Active Merchant'
xml.tag! 'clientLibraryVersion', VERSION
Expand Down
6 changes: 3 additions & 3 deletions lib/active_merchant/billing/gateways/cyber_source_rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions test/unit/gateways/cyber_source_rest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
3 changes: 2 additions & 1 deletion test/unit/gateways/cyber_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<\/merchantID>/, data)
assert_match(/<otherTax>\s+<vatTaxRate>1.01<\/vatTaxRate>\s+<nationalTaxIndicator>1<\/nationalTaxIndicator>\s+<\/otherTax>/m, data)
end.respond_with(successful_purchase_response)
end
Expand Down
Loading