-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary ---------------- This adds the L2/L3 fields required in purchase, authorize and capture transactions [SER-1554](https://spreedly.atlassian.net/browse/SER-1554) Unit Tests ---------------- Finished in 0.282324 seconds. 70 tests, 481 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 100% passed Remote Tests ---------------- Finished in 164.547288 seconds. 116 tests, 280 assertions, 7 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 93.9655% passed Rubocop ---------------- 806 files inspected, no offenses detected
- Loading branch information
Showing
3 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,46 @@ def setup | |
@credit_card = credit_card | ||
@amount = 100 | ||
@token = '2MPedsuenG2o8yFfrsdOBWmOuEf' | ||
|
||
@lvl_2_3_options = { | ||
order_id: '1', | ||
billing_address: address, | ||
shipping_address: address, | ||
description: 'Purchase', | ||
email: '[email protected]', | ||
processing_channel_id: 'pc_lxgl7aqahkzubkundd2l546hdm', | ||
invoice_id: 12462, | ||
tax_number: 123456, | ||
from_address_zip: 12345, | ||
tax_amount: 30, | ||
shipping_amount: 20, | ||
discount_amount: 10, | ||
duty_amount: 5, | ||
line_items: [ | ||
{ # only for American Express in level 2 or any lvl 3 | ||
commodity_code: 123, | ||
name: 'glass', | ||
quantity: 1, | ||
unit_price: 200, | ||
tax_amount: 12, | ||
discount_amount: 12, | ||
total_amount: 200, | ||
reference: 'glass123', | ||
unit_of_measure: 'Centimeters' | ||
}, | ||
{ | ||
commodity_code: 456, | ||
name: 'water', | ||
quantity: 2, | ||
unit_price: 100, | ||
tax_amount: 6, | ||
discount_amount: 6, | ||
total_amount: 100, | ||
reference: 'water123', | ||
unit_of_measure: 'Liters' | ||
} | ||
] | ||
} | ||
end | ||
|
||
def test_supported_card_types | ||
|
@@ -1115,6 +1155,89 @@ def test_authorize_supports_alternate_credit_card_implementation | |
end.respond_with(successful_authorize_response) | ||
end | ||
|
||
def test_authorize_with_level_2_3_data | ||
response = stub_comms(@gateway, :ssl_request) do | ||
@gateway.authorize(@amount, @credit_card, @lvl_2_3_options) | ||
end.check_request do |_method, _endpoint, data, _headers| | ||
request = JSON.parse(data) | ||
assert_equal request.dig('customer', 'tax_number'), 123456 | ||
assert_equal request.dig('processing', 'order_id'), 12462 | ||
assert_equal request.dig('processing', 'tax_amount'), 30 | ||
assert_equal request.dig('processing', 'discount_amount'), 10 | ||
assert_equal request.dig('processing', 'shipping_amount'), 20 | ||
assert_equal request.dig('processing', 'duty_amount'), 5 | ||
assert_equal request.dig('shipping', 'from_address_zip'), 12345 | ||
|
||
item_one = request['items'][0] | ||
item_two = request['items'][1] | ||
|
||
assert_equal item_one['reference'], 'glass123' | ||
assert_equal item_one['name'], 'glass' | ||
assert_equal item_one['quantity'], 1 | ||
assert_equal item_one['unit_price'], 200 | ||
assert_equal item_one['tax_amount'], 12 | ||
assert_equal item_one['discount_amount'], 12 | ||
assert_equal item_one['total_amount'], 200 | ||
assert_equal item_one['commodity_code'], 123 | ||
assert_equal item_one['unit_of_measure'], 'Centimeters' | ||
|
||
assert_equal item_two['reference'], 'water123' | ||
assert_equal item_two['name'], 'water' | ||
assert_equal item_two['quantity'], 2 | ||
assert_equal item_two['unit_price'], 100 | ||
assert_equal item_two['tax_amount'], 6 | ||
assert_equal item_two['discount_amount'], 6 | ||
assert_equal item_two['total_amount'], 100 | ||
assert_equal item_two['commodity_code'], 456 | ||
assert_equal item_two['unit_of_measure'], 'Liters' | ||
end.respond_with(successful_authorize_response) | ||
|
||
assert_success response | ||
assert_equal 'Succeeded', response.message | ||
assert_equal 'pay_fj3xswqe3emuxckocjx6td73ni', response.authorization | ||
end | ||
|
||
def test_capture_with_level_2_3_data | ||
response = stub_comms(@gateway, :ssl_request) do | ||
@gateway.capture(@amount, 'some_value', @lvl_2_3_options) | ||
end.check_request do |_method, _endpoint, data, _headers| | ||
request = JSON.parse(data) | ||
assert_equal request.dig('customer', 'tax_number'), 123456 | ||
assert_equal request.dig('processing', 'order_id'), 12462 | ||
assert_equal request.dig('processing', 'tax_amount'), 30 | ||
assert_equal request.dig('processing', 'discount_amount'), 10 | ||
assert_equal request.dig('processing', 'duty_amount'), 5 | ||
assert_equal request.dig('processing', 'shipping_amount'), 20 | ||
assert_equal request.dig('shipping', 'from_address_zip'), 12345 | ||
|
||
item_one = request['items'][0] | ||
item_two = request['items'][1] | ||
|
||
assert_equal item_one['name'], 'glass' | ||
assert_equal item_one['quantity'], 1 | ||
assert_equal item_one['unit_price'], 200 | ||
assert_equal item_one['reference'], 'glass123' | ||
assert_equal item_one['commodity_code'], 123 | ||
assert_equal item_one['unit_of_measure'], 'Centimeters' | ||
assert_equal item_one['total_amount'], 200 | ||
assert_equal item_one['tax_amount'], 12 | ||
assert_equal item_one['discount_amount'], 12 | ||
|
||
assert_equal item_two['reference'], 'water123' | ||
assert_equal item_two['name'], 'water' | ||
assert_equal item_two['quantity'], 2 | ||
assert_equal item_two['unit_price'], 100 | ||
assert_equal item_two['tax_amount'], 6 | ||
assert_equal item_two['discount_amount'], 6 | ||
assert_equal item_two['total_amount'], 100 | ||
assert_equal item_two['commodity_code'], 456 | ||
assert_equal item_two['unit_of_measure'], 'Liters' | ||
end.respond_with(successful_capture_response) | ||
|
||
assert_success response | ||
assert_equal 'Succeeded', response.message | ||
end | ||
|
||
private | ||
|
||
def pre_scrubbed | ||
|