Skip to content

Commit

Permalink
BMH-2869 Added test cases for level2/3 methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sivakumargandikota committed Jan 18, 2024
1 parent 9210319 commit f68c74d
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/active_merchant/billing/gateways/litle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ def add_level_two_data(doc, payment_method, options = {})
case payment_method.brand
when 'visa'
doc.salesTax(level_2_data[:sales_tax]) if level_2_data[:sales_tax]
doc.taxExempt(true) if level_2_data[:sales_tax] == 0
when 'master'
doc.customerReference(level_2_data[:customer_code]) if level_2_data[:customer_code]
doc.salesTax(level_2_data[:total_tax_amount]) if level_2_data[:total_tax_amount]
doc.taxExempt(true) if level_2_data[:total_tax_amount] == 0
doc.detailTax do
doc.taxIncludedInTotal(level_2_data[:tax_included_in_total]) if level_2_data[:tax_included_in_total]
doc.taxAmount(level_2_data[:tax_amount]) if level_2_data[:tax_amount]
Expand Down Expand Up @@ -91,6 +93,7 @@ def add_level_three_information_tags_visa(doc, payment_method, level_3_data)
def add_level_three_information_tags_master(doc, payment_method, level_3_data)
doc.customerReference :customerReference, level_3_data[:customer_code] if level_3_data[:customer_code]
doc.salesTax(level_3_data[:total_tax_amount]) if level_3_data[:total_tax_amount]
doc.taxExempt(true) if level_3_data[:total_tax_amount] == 0
doc.detailTax do
doc.taxIncludedInTotal(level_3_data[:tax_included_in_total]) if level_3_data[:tax_included_in_total]
doc.taxAmount(level_3_data[:tax_amount]) if level_3_data[:tax_amount]
Expand Down Expand Up @@ -119,6 +122,7 @@ def add_line_item_information_for_level_three_visa(doc, payment_method, level_3_
doc.taxAmount(line_item[:tax_amount]) if line_item[:tax_amount]
doc.itemDiscountAmount(line_item[:discount_per_line_item]) unless line_item[:discount_per_line_item] < 0
doc.unitCost(line_item[:unit_cost]) unless line_item[:unit_cost] < 0
doc.lineItemTotal(line_item[:line_item_total]) if line_item[:line_item_total]
doc.detailTax do
doc.taxIncludedInTotal(line_item[:tax_included_in_total]) if line_item[:tax_included_in_total]
doc.taxAmount(line_item[:tax_amount]) if line_item[:tax_amount]
Expand Down
97 changes: 97 additions & 0 deletions test/unit/gateways/litle_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,103 @@ def test_passing_merchant_data
end.respond_with(successful_purchase_response)
end

def test_passing_level_2_data_with_sales_tax_0_for_visa
options = @options.merge(
level_2_data: {
sales_tax: 0
}
)
stub_comms do
@gateway.purchase(@amount, @decrypted_apple_pay, options)
end.check_request do |_endpoint, data, _headers|
assert_match(%r(<taxExempt>true</taxExempt>), data)
assert_match(%r(<salesTax>0</salesTax>), data)
end.respond_with(successful_purchase_response)
end

def test_passing_level_2_data_with_sales_tax_0_for_mastercard
options = @options.merge(
level_2_data: {
total_tax_amount: 0
}
)
credit_card = CreditCard.new(
first_name: 'John',
last_name: 'Smith',
month: '01',
year: '2024',
brand: 'master',
number: '5555555555554444',
verification_value: '349'
)
stub_comms do
@gateway.purchase(@amount, credit_card, options)
end.check_request do |_endpoint, data, _headers|
assert_match(%r(<taxExempt>true</taxExempt>), data)
assert_match(%r(<salesTax>0</salesTax>), data)
end.respond_with(successful_purchase_response)
end

def test_passing_level_3_data_for_mastercard
options = @options.merge(
level_3_data: {
total_tax_amount: 0,
line_items: [{
product_code: 'test',
item_description: 'Legal services',
quantity: 1,
unit_of_measure: 'EA',
line_item_total: 500
}]
}
)
credit_card = CreditCard.new(
first_name: 'John',
last_name: 'Smith',
month: '01',
year: '2024',
brand: 'master',
number: '5555555555554444',
verification_value: '349'
)
stub_comms do
@gateway.purchase(@amount, credit_card, options)
end.check_request do |_endpoint, data, _headers|
assert_match(%r(<taxExempt>true</taxExempt>), data)
assert_match(%r(<salesTax>0</salesTax>), data)
assert_match(%r(<quantity>1</quantity>), data)
end.respond_with(successful_purchase_response)
end

def test_passing_level_3_data_for_visa
options = @options.merge(
level_3_data: {
discount_amount: 0,
shipping_amount: 0,
duty_amount: 0,
total_tax_amount: 0,
line_items: [{
item_sequence_number: 1,
commodity_code: 'Comm',
product_code: 'test',
item_description: 'Legal services',
quantity: 1,
unit_of_measure: 'EA',
discount_per_line_item: 0,
unit_cost: 500,
line_item_total: 500
}]
}
)
stub_comms do
@gateway.purchase(@amount, @decrypted_apple_pay, options)
end.check_request do |_endpoint, data, _headers|
assert_match(%r(<quantity>1</quantity>), data)
assert_match(%r(<commodityCode>Comm</commodityCode>), data)
assert_match(%r(<itemSequenceNumber>1</itemSequenceNumber>), data)
end.respond_with(successful_purchase_response)
end

def test_passing_litle_token
stub_comms do
@gateway.purchase(@amount, '121212121212', month: '01', year: '20', name: 'Jason Voorhees')
Expand Down

0 comments on commit f68c74d

Please sign in to comment.