From d21c7b08266323791bd8c4c43f3d7cd11939830f Mon Sep 17 00:00:00 2001 From: Sivakumar Gandikota Date: Thu, 1 Feb 2024 11:32:18 -0800 Subject: [PATCH] BMH-2918 Added support for payment_method brand for gateway purchase --- lib/active_merchant/billing/gateways/litle.rb | 11 +++--- .../gateways/litle/paypage_registration.rb | 3 +- .../billing/gateways/litle/token.rb | 15 ++++++++ test/unit/gateways/litle_test.rb | 36 ++++++++++++++++++- 4 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 lib/active_merchant/billing/gateways/litle/token.rb diff --git a/lib/active_merchant/billing/gateways/litle.rb b/lib/active_merchant/billing/gateways/litle.rb index 763eefa8041..14f5877d0c1 100644 --- a/lib/active_merchant/billing/gateways/litle.rb +++ b/lib/active_merchant/billing/gateways/litle.rb @@ -1,5 +1,6 @@ require 'nokogiri' require 'active_merchant/billing/gateways/litle/paypage_registration' +require 'active_merchant/billing/gateways/litle/token' module ActiveMerchant #:nodoc: module Billing #:nodoc: @@ -114,15 +115,15 @@ def add_line_item_information_for_level_three_visa(doc, payment_method, level_3_ doc.lineItemData do level_3_data[:line_items].each do |line_item| doc.itemSequenceNumber(line_item[:item_sequence_number]) if line_item[:item_sequence_number] - doc.commodityCode(line_item[:commodity_code]) if line_item[:commodity_code] doc.itemDescription(line_item[:item_description]) if line_item[:item_description] doc.productCode(line_item[:product_code]) if line_item[:product_code] doc.quantity(line_item[:quantity]) if line_item[:quantity] doc.unitOfMeasure(line_item[:unit_of_measure]) if line_item[:unit_of_measure] 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.itemDiscountAmount(line_item[:discount_per_line_item]) if line_item[:discount_per_line_item] + doc.commodityCode(line_item[:commodity_code]) if line_item[:commodity_code] + doc.unitCost(line_item[:unit_cost]) if line_item[:unit_cost] 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] @@ -320,10 +321,10 @@ def add_auth_purchase_params(doc, money, payment_method, options) add_payment_method(doc, payment_method, options) add_pos(doc, payment_method) add_descriptor(doc, options) - add_processing_type(doc, options) - add_original_network_transaction(doc, options) add_level_two_data(doc, payment_method, options) add_level_three_data(doc, payment_method, options) + add_processing_type(doc, options) + add_original_network_transaction(doc, options) add_merchant_data(doc, options) add_debt_repayment(doc, options) add_stored_credential_params(doc, options) diff --git a/lib/active_merchant/billing/gateways/litle/paypage_registration.rb b/lib/active_merchant/billing/gateways/litle/paypage_registration.rb index f8f4613295a..7181c246933 100644 --- a/lib/active_merchant/billing/gateways/litle/paypage_registration.rb +++ b/lib/active_merchant/billing/gateways/litle/paypage_registration.rb @@ -13,7 +13,7 @@ module Billing # The name parameter is allowed by Vantiv as a member of the billToAddress element. # It is passed in here to be consistent with the rest of the Litle gateway and Activemerchant. class LitlePaypageRegistration - attr_reader :paypage_registration_id, :month, :year, :verification_value, :name, :type + attr_reader :paypage_registration_id, :month, :year, :verification_value, :name, :type, :brand def initialize(paypage_registration_id, options = {}) @paypage_registration_id = paypage_registration_id @@ -22,6 +22,7 @@ def initialize(paypage_registration_id, options = {}) @verification_value = options[:verification_value] @name = options[:name] @type = options[:type] + @brand = options[:brand] end end end diff --git a/lib/active_merchant/billing/gateways/litle/token.rb b/lib/active_merchant/billing/gateways/litle/token.rb new file mode 100644 index 00000000000..47795a58407 --- /dev/null +++ b/lib/active_merchant/billing/gateways/litle/token.rb @@ -0,0 +1,15 @@ +module ActiveMerchant + module Billing + # The name parameter is allowed by Vantiv as a member of the billToAddress element. + # It is passed in here to be consistent with the rest of the Litle gateway and Activemerchant. + class LitleToken + attr_reader :litle_token, :name, :brand + + def initialize(litle_token, options = {}) + @litle_token = litle_token + @name = options[:name] + @brand = options[:brand] + end + end + end +end diff --git a/test/unit/gateways/litle_test.rb b/test/unit/gateways/litle_test.rb index 4929212eb5d..6e0f8606182 100644 --- a/test/unit/gateways/litle_test.rb +++ b/test/unit/gateways/litle_test.rb @@ -264,7 +264,7 @@ def test_passing_level_3_data_for_visa discount_amount: 0, shipping_amount: 0, duty_amount: 0, - total_tax_amount: 0, + tax_amount: 0, line_items: [{ item_sequence_number: 1, commodity_code: 'Comm', @@ -293,6 +293,40 @@ def test_passing_level_3_data_for_visa assert_match(%r(1), data) assert_match(%r(Comm), data) assert_match(%r(1), data) + assert_match(%r(0), data) + end.respond_with(successful_purchase_response) + end + + def test_passing_with_litle_token_of_level_3_rates + litle_token = ActiveMerchant::Billing::LitleToken.new( + 'XkNDRGZDTGZyS2RBSTVCazJNSmdWam5T', + brand: 'visa', + name: 'Joe Payer' + ) + options = @options.merge( + level_3_data: { + discount_amount: 0, + shipping_amount: 0, + duty_amount: 0, + 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, litle_token, options) + end.check_request do |_endpoint, data, _headers| + assert_match(%r(500), data) + assert_match(%r(0), data) end.respond_with(successful_purchase_response) end