From f68c74dc8f2e21ea1c8e3087c32109cf1561527a Mon Sep 17 00:00:00 2001 From: Sivakumar Gandikota Date: Wed, 17 Jan 2024 17:56:08 -0800 Subject: [PATCH] BMH-2869 Added test cases for level2/3 methods --- lib/active_merchant/billing/gateways/litle.rb | 4 + test/unit/gateways/litle_test.rb | 97 +++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/lib/active_merchant/billing/gateways/litle.rb b/lib/active_merchant/billing/gateways/litle.rb index b6267f7a1e2..763eefa8041 100644 --- a/lib/active_merchant/billing/gateways/litle.rb +++ b/lib/active_merchant/billing/gateways/litle.rb @@ -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] @@ -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] @@ -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] diff --git a/test/unit/gateways/litle_test.rb b/test/unit/gateways/litle_test.rb index 8a2c9d7b3aa..8eab9fa1e53 100644 --- a/test/unit/gateways/litle_test.rb +++ b/test/unit/gateways/litle_test.rb @@ -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(true), data) + assert_match(%r(0), 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(true), data) + assert_match(%r(0), 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(true), data) + assert_match(%r(0), data) + assert_match(%r(1), 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(1), data) + assert_match(%r(Comm), data) + assert_match(%r(1), 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')