Class: ActiveMerchant::Billing::LitleGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/litle.rb

Constant Summary collapse

SCHEMA_VERSION =
'9.14'

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#add_field_to_post_if_present, #add_fields_to_post_if_present, #card_brand, card_brand, #generate_unique_id, inherited, supported_countries, #supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ LitleGateway

Returns a new instance of LitleGateway.


21
22
23
24
# File 'lib/active_merchant/billing/gateways/litle.rb', line 21

def initialize(options = {})
  requires!(options, :login, :password, :merchant_id)
  super
end

Instance Method Details

#authorize(money, payment_method, options = {}) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_merchant/billing/gateways/litle.rb', line 42

def authorize(money, payment_method, options = {})
  request = build_xml_request do |doc|
    add_authentication(doc)
    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
  check?(payment_method) ? commit(:echeckVerification, request, money) : commit(:authorization, request, money)
end

#capture(money, authorization, options = {}) ⇒ Object


58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/active_merchant/billing/gateways/litle.rb', line 58

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

  request = build_xml_request do |doc|
    add_authentication(doc)
    add_descriptor(doc, options)
    doc.capture_(transaction_attributes(options)) do
      doc.litleTxnId(transaction_id)
      doc.amount(money) if money
    end
  end

  commit(:capture, request, money)
end

#credit(money, authorization, options = {}) ⇒ Object


73
74
75
76
# File 'lib/active_merchant/billing/gateways/litle.rb', line 73

def credit(money, authorization, options = {})
  ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
  refund(money, authorization, options)
end

#purchase(money, payment_method, options = {}) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/active_merchant/billing/gateways/litle.rb', line 26

def purchase(money, payment_method, options = {})
  request = build_xml_request do |doc|
    add_authentication(doc)
    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
  check?(payment_method) ? commit(:echeckSales, request, money) : commit(:sale, request, money)
end

#refund(money, payment, options = {}) ⇒ Object


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/active_merchant/billing/gateways/litle.rb', line 78

def refund(money, payment, options = {})
  request = build_xml_request do |doc|
    add_authentication(doc)
    add_descriptor(doc, options)
    doc.send(refund_type(payment), transaction_attributes(options)) do
      if payment.is_a?(String)
        transaction_id, = 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_credit_params(doc, money, payment, options)
      end
    end
  end

  commit(refund_type(payment), request)
end

#scrub(transcript) ⇒ Object


145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/active_merchant/billing/gateways/litle.rb', line 145

def scrub(transcript)
  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').
    gsub(%r((<authenticationValue>).+(</authenticationValue>)), '\1[FILTERED]\2')
end

#store(payment_method, options = {}) ⇒ Object


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/active_merchant/billing/gateways/litle.rb', line 119

def store(payment_method, options = {})
  request = build_xml_request do |doc|
    add_authentication(doc)
    doc.registerTokenRequest(transaction_attributes(options)) do
      doc.orderId(truncate(options[:order_id], 24))
      if payment_method.is_a?(String)
        doc.paypageRegistrationId(payment_method)
      elsif check?(payment_method)
        doc.echeckForToken do
          doc.accNum(payment_method.)
          doc.routingNum(payment_method.routing_number)
        end
      else
        doc.accountNumber(payment_method.number)
        doc.cardValidationNum(payment_method.verification_value) if payment_method.verification_value
      end
    end
  end

  commit(:registerToken, request)
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)

141
142
143
# File 'lib/active_merchant/billing/gateways/litle.rb', line 141

def supports_scrubbing?
  true
end

#verify(creditcard, options = {}) ⇒ Object


98
99
100
101
102
103
# File 'lib/active_merchant/billing/gateways/litle.rb', line 98

def verify(creditcard, options = {})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(0, creditcard, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end

#void(authorization, options = {}) ⇒ Object


105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/active_merchant/billing/gateways/litle.rb', line 105

def void(authorization, options = {})
  transaction_id, kind, money = split_authorization(authorization)

  request = build_xml_request do |doc|
    add_authentication(doc)
    doc.send(void_type(kind), transaction_attributes(options)) do
      doc.litleTxnId(transaction_id)
      doc.amount(money) if void_type(kind) == :authReversal
    end
  end

  commit(void_type(kind), request)
end