Skip to content

Commit

Permalink
Litle: Add Support for Echeck
Browse files Browse the repository at this point in the history
Adds support for Echeck and tests for certification.

Loaded suite test/remote/gateways/remote_litle_test
...................................

35 tests, 136 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Loaded suite test/unit/gateways/litle_test
Started
...................................

35 tests, 151 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  • Loading branch information
Niaja committed Mar 7, 2018
1 parent 76de040 commit 122ff92
Show file tree
Hide file tree
Showing 5 changed files with 644 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
@@ -1,6 +1,7 @@
= ActiveMerchant CHANGELOG

== HEAD
* Litle: Add Support for Echeck [nfarve] #2776
* Orbital: Correct level 2 tax handling [deedeelavinder] #2729
* Payeezy: Change determination method of endpoint for store request [deedeelavinder] #2731
* Adyen: Return refusal_reason_raw when present [curiousepic] #2728
Expand Down
93 changes: 76 additions & 17 deletions lib/active_merchant/billing/gateways/litle.rb
Expand Up @@ -23,23 +23,33 @@ def initialize(options={})
def purchase(money, payment_method, options={})
request = build_xml_request do |doc|
add_authentication(doc)
doc.sale(transaction_attributes(options)) do
add_auth_purchase_params(doc, money, payment_method, options)
if check?(payment_method)
doc.echeckSale(transaction_attributes(options)) do
add_echeck_purchase_params(doc, money, payment_method, options)
end
else
doc.sale(transaction_attributes(options)) do
add_auth_purchase_params(doc, money, payment_method, options)
end
end
end

commit(:sale, request, money)
check?(payment_method) ? commit(:echeckSales, request, money) : commit(:sale, request, money)
end

def authorize(money, payment_method, options={})
request = build_xml_request do |doc|
add_authentication(doc)
doc.authorization(transaction_attributes(options)) do
add_auth_purchase_params(doc, money, payment_method, options)
if check?(payment_method)
doc.echeckVerification(transaction_attributes(options)) do
add_echeck_purchase_params(doc, money, payment_method, options)
end
else
doc.authorization(transaction_attributes(options)) do
add_auth_purchase_params(doc, money, payment_method, options)
end
end
end

commit(:authorization, request, money)
check?(payment_method) ? commit(:echeckVerification, request, money) : commit(:authorization, request, money)
end

def capture(money, authorization, options={})
Expand All @@ -62,19 +72,24 @@ def credit(money, authorization, options = {})
refund(money, authorization, options)
end

def refund(money, authorization, options={})
transaction_id, _, _ = split_authorization(authorization)

def refund(money, payment, options={})
request = build_xml_request do |doc|
add_authentication(doc)
add_descriptor(doc, options)
doc.credit(transaction_attributes(options)) do
doc.litleTxnId(transaction_id)
doc.amount(money) if money
doc.send(refund_type(payment), transaction_attributes(options)) do
if payment.is_a?(String)
transaction_id, kind, _ = split_authorization(payment)
doc.litleTxnId(transaction_id)
doc.amount(money) if money
elsif check?(payment)
add_echeck_purchase_params(doc, money, payment, options)
else
add_auth_purchase_params(doc, money, payment, options)
end
end
end

commit(:credit, request)
commit(refund_type(payment), request)
end

def verify(creditcard, options = {})
Expand Down Expand Up @@ -124,6 +139,8 @@ def scrub(transcript)
gsub(%r((<user>).+(</user>)), '\1[FILTERED]\2').
gsub(%r((<password>).+(</password>)), '\1[FILTERED]\2').
gsub(%r((<number>).+(</number>)), '\1[FILTERED]\2').
gsub(%r((<accNum>).+(</accNum>)), '\1[FILTERED]\2').
gsub(%r((<routingNum>).+(</routingNum>)), '\1[FILTERED]\2').
gsub(%r((<cardValidationNum>).+(</cardValidationNum>)), '\1[FILTERED]\2').
gsub(%r((<accountNumber>).+(</accountNumber>)), '\1[FILTERED]\2').
gsub(%r((<paypageRegistrationId>).+(</paypageRegistrationId>)), '\1[FILTERED]\2').
Expand Down Expand Up @@ -160,7 +177,27 @@ def scrub(transcript)
}

def void_type(kind)
(kind == 'authorization') ? :authReversal : :void
if kind == 'authorization'
:authReversal
elsif kind == 'echeckSales'
:echeckVoid
else
:void
end
end

def refund_type(payment)
transaction_id, kind, _ = split_authorization(payment)
if check?(payment) || kind == 'echeckSales'
:echeckCredit
else
:credit
end
end

def check?(payment_method)
return false if payment_method.is_a?(String)
card_brand(payment_method) == 'check'
end

def add_authentication(doc)
Expand Down Expand Up @@ -193,6 +230,15 @@ def add_merchant_data(doc, options={})
end
end

def add_echeck_purchase_params(doc, money, payment_method, options)
doc.orderId(truncate(options[:order_id], 24))
doc.amount(money)
add_order_source(doc, payment_method, options)
add_billing_address(doc, payment_method, options)
add_payment_method(doc, payment_method, options)
add_descriptor(doc, options)
end

def add_descriptor(doc, options)
if options[:descriptor_name] || options[:descriptor_phone]
doc.customBilling do
Expand All @@ -215,6 +261,13 @@ def add_payment_method(doc, payment_method, options)
doc.card do
doc.track(payment_method.track_data)
end
elsif check?(payment_method)
doc.echeck do
doc.accType(payment_method.account_type)
doc.accNum(payment_method.account_number)
doc.routingNum(payment_method.routing_number)
doc.checkNum(payment_method.number)
end
else
doc.card do
doc.type_(CARD_TYPE[payment_method.brand])
Expand All @@ -239,7 +292,13 @@ def add_billing_address(doc, payment_method, options)
return if payment_method.is_a?(String)

doc.billToAddress do
doc.name(payment_method.name)
if check?(payment_method)
doc.name(payment_method.name)
doc.firstName(payment_method.first_name)
doc.lastName(payment_method.last_name)
else
doc.name(payment_method.name)
end
doc.email(options[:email]) if options[:email]

add_address(doc, options[:billing_address])
Expand Down

0 comments on commit 122ff92

Please sign in to comment.