Skip to content

Commit

Permalink
CyberSource: Add line_item for purchase
Browse files Browse the repository at this point in the history
Closes #4282

Added `line_items` field to be passed in purchase method also for cyber
source implementation.

CE-2240

Unit:
5044 tests, 74980 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Rubocop:
728 files inspected, no offenses detected

Remote:
101 tests, 520 assertions, 6 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
94.0594% passed
  • Loading branch information
ajawadmirza authored and jessiagee committed Jan 19, 2022
1 parent 1734367 commit 0958750
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
* Orbital: Add support for $0 verify [javierpedrozaing] #4275
* Update inline documentation with all supported cardtypes [ali-hassan] #4283
* PayWay: Update endpoints, response code [jessiagee] #4281
* CyberSource: Add `line_items` for purchase [ajawadmirza] #4282

== Version 1.124.0 (October 28th, 2021)
* Worldpay: Add Support for Submerchant Data on Worldpay [almalee24] #4147
Expand Down
6 changes: 3 additions & 3 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, true)
add_payment_method_or_subscription(xml, money, creditcard_or_reference, options)
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 @@ -881,7 +881,7 @@ def add_check_payment_method(xml)
end
end

def add_payment_method_or_subscription(xml, money, payment_method_or_reference, options, include_items = false)
def add_payment_method_or_subscription(xml, money, payment_method_or_reference, options)
if payment_method_or_reference.is_a?(String)
add_purchase_data(xml, money, true, options)
add_installments(xml, options)
Expand All @@ -894,7 +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_line_item_data(xml, options)
add_purchase_data(xml, money, true, options)
add_installments(xml, options)
add_creditcard(xml, payment_method_or_reference)
Expand Down
10 changes: 2 additions & 8 deletions test/remote/gateways/remote_cyber_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,8 @@ def setup
code: 'default',
description: 'Giant Walrus',
sku: 'WA323232323232323',
tax_amount: 5,
national_tax: 10
},
{
declared_value: 100,
quantity: 2,
description: 'Marble Snowcone',
sku: 'FAKE1232132113123'
tax_amount: 10,
national_tax: 5
}
],
currency: 'USD',
Expand Down
25 changes: 15 additions & 10 deletions test/unit/gateways/cyber_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,8 @@ def setup
code: 'default',
description: 'Giant Walrus',
sku: 'WA323232323232323',
tax_amount: '5',
national_tax: '10'
},
{
declared_value: @amount,
quantity: 2,
description: 'Marble Snowcone',
sku: 'FAKE1232132113123',
tax_amount: '4',
national_tax: '8'
tax_amount: '10',
national_tax: '5'
}
],
currency: 'USD'
Expand Down Expand Up @@ -492,6 +484,19 @@ def test_successful_credit_card_purchase_request
assert response.test?
end

def test_successful_credit_card_purchase_request_with_line_items
stub_comms do
@gateway.purchase(@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_purchase_response)
end

def test_successful_credit_card_purchase_with_elo_request
@gateway.stubs(:ssl_post).returns(successful_capture_response)
assert response = @gateway.purchase(@amount, @elo_credit_card, @options)
Expand Down

0 comments on commit 0958750

Please sign in to comment.