active_accountability_merchant 1.97.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +2948 -0
  3. data/CONTRIBUTORS +568 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +246 -0
  6. data/lib/active_merchant.rb +63 -0
  7. data/lib/active_merchant/billing.rb +15 -0
  8. data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
  9. data/lib/active_merchant/billing/avs_result.rb +96 -0
  10. data/lib/active_merchant/billing/base.rb +61 -0
  11. data/lib/active_merchant/billing/check.rb +80 -0
  12. data/lib/active_merchant/billing/compatibility.rb +117 -0
  13. data/lib/active_merchant/billing/credit_card.rb +406 -0
  14. data/lib/active_merchant/billing/credit_card_formatting.rb +23 -0
  15. data/lib/active_merchant/billing/credit_card_methods.rb +343 -0
  16. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  17. data/lib/active_merchant/billing/gateway.rb +330 -0
  18. data/lib/active_merchant/billing/gateways.rb +14 -0
  19. data/lib/active_merchant/billing/gateways/adyen.rb +503 -0
  20. data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
  21. data/lib/active_merchant/billing/gateways/authorize_net.rb +1055 -0
  22. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
  23. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +980 -0
  24. data/lib/active_merchant/billing/gateways/axcessms.rb +181 -0
  25. data/lib/active_merchant/billing/gateways/balanced.rb +256 -0
  26. data/lib/active_merchant/billing/gateways/bambora_apac.rb +226 -0
  27. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  28. data/lib/active_merchant/billing/gateways/banwire.rb +116 -0
  29. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +384 -0
  30. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
  31. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  32. data/lib/active_merchant/billing/gateways/beanstream.rb +217 -0
  33. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +473 -0
  34. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +57 -0
  35. data/lib/active_merchant/billing/gateways/blue_pay.rb +522 -0
  36. data/lib/active_merchant/billing/gateways/blue_snap.rb +522 -0
  37. data/lib/active_merchant/billing/gateways/bogus.rb +186 -0
  38. data/lib/active_merchant/billing/gateways/borgun.rb +220 -0
  39. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  40. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  41. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +22 -0
  42. data/lib/active_merchant/billing/gateways/braintree_blue.rb +740 -0
  43. data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
  44. data/lib/active_merchant/billing/gateways/bridge_pay.rb +244 -0
  45. data/lib/active_merchant/billing/gateways/cams.rb +230 -0
  46. data/lib/active_merchant/billing/gateways/card_connect.rb +316 -0
  47. data/lib/active_merchant/billing/gateways/card_save.rb +22 -0
  48. data/lib/active_merchant/billing/gateways/card_stream.rb +367 -0
  49. data/lib/active_merchant/billing/gateways/cardknox.rb +327 -0
  50. data/lib/active_merchant/billing/gateways/cardprocess.rb +254 -0
  51. data/lib/active_merchant/billing/gateways/cashnet.rb +219 -0
  52. data/lib/active_merchant/billing/gateways/cc5.rb +198 -0
  53. data/lib/active_merchant/billing/gateways/cecabank.rb +249 -0
  54. data/lib/active_merchant/billing/gateways/cenpos.rb +327 -0
  55. data/lib/active_merchant/billing/gateways/checkout.rb +214 -0
  56. data/lib/active_merchant/billing/gateways/checkout_v2.rb +270 -0
  57. data/lib/active_merchant/billing/gateways/citrus_pay.rb +22 -0
  58. data/lib/active_merchant/billing/gateways/clearhaus.rb +220 -0
  59. data/lib/active_merchant/billing/gateways/commercegate.rb +142 -0
  60. data/lib/active_merchant/billing/gateways/conekta.rb +228 -0
  61. data/lib/active_merchant/billing/gateways/creditcall.rb +271 -0
  62. data/lib/active_merchant/billing/gateways/credorax.rb +382 -0
  63. data/lib/active_merchant/billing/gateways/ct_payment.rb +268 -0
  64. data/lib/active_merchant/billing/gateways/culqi.rb +277 -0
  65. data/lib/active_merchant/billing/gateways/cyber_source.rb +828 -0
  66. data/lib/active_merchant/billing/gateways/d_local.rb +226 -0
  67. data/lib/active_merchant/billing/gateways/data_cash.rb +305 -0
  68. data/lib/active_merchant/billing/gateways/decidir.rb +233 -0
  69. data/lib/active_merchant/billing/gateways/dibs.rb +199 -0
  70. data/lib/active_merchant/billing/gateways/digitzs.rb +292 -0
  71. data/lib/active_merchant/billing/gateways/ebanx.rb +296 -0
  72. data/lib/active_merchant/billing/gateways/efsnet.rb +215 -0
  73. data/lib/active_merchant/billing/gateways/elavon.rb +320 -0
  74. data/lib/active_merchant/billing/gateways/element.rb +356 -0
  75. data/lib/active_merchant/billing/gateways/epay.rb +285 -0
  76. data/lib/active_merchant/billing/gateways/evo_ca.rb +308 -0
  77. data/lib/active_merchant/billing/gateways/eway.rb +226 -0
  78. data/lib/active_merchant/billing/gateways/eway_managed.rb +290 -0
  79. data/lib/active_merchant/billing/gateways/eway_rapid.rb +563 -0
  80. data/lib/active_merchant/billing/gateways/exact.rb +224 -0
  81. data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
  82. data/lib/active_merchant/billing/gateways/fat_zebra.rb +218 -0
  83. data/lib/active_merchant/billing/gateways/federated_canada.rb +159 -0
  84. data/lib/active_merchant/billing/gateways/finansbank.rb +22 -0
  85. data/lib/active_merchant/billing/gateways/first_giving.rb +142 -0
  86. data/lib/active_merchant/billing/gateways/first_pay.rb +182 -0
  87. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +451 -0
  88. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +485 -0
  89. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  90. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  91. data/lib/active_merchant/billing/gateways/forte.rb +270 -0
  92. data/lib/active_merchant/billing/gateways/garanti.rb +259 -0
  93. data/lib/active_merchant/billing/gateways/global_collect.rb +336 -0
  94. data/lib/active_merchant/billing/gateways/global_transport.rb +194 -0
  95. data/lib/active_merchant/billing/gateways/hdfc.rb +206 -0
  96. data/lib/active_merchant/billing/gateways/hps.rb +350 -0
  97. data/lib/active_merchant/billing/gateways/iats_payments.rb +290 -0
  98. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  99. data/lib/active_merchant/billing/gateways/inspire.rb +218 -0
  100. data/lib/active_merchant/billing/gateways/instapay.rb +162 -0
  101. data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
  102. data/lib/active_merchant/billing/gateways/iridium.rb +468 -0
  103. data/lib/active_merchant/billing/gateways/itransact.rb +447 -0
  104. data/lib/active_merchant/billing/gateways/iveri.rb +251 -0
  105. data/lib/active_merchant/billing/gateways/jetpay.rb +402 -0
  106. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +437 -0
  107. data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
  108. data/lib/active_merchant/billing/gateways/kushki.rb +219 -0
  109. data/lib/active_merchant/billing/gateways/latitude19.rb +411 -0
  110. data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
  111. data/lib/active_merchant/billing/gateways/litle.rb +507 -0
  112. data/lib/active_merchant/billing/gateways/mastercard.rb +267 -0
  113. data/lib/active_merchant/billing/gateways/maxipago.rb +220 -0
  114. data/lib/active_merchant/billing/gateways/mercado_pago.rb +277 -0
  115. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +194 -0
  116. data/lib/active_merchant/billing/gateways/merchant_one.rb +113 -0
  117. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  118. data/lib/active_merchant/billing/gateways/merchant_ware.rb +319 -0
  119. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +286 -0
  120. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +210 -0
  121. data/lib/active_merchant/billing/gateways/mercury.rb +356 -0
  122. data/lib/active_merchant/billing/gateways/metrics_global.rb +303 -0
  123. data/lib/active_merchant/billing/gateways/micropayment.rb +183 -0
  124. data/lib/active_merchant/billing/gateways/migs.rb +332 -0
  125. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  126. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  127. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +217 -0
  128. data/lib/active_merchant/billing/gateways/monei.rb +338 -0
  129. data/lib/active_merchant/billing/gateways/moneris.rb +377 -0
  130. data/lib/active_merchant/billing/gateways/moneris_us.rb +352 -0
  131. data/lib/active_merchant/billing/gateways/money_movers.rb +151 -0
  132. data/lib/active_merchant/billing/gateways/mundipagg.rb +293 -0
  133. data/lib/active_merchant/billing/gateways/nab_transact.rb +301 -0
  134. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +165 -0
  135. data/lib/active_merchant/billing/gateways/net_registry.rb +199 -0
  136. data/lib/active_merchant/billing/gateways/netaxept.rb +180 -0
  137. data/lib/active_merchant/billing/gateways/netbanx.rb +294 -0
  138. data/lib/active_merchant/billing/gateways/netbilling.rb +232 -0
  139. data/lib/active_merchant/billing/gateways/netpay.rb +222 -0
  140. data/lib/active_merchant/billing/gateways/network_merchants.rb +241 -0
  141. data/lib/active_merchant/billing/gateways/nmi.rb +324 -0
  142. data/lib/active_merchant/billing/gateways/ogone.rb +478 -0
  143. data/lib/active_merchant/billing/gateways/omise.rb +324 -0
  144. data/lib/active_merchant/billing/gateways/openpay.rb +228 -0
  145. data/lib/active_merchant/billing/gateways/opp.rb +388 -0
  146. data/lib/active_merchant/billing/gateways/optimal_payment.rb +332 -0
  147. data/lib/active_merchant/billing/gateways/orbital.rb +1006 -0
  148. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +47 -0
  149. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +206 -0
  150. data/lib/active_merchant/billing/gateways/pagarme.rb +246 -0
  151. data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
  152. data/lib/active_merchant/billing/gateways/pay_conex.rb +245 -0
  153. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +280 -0
  154. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  155. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  156. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +188 -0
  157. data/lib/active_merchant/billing/gateways/pay_secure.rb +111 -0
  158. data/lib/active_merchant/billing/gateways/paybox_direct.rb +200 -0
  159. data/lib/active_merchant/billing/gateways/payeezy.rb +410 -0
  160. data/lib/active_merchant/billing/gateways/payex.rb +410 -0
  161. data/lib/active_merchant/billing/gateways/payflow.rb +383 -0
  162. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +235 -0
  163. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +43 -0
  164. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  165. data/lib/active_merchant/billing/gateways/payflow_express.rb +220 -0
  166. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +14 -0
  167. data/lib/active_merchant/billing/gateways/payflow_uk.rb +20 -0
  168. data/lib/active_merchant/billing/gateways/payment_express.rb +369 -0
  169. data/lib/active_merchant/billing/gateways/paymentez.rb +300 -0
  170. data/lib/active_merchant/billing/gateways/paymill.rb +371 -0
  171. data/lib/active_merchant/billing/gateways/paypal.rb +128 -0
  172. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +717 -0
  173. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
  174. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  175. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  176. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  177. data/lib/active_merchant/billing/gateways/paypal_express.rb +269 -0
  178. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  179. data/lib/active_merchant/billing/gateways/payscout.rb +160 -0
  180. data/lib/active_merchant/billing/gateways/paystation.rb +207 -0
  181. data/lib/active_merchant/billing/gateways/payu_in.rb +248 -0
  182. data/lib/active_merchant/billing/gateways/payu_latam.rb +449 -0
  183. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  184. data/lib/active_merchant/billing/gateways/pin.rb +234 -0
  185. data/lib/active_merchant/billing/gateways/plugnpay.rb +284 -0
  186. data/lib/active_merchant/billing/gateways/pro_pay.rb +326 -0
  187. data/lib/active_merchant/billing/gateways/psigate.rb +227 -0
  188. data/lib/active_merchant/billing/gateways/psl_card.rb +296 -0
  189. data/lib/active_merchant/billing/gateways/qbms.rb +303 -0
  190. data/lib/active_merchant/billing/gateways/quantum.rb +276 -0
  191. data/lib/active_merchant/billing/gateways/quickbooks.rb +290 -0
  192. data/lib/active_merchant/billing/gateways/quickpay.rb +25 -0
  193. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +184 -0
  194. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +301 -0
  195. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +226 -0
  196. data/lib/active_merchant/billing/gateways/qvalent.rb +289 -0
  197. data/lib/active_merchant/billing/gateways/realex.rb +374 -0
  198. data/lib/active_merchant/billing/gateways/redsys.rb +534 -0
  199. data/lib/active_merchant/billing/gateways/s5.rb +246 -0
  200. data/lib/active_merchant/billing/gateways/safe_charge.rb +262 -0
  201. data/lib/active_merchant/billing/gateways/sage.rb +448 -0
  202. data/lib/active_merchant/billing/gateways/sage_pay.rb +434 -0
  203. data/lib/active_merchant/billing/gateways/sallie_mae.rb +142 -0
  204. data/lib/active_merchant/billing/gateways/secure_net.rb +267 -0
  205. data/lib/active_merchant/billing/gateways/secure_pay.rb +200 -0
  206. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +292 -0
  207. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +104 -0
  208. data/lib/active_merchant/billing/gateways/securion_pay.rb +264 -0
  209. data/lib/active_merchant/billing/gateways/skip_jack.rb +450 -0
  210. data/lib/active_merchant/billing/gateways/smart_ps.rb +280 -0
  211. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  212. data/lib/active_merchant/billing/gateways/spreedly_core.rb +306 -0
  213. data/lib/active_merchant/billing/gateways/stripe.rb +790 -0
  214. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +267 -0
  215. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +152 -0
  216. data/lib/active_merchant/billing/gateways/telr.rb +274 -0
  217. data/lib/active_merchant/billing/gateways/tns.rb +22 -0
  218. data/lib/active_merchant/billing/gateways/trans_first.rb +239 -0
  219. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +608 -0
  220. data/lib/active_merchant/billing/gateways/transact_pro.rb +224 -0
  221. data/lib/active_merchant/billing/gateways/transax.rb +22 -0
  222. data/lib/active_merchant/billing/gateways/transnational.rb +9 -0
  223. data/lib/active_merchant/billing/gateways/trexle.rb +218 -0
  224. data/lib/active_merchant/billing/gateways/trust_commerce.rb +490 -0
  225. data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
  226. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1620 -0
  227. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +355 -0
  228. data/lib/active_merchant/billing/gateways/vanco.rb +294 -0
  229. data/lib/active_merchant/billing/gateways/verifi.rb +225 -0
  230. data/lib/active_merchant/billing/gateways/viaklix.rb +176 -0
  231. data/lib/active_merchant/billing/gateways/visanet_peru.rb +245 -0
  232. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  233. data/lib/active_merchant/billing/gateways/wepay.rb +237 -0
  234. data/lib/active_merchant/billing/gateways/wirecard.rb +432 -0
  235. data/lib/active_merchant/billing/gateways/world_net.rb +344 -0
  236. data/lib/active_merchant/billing/gateways/worldpay.rb +634 -0
  237. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +215 -0
  238. data/lib/active_merchant/billing/gateways/worldpay_us.rb +221 -0
  239. data/lib/active_merchant/billing/model.rb +30 -0
  240. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
  241. data/lib/active_merchant/billing/payment_token.rb +21 -0
  242. data/lib/active_merchant/billing/rails.rb +3 -0
  243. data/lib/active_merchant/billing/response.rb +92 -0
  244. data/lib/active_merchant/connection.rb +195 -0
  245. data/lib/active_merchant/country.rb +336 -0
  246. data/lib/active_merchant/empty.rb +20 -0
  247. data/lib/active_merchant/errors.rb +35 -0
  248. data/lib/active_merchant/net_http_ssl_connection.rb +10 -0
  249. data/lib/active_merchant/network_connection_retries.rb +80 -0
  250. data/lib/active_merchant/post_data.rb +25 -0
  251. data/lib/active_merchant/posts_data.rb +92 -0
  252. data/lib/active_merchant/version.rb +3 -0
  253. data/lib/activemerchant.rb +1 -0
  254. data/lib/certs/cacert.pem +3988 -0
  255. data/lib/support/gateway_support.rb +69 -0
  256. data/lib/support/outbound_hosts.rb +28 -0
  257. data/lib/support/ssl_verify.rb +92 -0
  258. data/lib/support/ssl_version.rb +87 -0
  259. metadata +435 -0
@@ -0,0 +1,449 @@
1
+ require 'rexml/document'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # Initialization Options
6
+ # :login Your store number
7
+ # :pem The text of your linkpoint PEM file. Note
8
+ # this is not the path to file, but its
9
+ # contents. If you are only using one PEM
10
+ # file on your site you can declare it
11
+ # globally and then you won't need to
12
+ # include this option
13
+ #
14
+ #
15
+ # A valid store number is required. Unfortunately, with LinkPoint
16
+ # YOU CAN'T JUST USE ANY OLD STORE NUMBER. Also, you can't just
17
+ # generate your own PEM file. You'll need to use a special PEM file
18
+ # provided by LinkPoint.
19
+ #
20
+ # Go to http://www.linkpoint.com/support/sup_teststore.asp to set up
21
+ # a test account and obtain your PEM file.
22
+ #
23
+ # Declaring PEM file Globally
24
+ # ActiveMerchant::Billing::LinkpointGateway.pem_file = File.read( File.dirname(__FILE__) + '/../mycert.pem' )
25
+ #
26
+ #
27
+ # Valid Order Options
28
+ # :result =>
29
+ # LIVE Production mode
30
+ # GOOD Approved response in test mode
31
+ # DECLINE Declined response in test mode
32
+ # DUPLICATE Duplicate response in test mode
33
+ #
34
+ # :ponumber Order number
35
+ #
36
+ # :transactionorigin => Source of the transaction
37
+ # ECI Email or Internet
38
+ # MAIL Mail order
39
+ # MOTO Mail order/Telephone
40
+ # TELEPHONE Telephone
41
+ # RETAIL Face-to-face
42
+ #
43
+ # :ordertype =>
44
+ # SALE Real live sale
45
+ # PREAUTH Authorize only
46
+ # POSTAUTH Forced Ticket or Ticket Only transaction
47
+ # VOID
48
+ # CREDIT
49
+ # CALCSHIPPING For shipping charges calculations
50
+ # CALCTAX For sales tax calculations
51
+ #
52
+ # Recurring Options
53
+ # :action =>
54
+ # SUBMIT
55
+ # MODIFY
56
+ # CANCEL
57
+ #
58
+ # :installments Identifies how many recurring payments to charge the customer
59
+ # :startdate Date to begin charging the recurring payments. Format: YYYYMMDD or "immediate"
60
+ # :periodicity =>
61
+ # MONTHLY
62
+ # BIMONTHLY
63
+ # WEEKLY
64
+ # BIWEEKLY
65
+ # YEARLY
66
+ # DAILY
67
+ # :threshold Tells how many times to retry the transaction (if it fails) before contacting the merchant.
68
+ # :comments Uh... comments
69
+ #
70
+ #
71
+ # For reference:
72
+ #
73
+ # https://www.linkpointcentral.com/lpc/docs/Help/APIHelp/lpintguide.htm
74
+ #
75
+ # Entities = {
76
+ # :payment => [:subtotal, :tax, :vattax, :shipping, :chargetotal],
77
+ # :billing => [:name, :address1, :address2, :city, :state, :zip, :country, :email, :phone, :fax, :addrnum],
78
+ # :shipping => [:name, :address1, :address2, :city, :state, :zip, :country, :weight, :items, :carrier, :total],
79
+ # :creditcard => [:cardnumber, :cardexpmonth, :cardexpyear, :cvmvalue, :track],
80
+ # :telecheck => [:routing, :account, :checknumber, :bankname, :bankstate, :dl, :dlstate, :void, :accounttype, :ssn],
81
+ # :transactiondetails => [:transactionorigin, :oid, :ponumber, :taxexempt, :terminaltype, :ip, :reference_number, :recurring, :tdate],
82
+ # :periodic => [:action, :installments, :threshold, :startdate, :periodicity, :comments],
83
+ # :notes => [:comments, :referred]
84
+ # :items => [:item => [:price, :quantity, :description, :id, :options => [:option => [:name, :value]]]]
85
+ # }
86
+ #
87
+ #
88
+ # LinkPoint's Items entity is an optional entity that can be attached to orders.
89
+ # It is entered as :line_items to be consistent with the CyberSource implementation
90
+ #
91
+ # The line_item hash goes in the options hash and should look like
92
+ #
93
+ # :line_items => [
94
+ # {
95
+ # :id => '123456',
96
+ # :description => 'Logo T-Shirt',
97
+ # :price => '12.00',
98
+ # :quantity => '1',
99
+ # :options => [
100
+ # {
101
+ # :name => 'Color',
102
+ # :value => 'Red'
103
+ # },
104
+ # {
105
+ # :name => 'Size',
106
+ # :value => 'XL'
107
+ # }
108
+ # ]
109
+ # },
110
+ # {
111
+ # :id => '111',
112
+ # :description => 'keychain',
113
+ # :price => '3.00',
114
+ # :quantity => '1'
115
+ # }
116
+ # ]
117
+ # This functionality is only supported by this particular gateway may
118
+ # be changed at any time
119
+ #
120
+ class LinkpointGateway < Gateway
121
+ # Your global PEM file. This will be assigned to you by linkpoint
122
+ #
123
+ # Example:
124
+ #
125
+ # ActiveMerchant::Billing::LinkpointGateway.pem_file = File.read( File.dirname(__FILE__) + '/../mycert.pem' )
126
+ #
127
+ cattr_accessor :pem_file
128
+
129
+ self.test_url = 'https://staging.linkpt.net:1129/'
130
+ self.live_url = 'https://secure.linkpt.net:1129/'
131
+
132
+ self.supported_countries = ['US']
133
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club]
134
+ self.homepage_url = 'http://www.linkpoint.com/'
135
+ self.display_name = 'LinkPoint'
136
+
137
+ def initialize(options = {})
138
+ requires!(options, :login)
139
+
140
+ @options = {
141
+ :result => 'LIVE',
142
+ :pem => LinkpointGateway.pem_file
143
+ }.update(options)
144
+
145
+ raise ArgumentError, "You need to pass in your pem file using the :pem parameter or set it globally using ActiveMerchant::Billing::LinkpointGateway.pem_file = File.read( File.dirname(__FILE__) + '/../mycert.pem' ) or similar" if @options[:pem].blank?
146
+
147
+ @options[:pem].strip!
148
+ end
149
+
150
+ # Send a purchase request with periodic options
151
+ # Recurring Options
152
+ # :action =>
153
+ # SUBMIT
154
+ # MODIFY
155
+ # CANCEL
156
+ #
157
+ # :installments Identifies how many recurring payments to charge the customer
158
+ # :startdate Date to begin charging the recurring payments. Format: YYYYMMDD or "immediate"
159
+ # :periodicity =>
160
+ # :monthly
161
+ # :bimonthly
162
+ # :weekly
163
+ # :biweekly
164
+ # :yearly
165
+ # :daily
166
+ # :threshold Tells how many times to retry the transaction (if it fails) before contacting the merchant.
167
+ # :comments Uh... comments
168
+ #
169
+ def recurring(money, creditcard, options={})
170
+ ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE
171
+
172
+ requires!(options, [:periodicity, :bimonthly, :monthly, :biweekly, :weekly, :yearly, :daily], :installments, :order_id)
173
+
174
+ options.update(
175
+ :ordertype => 'SALE',
176
+ :action => options[:action] || 'SUBMIT',
177
+ :installments => options[:installments] || 12,
178
+ :startdate => options[:startdate] || 'immediate',
179
+ :periodicity => options[:periodicity].to_s || 'monthly',
180
+ :comments => options[:comments] || nil,
181
+ :threshold => options[:threshold] || 3
182
+ )
183
+ commit(money, creditcard, options)
184
+ end
185
+
186
+ # Buy the thing
187
+ def purchase(money, creditcard, options={})
188
+ requires!(options, :order_id)
189
+ options.update(
190
+ :ordertype => 'SALE'
191
+ )
192
+ commit(money, creditcard, options)
193
+ end
194
+
195
+ #
196
+ # Authorize the transaction
197
+ #
198
+ # Reserves the funds on the customer's credit card, but does not charge the card.
199
+ #
200
+ def authorize(money, creditcard, options = {})
201
+ requires!(options, :order_id)
202
+ options.update(
203
+ :ordertype => 'PREAUTH'
204
+ )
205
+ commit(money, creditcard, options)
206
+ end
207
+
208
+ #
209
+ # Post an authorization.
210
+ #
211
+ # Captures the funds from an authorized transaction.
212
+ # Order_id must be a valid order id from a prior authorized transaction.
213
+ #
214
+ def capture(money, authorization, options = {})
215
+ options.update(
216
+ :order_id => authorization,
217
+ :ordertype => 'POSTAUTH'
218
+ )
219
+ commit(money, nil, options)
220
+ end
221
+
222
+ # Void a previous transaction
223
+ def void(identification, options = {})
224
+ options.update(
225
+ :order_id => identification,
226
+ :ordertype => 'VOID'
227
+ )
228
+ commit(nil, nil, options)
229
+ end
230
+
231
+ #
232
+ # Refund an order
233
+ #
234
+ # identification must be a valid order id previously submitted by SALE
235
+ #
236
+ def refund(money, identification, options = {})
237
+ options.update(
238
+ :ordertype => 'CREDIT',
239
+ :order_id => identification
240
+ )
241
+ commit(money, nil, options)
242
+ end
243
+
244
+ def credit(money, identification, options = {})
245
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
246
+ refund(money, identification, options)
247
+ end
248
+
249
+ def supports_scrubbing
250
+ true
251
+ end
252
+
253
+ def scrub(transcript)
254
+ transcript.
255
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
256
+ gsub(%r((<cardnumber>)\d+(</cardnumber>))i, '\1[FILTERED]\2').
257
+ gsub(%r((<cvmvalue>)\d+(</cvmvalue>))i, '\1[FILTERED]\2')
258
+ end
259
+
260
+ private
261
+
262
+ # Commit the transaction by posting the XML file to the LinkPoint server
263
+ def commit(money, creditcard, options = {})
264
+ response = parse(ssl_post(test? ? self.test_url : self.live_url, post_data(money, creditcard, options)))
265
+
266
+ Response.new(successful?(response), response[:message], response,
267
+ :test => test?,
268
+ :authorization => response[:ordernum],
269
+ :avs_result => { :code => response[:avs].to_s[2, 1] },
270
+ :cvv_result => response[:avs].to_s[3, 1]
271
+ )
272
+ end
273
+
274
+ def successful?(response)
275
+ response[:approved] == 'APPROVED'
276
+ end
277
+
278
+ # Build the XML file
279
+ def post_data(money, creditcard, options)
280
+ params = parameters(money, creditcard, options)
281
+
282
+ xml = REXML::Document.new
283
+ order = xml.add_element('order')
284
+
285
+ # Merchant Info
286
+ merchantinfo = order.add_element('merchantinfo')
287
+ merchantinfo.add_element('configfile').text = @options[:login]
288
+
289
+ # Loop over the params hash to construct the XML string
290
+ for key, value in params
291
+ elem = order.add_element(key.to_s)
292
+ if key == :items
293
+ build_items(elem, value)
294
+ else
295
+ for k, _ in params[key]
296
+ elem.add_element(k.to_s).text = params[key][k].to_s if params[key][k]
297
+ end
298
+ end
299
+ # Linkpoint doesn't understand empty elements:
300
+ order.delete(elem) if elem.size == 0
301
+ end
302
+ return xml.to_s
303
+ end
304
+
305
+ # adds LinkPoint's Items entity to the XML. Called from post_data
306
+ def build_items(element, items)
307
+ for item in items
308
+ item_element = element.add_element('item')
309
+ for key, value in item
310
+ if key == :options
311
+ options_element = item_element.add_element('options')
312
+ for option in value
313
+ opt_element = options_element.add_element('option')
314
+ opt_element.add_element('name').text = option[:name] unless option[:name].blank?
315
+ opt_element.add_element('value').text = option[:value] unless option[:value].blank?
316
+ end
317
+ else
318
+ item_element.add_element(key.to_s).text = item[key].to_s unless item[key].blank?
319
+ end
320
+ end
321
+ end
322
+ end
323
+
324
+ # Set up the parameters hash just once so we don't have to do it
325
+ # for every action.
326
+ def parameters(money, creditcard, options = {})
327
+ params = {
328
+ :payment => {
329
+ :subtotal => amount(options[:subtotal]),
330
+ :tax => amount(options[:tax]),
331
+ :vattax => amount(options[:vattax]),
332
+ :shipping => amount(options[:shipping]),
333
+ :chargetotal => amount(money)
334
+ },
335
+ :transactiondetails => {
336
+ :transactionorigin => options[:transactionorigin] || 'ECI',
337
+ :oid => options[:order_id],
338
+ :ponumber => options[:ponumber],
339
+ :taxexempt => options[:taxexempt],
340
+ :terminaltype => options[:terminaltype],
341
+ :ip => options[:ip],
342
+ :reference_number => options[:reference_number],
343
+ :recurring => options[:recurring] || 'NO', # DO NOT USE if you are using the periodic billing option.
344
+ :tdate => options[:tdate]
345
+ },
346
+ :orderoptions => {
347
+ :ordertype => options[:ordertype],
348
+ :result => @options[:result]
349
+ },
350
+ :periodic => {
351
+ :action => options[:action],
352
+ :installments => options[:installments],
353
+ :threshold => options[:threshold],
354
+ :startdate => options[:startdate],
355
+ :periodicity => options[:periodicity],
356
+ :comments => options[:comments]
357
+ },
358
+ :telecheck => {
359
+ :routing => options[:telecheck_routing],
360
+ :account => options[:telecheck_account],
361
+ :checknumber => options[:telecheck_checknumber],
362
+ :bankname => options[:telecheck_bankname],
363
+ :dl => options[:telecheck_dl],
364
+ :dlstate => options[:telecheck_dlstate],
365
+ :void => options[:telecheck_void],
366
+ :accounttype => options[:telecheck_accounttype],
367
+ :ssn => options[:telecheck_ssn],
368
+ }
369
+ }
370
+
371
+ if creditcard
372
+ params[:creditcard] = {
373
+ :cardnumber => creditcard.number,
374
+ :cardexpmonth => creditcard.month,
375
+ :cardexpyear => format_creditcard_expiry_year(creditcard.year),
376
+ :track => nil
377
+ }
378
+
379
+ if creditcard.verification_value?
380
+ params[:creditcard][:cvmvalue] = creditcard.verification_value
381
+ params[:creditcard][:cvmindicator] = 'provided'
382
+ else
383
+ params[:creditcard][:cvmindicator] = 'not_provided'
384
+ end
385
+ end
386
+
387
+ if billing_address = options[:billing_address] || options[:address]
388
+
389
+ params[:billing] = {}
390
+ params[:billing][:name] = billing_address[:name] || (creditcard ? creditcard.name : nil)
391
+ params[:billing][:address1] = billing_address[:address1] unless billing_address[:address1].blank?
392
+ params[:billing][:address2] = billing_address[:address2] unless billing_address[:address2].blank?
393
+ params[:billing][:city] = billing_address[:city] unless billing_address[:city].blank?
394
+ params[:billing][:state] = billing_address[:state] unless billing_address[:state].blank?
395
+ params[:billing][:zip] = billing_address[:zip] unless billing_address[:zip].blank?
396
+ params[:billing][:country] = billing_address[:country] unless billing_address[:country].blank?
397
+ params[:billing][:company] = billing_address[:company] unless billing_address[:company].blank?
398
+ params[:billing][:phone] = billing_address[:phone] unless billing_address[:phone].blank?
399
+ params[:billing][:email] = options[:email] unless options[:email].blank?
400
+ end
401
+
402
+ if shipping_address = options[:shipping_address]
403
+
404
+ params[:shipping] = {}
405
+ params[:shipping][:name] = shipping_address[:name] || (creditcard ? creditcard.name : nil)
406
+ params[:shipping][:address1] = shipping_address[:address1] unless shipping_address[:address1].blank?
407
+ params[:shipping][:address2] = shipping_address[:address2] unless shipping_address[:address2].blank?
408
+ params[:shipping][:city] = shipping_address[:city] unless shipping_address[:city].blank?
409
+ params[:shipping][:state] = shipping_address[:state] unless shipping_address[:state].blank?
410
+ params[:shipping][:zip] = shipping_address[:zip] unless shipping_address[:zip].blank?
411
+ params[:shipping][:country] = shipping_address[:country] unless shipping_address[:country].blank?
412
+ end
413
+
414
+ params[:items] = options[:line_items] if options[:line_items]
415
+
416
+ return params
417
+ end
418
+
419
+ def parse(xml)
420
+ # For reference, a typical response...
421
+ # <r_csp></r_csp>
422
+ # <r_time></r_time>
423
+ # <r_ref></r_ref>
424
+ # <r_error></r_error>
425
+ # <r_ordernum></r_ordernum>
426
+ # <r_message>This is a test transaction and will not show up in the Reports</r_message>
427
+ # <r_code></r_code>
428
+ # <r_tdate>Thu Feb 2 15:40:21 2006</r_tdate>
429
+ # <r_score></r_score>
430
+ # <r_authresponse></r_authresponse>
431
+ # <r_approved>APPROVED</r_approved>
432
+ # <r_avs></r_avs>
433
+
434
+ response = {:message => 'Global Error Receipt', :complete => false}
435
+
436
+ xml = REXML::Document.new("<response>#{xml}</response>")
437
+ xml.root&.elements&.each do |node|
438
+ response[node.name.downcase.sub(/^r_/, '').to_sym] = normalize(node.text)
439
+ end
440
+
441
+ response
442
+ end
443
+
444
+ def format_creditcard_expiry_year(year)
445
+ sprintf('%.4i', year)[-2..-1]
446
+ end
447
+ end
448
+ end
449
+ end
@@ -0,0 +1,507 @@
1
+ require 'nokogiri'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class LitleGateway < Gateway
6
+ SCHEMA_VERSION = '9.14'
7
+
8
+ self.test_url = 'https://www.testvantivcnp.com/sandbox/communicator/online'
9
+ self.live_url = 'https://payments.vantivcnp.com/vap/communicator/online'
10
+
11
+ self.supported_countries = ['US']
12
+ self.default_currency = 'USD'
13
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club, :jcb]
14
+
15
+ self.homepage_url = 'http://www.vantiv.com/'
16
+ self.display_name = 'Vantiv eCommerce'
17
+
18
+ def initialize(options={})
19
+ requires!(options, :login, :password, :merchant_id)
20
+ super
21
+ end
22
+
23
+ def purchase(money, payment_method, options={})
24
+ request = build_xml_request do |doc|
25
+ add_authentication(doc)
26
+ if check?(payment_method)
27
+ doc.echeckSale(transaction_attributes(options)) do
28
+ add_echeck_purchase_params(doc, money, payment_method, options)
29
+ end
30
+ else
31
+ doc.sale(transaction_attributes(options)) do
32
+ add_auth_purchase_params(doc, money, payment_method, options)
33
+ end
34
+ end
35
+ end
36
+ check?(payment_method) ? commit(:echeckSales, request, money) : commit(:sale, request, money)
37
+ end
38
+
39
+ def authorize(money, payment_method, options={})
40
+ request = build_xml_request do |doc|
41
+ add_authentication(doc)
42
+ if check?(payment_method)
43
+ doc.echeckVerification(transaction_attributes(options)) do
44
+ add_echeck_purchase_params(doc, money, payment_method, options)
45
+ end
46
+ else
47
+ doc.authorization(transaction_attributes(options)) do
48
+ add_auth_purchase_params(doc, money, payment_method, options)
49
+ end
50
+ end
51
+ end
52
+ check?(payment_method) ? commit(:echeckVerification, request, money) : commit(:authorization, request, money)
53
+ end
54
+
55
+ def capture(money, authorization, options={})
56
+ transaction_id, _, _ = split_authorization(authorization)
57
+
58
+ request = build_xml_request do |doc|
59
+ add_authentication(doc)
60
+ add_descriptor(doc, options)
61
+ doc.capture_(transaction_attributes(options)) do
62
+ doc.litleTxnId(transaction_id)
63
+ doc.amount(money) if money
64
+ end
65
+ end
66
+
67
+ commit(:capture, request, money)
68
+ end
69
+
70
+ def credit(money, authorization, options = {})
71
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
72
+ refund(money, authorization, options)
73
+ end
74
+
75
+ def refund(money, payment, options={})
76
+ request = build_xml_request do |doc|
77
+ add_authentication(doc)
78
+ add_descriptor(doc, options)
79
+ doc.send(refund_type(payment), transaction_attributes(options)) do
80
+ if payment.is_a?(String)
81
+ transaction_id, _, _ = split_authorization(payment)
82
+ doc.litleTxnId(transaction_id)
83
+ doc.amount(money) if money
84
+ elsif check?(payment)
85
+ add_echeck_purchase_params(doc, money, payment, options)
86
+ else
87
+ add_auth_purchase_params(doc, money, payment, options)
88
+ end
89
+ end
90
+ end
91
+
92
+ commit(refund_type(payment), request)
93
+ end
94
+
95
+ def verify(creditcard, options = {})
96
+ MultiResponse.run(:use_first_response) do |r|
97
+ r.process { authorize(0, creditcard, options) }
98
+ r.process(:ignore_result) { void(r.authorization, options) }
99
+ end
100
+ end
101
+
102
+ def void(authorization, options={})
103
+ transaction_id, kind, money = split_authorization(authorization)
104
+
105
+ request = build_xml_request do |doc|
106
+ add_authentication(doc)
107
+ doc.send(void_type(kind), transaction_attributes(options)) do
108
+ doc.litleTxnId(transaction_id)
109
+ doc.amount(money) if void_type(kind) == :authReversal
110
+ end
111
+ end
112
+
113
+ commit(void_type(kind), request)
114
+ end
115
+
116
+ def store(payment_method, options = {})
117
+ request = build_xml_request do |doc|
118
+ add_authentication(doc)
119
+ doc.registerTokenRequest(transaction_attributes(options)) do
120
+ doc.orderId(truncate(options[:order_id], 24))
121
+ if payment_method.is_a?(String)
122
+ doc.paypageRegistrationId(payment_method)
123
+ elsif check?(payment_method)
124
+ doc.echeckForToken do
125
+ doc.accNum(payment_method.account_number)
126
+ doc.routingNum(payment_method.routing_number)
127
+ end
128
+ else
129
+ doc.accountNumber(payment_method.number)
130
+ doc.cardValidationNum(payment_method.verification_value) if payment_method.verification_value
131
+ end
132
+ end
133
+ end
134
+
135
+ commit(:registerToken, request)
136
+ end
137
+
138
+ def supports_scrubbing?
139
+ true
140
+ end
141
+
142
+ def scrub(transcript)
143
+ transcript.
144
+ gsub(%r((<user>).+(</user>)), '\1[FILTERED]\2').
145
+ gsub(%r((<password>).+(</password>)), '\1[FILTERED]\2').
146
+ gsub(%r((<number>).+(</number>)), '\1[FILTERED]\2').
147
+ gsub(%r((<accNum>).+(</accNum>)), '\1[FILTERED]\2').
148
+ gsub(%r((<routingNum>).+(</routingNum>)), '\1[FILTERED]\2').
149
+ gsub(%r((<cardValidationNum>).+(</cardValidationNum>)), '\1[FILTERED]\2').
150
+ gsub(%r((<accountNumber>).+(</accountNumber>)), '\1[FILTERED]\2').
151
+ gsub(%r((<paypageRegistrationId>).+(</paypageRegistrationId>)), '\1[FILTERED]\2').
152
+ gsub(%r((<authenticationValue>).+(</authenticationValue>)), '\1[FILTERED]\2')
153
+ end
154
+
155
+ private
156
+
157
+ CARD_TYPE = {
158
+ 'visa' => 'VI',
159
+ 'master' => 'MC',
160
+ 'american_express' => 'AX',
161
+ 'discover' => 'DI',
162
+ 'jcb' => 'JC',
163
+ 'diners_club' => 'DC'
164
+ }
165
+
166
+ AVS_RESPONSE_CODE = {
167
+ '00' => 'Y',
168
+ '01' => 'X',
169
+ '02' => 'D',
170
+ '10' => 'Z',
171
+ '11' => 'W',
172
+ '12' => 'A',
173
+ '13' => 'A',
174
+ '14' => 'P',
175
+ '20' => 'N',
176
+ '30' => 'S',
177
+ '31' => 'R',
178
+ '32' => 'U',
179
+ '33' => 'R',
180
+ '34' => 'I',
181
+ '40' => 'E'
182
+ }
183
+
184
+ def void_type(kind)
185
+ if kind == 'authorization'
186
+ :authReversal
187
+ elsif kind == 'echeckSales'
188
+ :echeckVoid
189
+ else
190
+ :void
191
+ end
192
+ end
193
+
194
+ def refund_type(payment)
195
+ _, kind, _ = split_authorization(payment)
196
+ if check?(payment) || kind == 'echeckSales'
197
+ :echeckCredit
198
+ else
199
+ :credit
200
+ end
201
+ end
202
+
203
+ def check?(payment_method)
204
+ return false if payment_method.is_a?(String)
205
+ card_brand(payment_method) == 'check'
206
+ end
207
+
208
+ def add_authentication(doc)
209
+ doc.authentication do
210
+ doc.user(@options[:login])
211
+ doc.password(@options[:password])
212
+ end
213
+ end
214
+
215
+ def add_auth_purchase_params(doc, money, payment_method, options)
216
+ doc.orderId(truncate(options[:order_id], 24))
217
+ doc.amount(money)
218
+ add_order_source(doc, payment_method, options)
219
+ add_billing_address(doc, payment_method, options)
220
+ add_shipping_address(doc, payment_method, options)
221
+ add_payment_method(doc, payment_method, options)
222
+ add_pos(doc, payment_method)
223
+ add_descriptor(doc, options)
224
+ add_merchant_data(doc, options)
225
+ add_debt_repayment(doc, options)
226
+ add_stored_credential_params(doc, options)
227
+ end
228
+
229
+ def add_merchant_data(doc, options={})
230
+ if options[:affiliate] || options[:campaign] || options[:merchant_grouping_id]
231
+ doc.merchantData do
232
+ doc.affiliate(options[:affiliate]) if options[:affiliate]
233
+ doc.campaign(options[:campaign]) if options[:campaign]
234
+ doc.merchantGroupingId(options[:merchant_grouping_id]) if options[:merchant_grouping_id]
235
+ end
236
+ end
237
+ end
238
+
239
+ def add_echeck_purchase_params(doc, money, payment_method, options)
240
+ doc.orderId(truncate(options[:order_id], 24))
241
+ doc.amount(money)
242
+ add_order_source(doc, payment_method, options)
243
+ add_billing_address(doc, payment_method, options)
244
+ add_payment_method(doc, payment_method, options)
245
+ add_descriptor(doc, options)
246
+ end
247
+
248
+ def add_descriptor(doc, options)
249
+ if options[:descriptor_name] || options[:descriptor_phone]
250
+ doc.customBilling do
251
+ doc.phone(options[:descriptor_phone]) if options[:descriptor_phone]
252
+ doc.descriptor(options[:descriptor_name]) if options[:descriptor_name]
253
+ end
254
+ end
255
+ end
256
+
257
+ def add_debt_repayment(doc, options)
258
+ doc.debtRepayment(true) if options[:debt_repayment] == true
259
+ end
260
+
261
+ def add_payment_method(doc, payment_method, options)
262
+ if payment_method.is_a?(String)
263
+ doc.token do
264
+ doc.litleToken(payment_method)
265
+ end
266
+ elsif payment_method.respond_to?(:track_data) && payment_method.track_data.present?
267
+ doc.card do
268
+ doc.track(payment_method.track_data)
269
+ end
270
+ elsif check?(payment_method)
271
+ doc.echeck do
272
+ doc.accType(payment_method.account_type.capitalize)
273
+ doc.accNum(payment_method.account_number)
274
+ doc.routingNum(payment_method.routing_number)
275
+ doc.checkNum(payment_method.number)
276
+ end
277
+ else
278
+ doc.card do
279
+ doc.type_(CARD_TYPE[payment_method.brand])
280
+ doc.number(payment_method.number)
281
+ doc.expDate(exp_date(payment_method))
282
+ doc.cardValidationNum(payment_method.verification_value)
283
+ end
284
+ if payment_method.is_a?(NetworkTokenizationCreditCard)
285
+ doc.cardholderAuthentication do
286
+ doc.authenticationValue(payment_method.payment_cryptogram)
287
+ end
288
+ elsif options[:order_source]&.start_with?('3ds')
289
+ doc.cardholderAuthentication do
290
+ doc.authenticationValue(options[:cavv]) if options[:cavv]
291
+ doc.authenticationTransactionId(options[:xid]) if options[:xid]
292
+ end
293
+ end
294
+ end
295
+ end
296
+
297
+ def add_stored_credential_params(doc, options={})
298
+ return unless options[:stored_credential]
299
+
300
+ if options[:stored_credential][:initial_transaction]
301
+ add_stored_credential_params_initial(doc, options)
302
+ else
303
+ add_stored_credential_params_used(doc, options)
304
+ end
305
+ end
306
+
307
+ def add_stored_credential_params_initial(doc, options)
308
+ case options[:stored_credential][:reason_type]
309
+ when 'unscheduled'
310
+ doc.processingType('initialCOF')
311
+ when 'installment'
312
+ doc.processingType('initialInstallment')
313
+ when 'recurring'
314
+ doc.processingType('initialRecurring')
315
+ end
316
+ end
317
+
318
+ def add_stored_credential_params_used(doc, options)
319
+ if options[:stored_credential][:reason_type] == 'unscheduled'
320
+ if options[:stored_credential][:initiator] == 'merchant'
321
+ doc.processingType('merchantInitiatedCOF')
322
+ else
323
+ doc.processingType('cardholderInitiatedCOF')
324
+ end
325
+ end
326
+ doc.originalNetworkTransactionId(options[:stored_credential][:network_transaction_id])
327
+ end
328
+
329
+ def add_billing_address(doc, payment_method, options)
330
+ return if payment_method.is_a?(String)
331
+
332
+ doc.billToAddress do
333
+ if check?(payment_method)
334
+ doc.name(payment_method.name)
335
+ doc.firstName(payment_method.first_name)
336
+ doc.lastName(payment_method.last_name)
337
+ else
338
+ doc.name(payment_method.name)
339
+ end
340
+ doc.email(options[:email]) if options[:email]
341
+
342
+ add_address(doc, options[:billing_address])
343
+ end
344
+ end
345
+
346
+ def add_shipping_address(doc, payment_method, options)
347
+ return if payment_method.is_a?(String)
348
+
349
+ doc.shipToAddress do
350
+ add_address(doc, options[:shipping_address])
351
+ end
352
+ end
353
+
354
+ def add_address(doc, address)
355
+ return unless address
356
+
357
+ doc.companyName(address[:company]) unless address[:company].blank?
358
+ doc.addressLine1(address[:address1]) unless address[:address1].blank?
359
+ doc.addressLine2(address[:address2]) unless address[:address2].blank?
360
+ doc.city(address[:city]) unless address[:city].blank?
361
+ doc.state(address[:state]) unless address[:state].blank?
362
+ doc.zip(address[:zip]) unless address[:zip].blank?
363
+ doc.country(address[:country]) unless address[:country].blank?
364
+ doc.phone(address[:phone]) unless address[:phone].blank?
365
+ end
366
+
367
+ def add_order_source(doc, payment_method, options)
368
+ order_source = order_source(options)
369
+ if order_source
370
+ doc.orderSource(order_source)
371
+ elsif payment_method.is_a?(NetworkTokenizationCreditCard) && payment_method.source == :apple_pay
372
+ doc.orderSource('applepay')
373
+ elsif payment_method.is_a?(NetworkTokenizationCreditCard) && payment_method.source == :android_pay
374
+ doc.orderSource('androidpay')
375
+ elsif payment_method.respond_to?(:track_data) && payment_method.track_data.present?
376
+ doc.orderSource('retail')
377
+ else
378
+ doc.orderSource('ecommerce')
379
+ end
380
+ end
381
+
382
+ def order_source(options={})
383
+ return options[:order_source] unless options[:stored_credential]
384
+ order_source = nil
385
+
386
+ case options[:stored_credential][:reason_type]
387
+ when 'unscheduled'
388
+ if options[:stored_credential][:initiator] == 'merchant'
389
+ # For merchant-initiated, we should always set order source to
390
+ # 'ecommerce'
391
+ order_source = 'ecommerce'
392
+ else
393
+ # For cardholder-initiated, we rely on #add_order_source's
394
+ # default logic to set orderSource appropriately
395
+ order_source = options[:order_source]
396
+ end
397
+ when 'installment'
398
+ order_source = 'installment'
399
+ when 'recurring'
400
+ order_source = 'recurring'
401
+ end
402
+
403
+ order_source
404
+ end
405
+
406
+ def add_pos(doc, payment_method)
407
+ return unless payment_method.respond_to?(:track_data) && payment_method.track_data.present?
408
+
409
+ doc.pos do
410
+ doc.capability('magstripe')
411
+ doc.entryMode('completeread')
412
+ doc.cardholderId('signature')
413
+ end
414
+ end
415
+
416
+ def exp_date(payment_method)
417
+ "#{format(payment_method.month, :two_digits)}#{format(payment_method.year, :two_digits)}"
418
+ end
419
+
420
+ def parse(kind, xml)
421
+ parsed = {}
422
+
423
+ doc = Nokogiri::XML(xml).remove_namespaces!
424
+ doc.xpath("//litleOnlineResponse/#{kind}Response/*").each do |node|
425
+ if node.elements.empty?
426
+ parsed[node.name.to_sym] = node.text
427
+ else
428
+ node.elements.each do |childnode|
429
+ name = "#{node.name}_#{childnode.name}"
430
+ parsed[name.to_sym] = childnode.text
431
+ end
432
+ end
433
+ end
434
+
435
+ if parsed.empty?
436
+ %w(response message).each do |attribute|
437
+ parsed[attribute.to_sym] = doc.xpath('//litleOnlineResponse').attribute(attribute).value
438
+ end
439
+ end
440
+
441
+ parsed
442
+ end
443
+
444
+ def commit(kind, request, money=nil)
445
+ parsed = parse(kind, ssl_post(url, request, headers))
446
+
447
+ options = {
448
+ authorization: authorization_from(kind, parsed, money),
449
+ test: test?,
450
+ :avs_result => { :code => AVS_RESPONSE_CODE[parsed[:fraudResult_avsResult]] },
451
+ :cvv_result => parsed[:fraudResult_cardValidationResult]
452
+ }
453
+
454
+ Response.new(success_from(kind, parsed), parsed[:message], parsed, options)
455
+ end
456
+
457
+ def success_from(kind, parsed)
458
+ return (parsed[:response] == '000') unless kind == :registerToken
459
+ %w(000 801 802).include?(parsed[:response])
460
+ end
461
+
462
+ def authorization_from(kind, parsed, money)
463
+ kind == :registerToken ? parsed[:litleToken] : "#{parsed[:litleTxnId]};#{kind};#{money}"
464
+ end
465
+
466
+ def split_authorization(authorization)
467
+ transaction_id, kind, money = authorization.to_s.split(';')
468
+ [transaction_id, kind, money]
469
+ end
470
+
471
+ def transaction_attributes(options)
472
+ attributes = {}
473
+ attributes[:id] = truncate(options[:id] || options[:order_id], 24)
474
+ attributes[:reportGroup] = options[:merchant] || 'Default Report Group'
475
+ attributes[:customerId] = options[:customer]
476
+ attributes.delete_if { |key, value| value == nil }
477
+ attributes
478
+ end
479
+
480
+ def root_attributes
481
+ {
482
+ merchantId: @options[:merchant_id],
483
+ version: SCHEMA_VERSION,
484
+ xmlns: 'http://www.litle.com/schema'
485
+ }
486
+ end
487
+
488
+ def build_xml_request
489
+ builder = Nokogiri::XML::Builder.new
490
+ builder.__send__('litleOnlineRequest', root_attributes) do |doc|
491
+ yield(doc)
492
+ end
493
+ builder.doc.root.to_xml
494
+ end
495
+
496
+ def url
497
+ test? ? test_url : live_url
498
+ end
499
+
500
+ def headers
501
+ {
502
+ 'Content-Type' => 'text/xml'
503
+ }
504
+ end
505
+ end
506
+ end
507
+ end