Skip to content

Commit

Permalink
CyberSource: Add line_items for authorize method
Browse files Browse the repository at this point in the history
Added `line_items` field to be passed in for authorize method in cyber
source implementation.

CE-2240

Remote:
101 tests, 520 assertions, 6 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
94.0594% passed

Unit:
5023 tests, 74856 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Rubocop:
725 files inspected, no offenses detected

Closes #4268
  • Loading branch information
ajawadmirza authored and meagabeth committed Jan 13, 2022
1 parent 68ea982 commit e9cdb18
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
* CheckoutV2: Add support for Apple Pay and Google Pay tokens [AMHOL] #4235
* Decidir Plus: Update payment reference [naashton] #4271
* Paysafe: Update redact method [meagabeth] #4269
* CyberSource: Add `line_items` field in authorize method [ajawadmirza] #4268

== Version 1.124.0 (October 28th, 2021)
* Worldpay: Add Support for Submerchant Data on Worldpay [almalee24] #4147
Expand Down
7 changes: 5 additions & 2 deletions lib/active_merchant/billing/gateways/cyber_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def check_billing_field_value(default, submitted)
def build_auth_request(money, creditcard_or_reference, options)
xml = Builder::XmlMarkup.new indent: 2
add_customer_id(xml, options)
add_payment_method_or_subscription(xml, money, creditcard_or_reference, options)
add_payment_method_or_subscription(xml, money, creditcard_or_reference, options, true)
add_threeds_2_ucaf_data(xml, creditcard_or_reference, options)
add_decision_manager_fields(xml, options)
add_mdd_fields(xml, options)
Expand Down Expand Up @@ -500,6 +500,8 @@ def extract_option(prioritized_options, option_name)
end

def add_line_item_data(xml, options)
return unless options[:line_items]

options[:line_items].each_with_index do |value, index|
xml.tag! 'item', { 'id' => index } do
xml.tag! 'unitPrice', localized_amount(value[:declared_value].to_i, options[:currency] || default_currency)
Expand Down Expand Up @@ -879,7 +881,7 @@ def add_check_payment_method(xml)
end
end

def add_payment_method_or_subscription(xml, money, payment_method_or_reference, options)
def add_payment_method_or_subscription(xml, money, payment_method_or_reference, options, include_items = false)
if payment_method_or_reference.is_a?(String)
add_purchase_data(xml, money, true, options)
add_installments(xml, options)
Expand All @@ -892,6 +894,7 @@ def add_payment_method_or_subscription(xml, money, payment_method_or_reference,
else
add_address(xml, payment_method_or_reference, options[:billing_address], options)
add_address(xml, payment_method_or_reference, options[:shipping_address], options, true)
add_line_item_data(xml, options) if include_items
add_purchase_data(xml, money, true, options)
add_installments(xml, options)
add_creditcard(xml, payment_method_or_reference)
Expand Down
13 changes: 13 additions & 0 deletions test/unit/gateways/cyber_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,19 @@ def test_successful_credit_card_tax_request_with_amounts
end.respond_with(successful_tax_response)
end

def test_successful_credit_card_authorize_request_with_line_items
stub_comms do
@gateway.authorize(@amount, @credit_card, @options)
end.check_request do |_endpoint, data, _headers|
doc = REXML::Document.new(data)
REXML::XPath.each(doc, '//item') do |item|
request_item = @options[:line_items][item.attributes['id'].to_i]
assert_match(request_item[:tax_amount], item.get_elements('taxAmount')[0].text)
assert_match(request_item[:national_tax], item.get_elements('nationalTax')[0].text)
end
end.respond_with(successful_tax_response)
end

def test_successful_credit_card_capture_request
@gateway.stubs(:ssl_post).returns(successful_authorization_response, successful_capture_response)
assert response = @gateway.authorize(@amount, @credit_card, @options)
Expand Down

0 comments on commit e9cdb18

Please sign in to comment.