Skip to content

Commit

Permalink
Merge pull request #6 from mycase/BMH-2869
Browse files Browse the repository at this point in the history
BMH-2869 Added Level2/3 helper methods for Worldpay sale purchase
  • Loading branch information
dotcom900825 authored Jan 19, 2024
2 parents 7a5b582 + db17a9a commit 5f49390
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 1 deletion.
96 changes: 96 additions & 0 deletions lib/active_merchant/billing/gateways/litle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,100 @@ def purchase(money, payment_method, options = {})
check?(payment_method) ? commit(:echeckSales, request, money) : commit(:sale, request, money)
end

def add_level_two_data(doc, payment_method, options = {})
level_2_data = options[:level_2_data]
if level_2_data
doc.enhancedData do
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]
doc.cardAcceptorTaxId(level_2_data[:card_acceptor_tax_id]) if level_2_data[:card_acceptor_tax_id]
end
end
end
end
end

def add_level_three_data(doc, payment_method, options = {})
level_3_data = options[:level_3_data]
if level_3_data
doc.enhancedData do
case payment_method.brand
when 'visa'
add_level_three_information_tags_visa(doc, payment_method, level_3_data)
when 'master'
add_level_three_information_tags_master(doc, payment_method, level_3_data)
end
end
end
end

def add_level_three_information_tags_visa(doc, payment_method, level_3_data)
doc.discountAmount(level_3_data[:discount_amount]) if level_3_data[:discount_amount]
doc.shippingAmount(level_3_data[:shipping_amount]) if level_3_data[:shipping_amount]
doc.dutyAmount(level_3_data[:duty_amount]) if level_3_data[:duty_amount]
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]
doc.taxRate(level_3_data[:tax_rate]) if level_3_data[:tax_rate]
doc.taxTypeIdentifier(level_3_data[:tax_type_identifier]) if level_3_data[:tax_type_identifier]
doc.cardAcceptorTaxId(level_3_data[:card_acceptor_tax_id]) if level_3_data[:card_acceptor_tax_id]
end
add_line_item_information_for_level_three_visa(doc, payment_method, level_3_data)
end

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]
doc.cardAcceptorTaxId :cardAcceptorTaxId, level_3_data[:card_acceptor_tax_id] if level_3_data[:card_acceptor_tax_id]
end
doc.lineItemData do
level_3_data[:line_items].each do |line_item|
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.lineItemTotal(line_item[:line_item_total]) if line_item[:line_item_total]
end
end
end

def add_line_item_information_for_level_three_visa(doc, payment_method, level_3_data)
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.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]
doc.taxRate(line_item[:tax_rate]) if line_item[:tax_rate]
doc.taxTypeIdentifier(line_item[:tax_type_identifier]) if line_item[:tax_type_identifier]
doc.cardAcceptorTaxId(line_item[:card_acceptor_tax_id]) if line_item[:card_acceptor_tax_id]
end
end
end
end

def authorize(money, payment_method, options = {})
request = build_xml_request do |doc|
add_authentication(doc)
Expand Down Expand Up @@ -228,6 +322,8 @@ def add_auth_purchase_params(doc, money, payment_method, options)
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_merchant_data(doc, options)
add_debt_repayment(doc, options)
add_stored_credential_params(doc, options)
Expand Down
2 changes: 1 addition & 1 deletion lib/active_merchant/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveMerchant
VERSION = '1.125.0'
VERSION = '1.126.0'
end
115 changes: 115 additions & 0 deletions test/unit/gateways/litle_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,121 @@ 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
}
)
credit_card = CreditCard.new(
first_name: 'John',
last_name: 'Smith',
month: '01',
year: '2028',
brand: 'visa',
number: '4111111111111111',
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_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: '2028',
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
}]
}
)
credit_card = CreditCard.new(
first_name: 'John',
last_name: 'Smith',
month: '01',
year: '2028',
brand: 'visa',
number: '4111111111111111',
verification_value: '349'
)
stub_comms do
@gateway.purchase(@amount, credit_card, 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 5f49390

Please sign in to comment.