swiss-crm-activemerchant 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +4033 -0
  3. data/CONTRIBUTORS +568 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +252 -0
  6. data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
  7. data/lib/active_merchant/billing/avs_result.rb +95 -0
  8. data/lib/active_merchant/billing/base.rb +48 -0
  9. data/lib/active_merchant/billing/check.rb +112 -0
  10. data/lib/active_merchant/billing/compatibility.rb +118 -0
  11. data/lib/active_merchant/billing/credit_card.rb +451 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +512 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +37 -0
  15. data/lib/active_merchant/billing/gateway.rb +332 -0
  16. data/lib/active_merchant/billing/gateways/adyen.rb +774 -0
  17. data/lib/active_merchant/billing/gateways/airwallex.rb +370 -0
  18. data/lib/active_merchant/billing/gateways/alelo.rb +256 -0
  19. data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
  20. data/lib/active_merchant/billing/gateways/authorize_net.rb +1125 -0
  21. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +424 -0
  22. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +977 -0
  23. data/lib/active_merchant/billing/gateways/axcessms.rb +242 -0
  24. data/lib/active_merchant/billing/gateways/balanced.rb +263 -0
  25. data/lib/active_merchant/billing/gateways/bambora_apac.rb +222 -0
  26. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  27. data/lib/active_merchant/billing/gateways/banwire.rb +116 -0
  28. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +397 -0
  29. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
  30. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  31. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +474 -0
  32. data/lib/active_merchant/billing/gateways/beanstream.rb +238 -0
  33. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +57 -0
  34. data/lib/active_merchant/billing/gateways/blue_pay.rb +549 -0
  35. data/lib/active_merchant/billing/gateways/blue_snap.rb +644 -0
  36. data/lib/active_merchant/billing/gateways/bogus.rb +190 -0
  37. data/lib/active_merchant/billing/gateways/borgun.rb +272 -0
  38. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  39. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +28 -0
  40. data/lib/active_merchant/billing/gateways/braintree/token_nonce.rb +113 -0
  41. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  42. data/lib/active_merchant/billing/gateways/braintree_blue.rb +952 -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 +338 -0
  47. data/lib/active_merchant/billing/gateways/card_save.rb +21 -0
  48. data/lib/active_merchant/billing/gateways/card_stream.rb +394 -0
  49. data/lib/active_merchant/billing/gateways/cardknox.rb +327 -0
  50. data/lib/active_merchant/billing/gateways/cardprocess.rb +256 -0
  51. data/lib/active_merchant/billing/gateways/cashnet.rb +235 -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 +328 -0
  55. data/lib/active_merchant/billing/gateways/checkout.rb +212 -0
  56. data/lib/active_merchant/billing/gateways/checkout_v2.rb +587 -0
  57. data/lib/active_merchant/billing/gateways/citrus_pay.rb +21 -0
  58. data/lib/active_merchant/billing/gateways/clearhaus.rb +219 -0
  59. data/lib/active_merchant/billing/gateways/commerce_hub.rb +366 -0
  60. data/lib/active_merchant/billing/gateways/commercegate.rb +142 -0
  61. data/lib/active_merchant/billing/gateways/conekta.rb +230 -0
  62. data/lib/active_merchant/billing/gateways/creditcall.rb +272 -0
  63. data/lib/active_merchant/billing/gateways/credorax.rb +526 -0
  64. data/lib/active_merchant/billing/gateways/ct_payment.rb +269 -0
  65. data/lib/active_merchant/billing/gateways/culqi.rb +279 -0
  66. data/lib/active_merchant/billing/gateways/cyber_source/cyber_source_common.rb +36 -0
  67. data/lib/active_merchant/billing/gateways/cyber_source.rb +1148 -0
  68. data/lib/active_merchant/billing/gateways/cyber_source_rest.rb +454 -0
  69. data/lib/active_merchant/billing/gateways/d_local.rb +343 -0
  70. data/lib/active_merchant/billing/gateways/data_cash.rb +302 -0
  71. data/lib/active_merchant/billing/gateways/decidir.rb +358 -0
  72. data/lib/active_merchant/billing/gateways/decidir_plus.rb +344 -0
  73. data/lib/active_merchant/billing/gateways/dibs.rb +199 -0
  74. data/lib/active_merchant/billing/gateways/digitzs.rb +295 -0
  75. data/lib/active_merchant/billing/gateways/ebanx.rb +346 -0
  76. data/lib/active_merchant/billing/gateways/efsnet.rb +215 -0
  77. data/lib/active_merchant/billing/gateways/elavon.rb +475 -0
  78. data/lib/active_merchant/billing/gateways/element.rb +406 -0
  79. data/lib/active_merchant/billing/gateways/epay.rb +296 -0
  80. data/lib/active_merchant/billing/gateways/evo_ca.rb +307 -0
  81. data/lib/active_merchant/billing/gateways/eway.rb +226 -0
  82. data/lib/active_merchant/billing/gateways/eway_managed.rb +289 -0
  83. data/lib/active_merchant/billing/gateways/eway_rapid.rb +578 -0
  84. data/lib/active_merchant/billing/gateways/exact.rb +219 -0
  85. data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
  86. data/lib/active_merchant/billing/gateways/fat_zebra.rb +223 -0
  87. data/lib/active_merchant/billing/gateways/federated_canada.rb +158 -0
  88. data/lib/active_merchant/billing/gateways/finansbank.rb +22 -0
  89. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  90. data/lib/active_merchant/billing/gateways/first_pay.rb +182 -0
  91. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +452 -0
  92. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +505 -0
  93. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  94. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  95. data/lib/active_merchant/billing/gateways/fluidpay.rb +275 -0
  96. data/lib/active_merchant/billing/gateways/forte.rb +286 -0
  97. data/lib/active_merchant/billing/gateways/garanti.rb +256 -0
  98. data/lib/active_merchant/billing/gateways/global_collect.rb +580 -0
  99. data/lib/active_merchant/billing/gateways/global_transport.rb +193 -0
  100. data/lib/active_merchant/billing/gateways/hdfc.rb +205 -0
  101. data/lib/active_merchant/billing/gateways/hps.rb +472 -0
  102. data/lib/active_merchant/billing/gateways/iats_payments.rb +312 -0
  103. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  104. data/lib/active_merchant/billing/gateways/inspire.rb +213 -0
  105. data/lib/active_merchant/billing/gateways/instapay.rb +159 -0
  106. data/lib/active_merchant/billing/gateways/ipg.rb +420 -0
  107. data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
  108. data/lib/active_merchant/billing/gateways/iridium.rb +467 -0
  109. data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
  110. data/lib/active_merchant/billing/gateways/iveri.rb +290 -0
  111. data/lib/active_merchant/billing/gateways/ixopay.rb +320 -0
  112. data/lib/active_merchant/billing/gateways/jetpay.rb +395 -0
  113. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +432 -0
  114. data/lib/active_merchant/billing/gateways/klarna.rb +317 -0
  115. data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
  116. data/lib/active_merchant/billing/gateways/kushki.rb +297 -0
  117. data/lib/active_merchant/billing/gateways/latitude19.rb +412 -0
  118. data/lib/active_merchant/billing/gateways/linkpoint.rb +448 -0
  119. data/lib/active_merchant/billing/gateways/litle.rb +643 -0
  120. data/lib/active_merchant/billing/gateways/mastercard.rb +286 -0
  121. data/lib/active_merchant/billing/gateways/maxipago.rb +220 -0
  122. data/lib/active_merchant/billing/gateways/mercado_pago.rb +348 -0
  123. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +228 -0
  124. data/lib/active_merchant/billing/gateways/merchant_one.rb +110 -0
  125. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  126. data/lib/active_merchant/billing/gateways/merchant_ware.rb +313 -0
  127. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +284 -0
  128. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +248 -0
  129. data/lib/active_merchant/billing/gateways/mercury.rb +352 -0
  130. data/lib/active_merchant/billing/gateways/metrics_global.rb +293 -0
  131. data/lib/active_merchant/billing/gateways/micropayment.rb +182 -0
  132. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  133. data/lib/active_merchant/billing/gateways/migs.rb +329 -0
  134. data/lib/active_merchant/billing/gateways/mit.rb +260 -0
  135. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  136. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +215 -0
  137. data/lib/active_merchant/billing/gateways/moka.rb +290 -0
  138. data/lib/active_merchant/billing/gateways/monei.rb +424 -0
  139. data/lib/active_merchant/billing/gateways/moneris.rb +488 -0
  140. data/lib/active_merchant/billing/gateways/money_movers.rb +150 -0
  141. data/lib/active_merchant/billing/gateways/mundipagg.rb +366 -0
  142. data/lib/active_merchant/billing/gateways/nab_transact.rb +299 -0
  143. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +163 -0
  144. data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
  145. data/lib/active_merchant/billing/gateways/netaxept.rb +180 -0
  146. data/lib/active_merchant/billing/gateways/netbanx.rb +376 -0
  147. data/lib/active_merchant/billing/gateways/netbilling.rb +229 -0
  148. data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
  149. data/lib/active_merchant/billing/gateways/network_merchants.rb +238 -0
  150. data/lib/active_merchant/billing/gateways/nmi.rb +396 -0
  151. data/lib/active_merchant/billing/gateways/ogone.rb +509 -0
  152. data/lib/active_merchant/billing/gateways/omise.rb +323 -0
  153. data/lib/active_merchant/billing/gateways/openpay.rb +246 -0
  154. data/lib/active_merchant/billing/gateways/opp.rb +394 -0
  155. data/lib/active_merchant/billing/gateways/optimal_payment.rb +331 -0
  156. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +45 -0
  157. data/lib/active_merchant/billing/gateways/orbital.rb +1267 -0
  158. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +206 -0
  159. data/lib/active_merchant/billing/gateways/pagarme.rb +239 -0
  160. data/lib/active_merchant/billing/gateways/pago_facil.rb +120 -0
  161. data/lib/active_merchant/billing/gateways/pay_arc.rb +392 -0
  162. data/lib/active_merchant/billing/gateways/pay_conex.rb +245 -0
  163. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +277 -0
  164. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  165. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  166. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +206 -0
  167. data/lib/active_merchant/billing/gateways/pay_secure.rb +110 -0
  168. data/lib/active_merchant/billing/gateways/pay_trace.rb +450 -0
  169. data/lib/active_merchant/billing/gateways/paybox_direct.rb +224 -0
  170. data/lib/active_merchant/billing/gateways/payeezy.rb +513 -0
  171. data/lib/active_merchant/billing/gateways/payex.rb +409 -0
  172. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +235 -0
  173. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +42 -0
  174. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  175. data/lib/active_merchant/billing/gateways/payflow.rb +473 -0
  176. data/lib/active_merchant/billing/gateways/payflow_express.rb +220 -0
  177. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +14 -0
  178. data/lib/active_merchant/billing/gateways/payflow_uk.rb +20 -0
  179. data/lib/active_merchant/billing/gateways/payment_express.rb +373 -0
  180. data/lib/active_merchant/billing/gateways/paymentez.rb +365 -0
  181. data/lib/active_merchant/billing/gateways/paymill.rb +369 -0
  182. data/lib/active_merchant/billing/gateways/paynetworx.rb +228 -0
  183. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +718 -0
  184. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +69 -0
  185. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  186. data/lib/active_merchant/billing/gateways/paypal.rb +136 -0
  187. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  188. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  189. data/lib/active_merchant/billing/gateways/paypal_express.rb +272 -0
  190. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  191. data/lib/active_merchant/billing/gateways/paypal_standard.rb +281 -0
  192. data/lib/active_merchant/billing/gateways/paysafe.rb +420 -0
  193. data/lib/active_merchant/billing/gateways/payscout.rb +159 -0
  194. data/lib/active_merchant/billing/gateways/paystation.rb +204 -0
  195. data/lib/active_merchant/billing/gateways/payu_in.rb +249 -0
  196. data/lib/active_merchant/billing/gateways/payu_latam.rb +482 -0
  197. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  198. data/lib/active_merchant/billing/gateways/payway_dot_com.rb +253 -0
  199. data/lib/active_merchant/billing/gateways/pin.rb +273 -0
  200. data/lib/active_merchant/billing/gateways/pixxels.rb +263 -0
  201. data/lib/active_merchant/billing/gateways/plexo.rb +308 -0
  202. data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
  203. data/lib/active_merchant/billing/gateways/priority.rb +392 -0
  204. data/lib/active_merchant/billing/gateways/pro_pay.rb +325 -0
  205. data/lib/active_merchant/billing/gateways/psigate.rb +227 -0
  206. data/lib/active_merchant/billing/gateways/psl_card.rb +295 -0
  207. data/lib/active_merchant/billing/gateways/qbms.rb +302 -0
  208. data/lib/active_merchant/billing/gateways/quantum.rb +274 -0
  209. data/lib/active_merchant/billing/gateways/quickbooks.rb +377 -0
  210. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +184 -0
  211. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +297 -0
  212. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +226 -0
  213. data/lib/active_merchant/billing/gateways/quickpay.rb +24 -0
  214. data/lib/active_merchant/billing/gateways/qvalent.rb +305 -0
  215. data/lib/active_merchant/billing/gateways/rapyd.rb +319 -0
  216. data/lib/active_merchant/billing/gateways/reach.rb +277 -0
  217. data/lib/active_merchant/billing/gateways/realex.rb +400 -0
  218. data/lib/active_merchant/billing/gateways/redsys.rb +723 -0
  219. data/lib/active_merchant/billing/gateways/s5.rb +247 -0
  220. data/lib/active_merchant/billing/gateways/safe_charge.rb +298 -0
  221. data/lib/active_merchant/billing/gateways/sage.rb +446 -0
  222. data/lib/active_merchant/billing/gateways/sage_pay.rb +434 -0
  223. data/lib/active_merchant/billing/gateways/sallie_mae.rb +141 -0
  224. data/lib/active_merchant/billing/gateways/secure_net.rb +260 -0
  225. data/lib/active_merchant/billing/gateways/secure_pay.rb +191 -0
  226. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +290 -0
  227. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +103 -0
  228. data/lib/active_merchant/billing/gateways/securion_pay.rb +305 -0
  229. data/lib/active_merchant/billing/gateways/shift4.rb +345 -0
  230. data/lib/active_merchant/billing/gateways/simetrik.rb +368 -0
  231. data/lib/active_merchant/billing/gateways/skip_jack.rb +450 -0
  232. data/lib/active_merchant/billing/gateways/smart_ps.rb +274 -0
  233. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  234. data/lib/active_merchant/billing/gateways/spreedly_core.rb +354 -0
  235. data/lib/active_merchant/billing/gateways/stripe.rb +866 -0
  236. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +602 -0
  237. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +151 -0
  238. data/lib/active_merchant/billing/gateways/telr.rb +273 -0
  239. data/lib/active_merchant/billing/gateways/tns.rb +23 -0
  240. data/lib/active_merchant/billing/gateways/trans_first.rb +240 -0
  241. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +612 -0
  242. data/lib/active_merchant/billing/gateways/transact_pro.rb +222 -0
  243. data/lib/active_merchant/billing/gateways/transax.rb +21 -0
  244. data/lib/active_merchant/billing/gateways/transnational.rb +9 -0
  245. data/lib/active_merchant/billing/gateways/trexle.rb +221 -0
  246. data/lib/active_merchant/billing/gateways/trust_commerce.rb +500 -0
  247. data/lib/active_merchant/billing/gateways/usa_epay.rb +24 -0
  248. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1612 -0
  249. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +367 -0
  250. data/lib/active_merchant/billing/gateways/vanco.rb +303 -0
  251. data/lib/active_merchant/billing/gateways/verifi.rb +224 -0
  252. data/lib/active_merchant/billing/gateways/viaklix.rb +171 -0
  253. data/lib/active_merchant/billing/gateways/visanet_peru.rb +250 -0
  254. data/lib/active_merchant/billing/gateways/vpos.rb +223 -0
  255. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  256. data/lib/active_merchant/billing/gateways/wepay.rb +235 -0
  257. data/lib/active_merchant/billing/gateways/wirecard.rb +430 -0
  258. data/lib/active_merchant/billing/gateways/wompi.rb +197 -0
  259. data/lib/active_merchant/billing/gateways/world_net.rb +345 -0
  260. data/lib/active_merchant/billing/gateways/worldpay.rb +1050 -0
  261. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +208 -0
  262. data/lib/active_merchant/billing/gateways/worldpay_us.rb +221 -0
  263. data/lib/active_merchant/billing/gateways.rb +14 -0
  264. data/lib/active_merchant/billing/model.rb +30 -0
  265. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
  266. data/lib/active_merchant/billing/payment_token.rb +21 -0
  267. data/lib/active_merchant/billing/rails.rb +3 -0
  268. data/lib/active_merchant/billing/response.rb +121 -0
  269. data/lib/active_merchant/billing/three_d_secure_eci_mapper.rb +27 -0
  270. data/lib/active_merchant/billing.rb +16 -0
  271. data/lib/active_merchant/connection.rb +194 -0
  272. data/lib/active_merchant/country.rb +338 -0
  273. data/lib/active_merchant/empty.rb +20 -0
  274. data/lib/active_merchant/errors.rb +38 -0
  275. data/lib/active_merchant/net_http_ssl_connection.rb +11 -0
  276. data/lib/active_merchant/network_connection_retries.rb +78 -0
  277. data/lib/active_merchant/post_data.rb +26 -0
  278. data/lib/active_merchant/posts_data.rb +92 -0
  279. data/lib/active_merchant/version.rb +3 -0
  280. data/lib/active_merchant.rb +63 -0
  281. data/lib/activemerchant.rb +1 -0
  282. data/lib/certs/cacert.pem +3214 -0
  283. data/lib/support/gateway_support.rb +69 -0
  284. data/lib/support/outbound_hosts.rb +28 -0
  285. data/lib/support/ssl_verify.rb +88 -0
  286. data/lib/support/ssl_version.rb +86 -0
  287. metadata +506 -0
@@ -0,0 +1,1612 @@
1
+ require 'securerandom'
2
+ require 'digest'
3
+
4
+ module ActiveMerchant #:nodoc:
5
+ module Billing #:nodoc:
6
+ # ==== USA ePay Advanced SOAP Interface
7
+ #
8
+ # This class encapsulates USA ePay's Advanced SOAP Interface. The Advanced Soap Interface allows
9
+ # standard transactions, storing customer information, and recurring billing. Storing sensitive
10
+ # information on USA ePay's servers can help with PCI DSS compliance, since customer and card data
11
+ # do not need to be stored locally.
12
+ #
13
+ # Make sure you have enabled this functionality for your account with USA ePay.
14
+ #
15
+ # Information about the Advanced SOAP interface is available on the {USA ePay wiki}[http://wiki.usaepay.com/developer/soap].
16
+ #
17
+ # ==== Login, Password, and Software ID
18
+ #
19
+ # Please follow all of USA ePay's directions for acquiring all accounts and settings.
20
+ #
21
+ # The value used for <tt>:login</tt> is the Key value found in the Merchant Console under Settings > Source
22
+ # Key. You will have to add this key in the USA ePay Merchant Console.
23
+ #
24
+ # The value used for <tt>:password</tt> is the pin value also found and assigned in the Merchant Console under
25
+ # Settings > Source Key. The pin is required to use all but basic transactions in the SOAP interface.
26
+ # You will have to add the pin to your source key, as it defaults to none.
27
+ #
28
+ # The value used for the <tt>:software_id</tt> is found in the Developer's Login under the Developers Center
29
+ # in your WSDL. It is the 8 character value in <soap:address> tag. A masked example:
30
+ # <soap:address location="https://www.usaepay.com/soap/gate/XXXXXXXX"/>
31
+ # It is also found in the link to your WSDL. This is required as every account has a different path
32
+ # SOAP requests are submitted to. Optionally, you can provide the entire urls via <tt>:live_url</tt> and <tt>:test_url</tt>, if your prefer.
33
+ #
34
+ # ==== Responses
35
+ # * <tt>#success?</tt> -- +true+ if transmitted and returned correctly
36
+ # * <tt>#message</tt> -- response or fault message
37
+ # * <tt>#authorization</tt> -- reference_number or nil
38
+ # * <tt>#params</tt> -- hash of entire soap response contents
39
+ #
40
+ # ==== Address Options
41
+ # * <tt>:billing_address/:shipping_address</tt> -- contains some extra options
42
+ # * <tt>:name</tt> -- virtual attribute; will split to first and last name
43
+ # * <tt>:first_name</tt>
44
+ # * <tt>:last_name</tt>
45
+ # * <tt>:address1 </tt>
46
+ # * <tt>:address2 </tt>
47
+ # * <tt>:city </tt>
48
+ # * <tt>:state </tt>
49
+ # * <tt>:zip </tt>
50
+ # * <tt>:country </tt>
51
+ # * <tt>:phone</tt>
52
+ # * <tt>:email</tt>
53
+ # * <tt>:fax</tt>
54
+ # * <tt>:company</tt>
55
+ #
56
+ # ==== Support:
57
+ # * Questions: post to {active_merchant google group}[http://groups.google.com/group/activemerchant]
58
+ # * Feedback/fixes: matt (at) nearapogee (dot) com
59
+ #
60
+ # ==== Links:
61
+ # * {USA ePay Merchant Console}[https://sandbox.usaepay.com/login]
62
+ # * {USA ePay Developer Login}[https://www.usaepay.com/developer/login]
63
+ #
64
+ class UsaEpayAdvancedGateway < Gateway
65
+ API_VERSION = '1.4'
66
+
67
+ TEST_URL_BASE = 'https://sandbox.usaepay.com/soap/gate/' #:nodoc:
68
+ LIVE_URL_BASE = 'https://www.usaepay.com/soap/gate/' #:nodoc:
69
+
70
+ self.test_url = TEST_URL_BASE
71
+ self.live_url = LIVE_URL_BASE
72
+
73
+ FAILURE_MESSAGE = 'Default Failure' #:nodoc:
74
+
75
+ self.supported_countries = ['US']
76
+ self.supported_cardtypes = %i[visa master american_express discover diners_club jcb]
77
+ self.homepage_url = 'http://www.usaepay.com/'
78
+ self.display_name = 'USA ePay Advanced SOAP Interface'
79
+
80
+ CUSTOMER_PROFILE_OPTIONS = {
81
+ id: [:string, 'CustomerID'], # merchant assigned number
82
+ notes: [:string, 'Notes'],
83
+ data: [:string, 'CustomData'],
84
+ url: [:string, 'URL']
85
+ } #:nodoc:
86
+
87
+ CUSTOMER_RECURRING_BILLING_OPTIONS = {
88
+ enabled: [:boolean, 'Enabled'],
89
+ schedule: [:string, 'Schedule'],
90
+ number_left: [:integer, 'NumLeft'],
91
+ currency: [:string, 'Currency'],
92
+ description: [:string, 'Description'],
93
+ order_id: [:string, 'OrderID'],
94
+ user: [:string, 'User'],
95
+ source: [:string, 'Source'],
96
+ send_receipt: [:boolean, 'SendReceipt'],
97
+ receipt_note: [:string, 'ReceiptNote']
98
+ } #:nodoc:
99
+
100
+ CUSTOMER_POINT_OF_SALE_OPTIONS = {
101
+ price_tier: [:string, 'PriceTier'],
102
+ tax_class: [:string, 'TaxClass'],
103
+ lookup_code: [:string, 'LookupCode']
104
+ } #:nodoc:
105
+
106
+ CUSTOMER_OPTIONS = [
107
+ CUSTOMER_PROFILE_OPTIONS,
108
+ CUSTOMER_RECURRING_BILLING_OPTIONS,
109
+ CUSTOMER_POINT_OF_SALE_OPTIONS
110
+ ].inject(:merge) #:nodoc:
111
+
112
+ COMMON_ADDRESS_OPTIONS = {
113
+ first_name: [:string, 'FirstName'],
114
+ last_name: [:string, 'LastName'],
115
+ city: [:string, 'City'],
116
+ state: [:string, 'State'],
117
+ zip: [:string, 'Zip'],
118
+ country: [:string, 'Country'],
119
+ phone: [:string, 'Phone'],
120
+ email: [:string, 'Email'],
121
+ fax: [:string, 'Fax'],
122
+ company: [:string, 'Company']
123
+ } #:nodoc:
124
+
125
+ ADDRESS_OPTIONS = [
126
+ COMMON_ADDRESS_OPTIONS,
127
+ {
128
+ address1: [:string, 'Street'],
129
+ address2: [:string, 'Street2']
130
+ }
131
+ ].inject(:merge) #:nodoc
132
+
133
+ CUSTOMER_UPDATE_DATA_FIELDS = [
134
+ CUSTOMER_PROFILE_OPTIONS,
135
+ CUSTOMER_RECURRING_BILLING_OPTIONS,
136
+ COMMON_ADDRESS_OPTIONS,
137
+ {
138
+ address1: [:string, 'Address'],
139
+ address2: [:string, 'Address2']
140
+ },
141
+ {
142
+ card_number: [:string, 'CardNumber'],
143
+ card_exp: [:string, 'CardExp'],
144
+ account: [:string, 'Account'],
145
+ routing: [:string, 'Routing'],
146
+ check_format: [:string, 'CheckFormat'],
147
+ record_type: [:string, 'RecordType']
148
+ }
149
+ ].inject(:merge) #:nodoc
150
+
151
+ CUSTOMER_TRANSACTION_REQUEST_OPTIONS = {
152
+ command: [:string, 'Command'],
153
+ ignore_duplicate: [:boolean, 'IgnoreDuplicate'],
154
+ client_ip: [:string, 'ClientIP'],
155
+ customer_receipt: [:boolean, 'CustReceipt'],
156
+ customer_email: [:boolean, 'CustReceiptEmail'],
157
+ customer_template: [:boolean, 'CustReceiptName'],
158
+ merchant_receipt: [:boolean, 'MerchReceipt'],
159
+ merchant_email: [:boolean, 'MerchReceiptEmail'],
160
+ merchant_template: [:boolean, 'MerchReceiptName'],
161
+ recurring: [:boolean, 'isRecurring'],
162
+ verification_value: [:string, 'CardCode'],
163
+ software: [:string, 'Software']
164
+ } #:nodoc:
165
+
166
+ TRANSACTION_REQUEST_OBJECT_OPTIONS = {
167
+ command: [:string, 'Command'],
168
+ ignore_duplicate: [:boolean, 'IgnoreDuplicate'],
169
+ authorization_code: [:string, 'AuthCode'],
170
+ reference_number: [:string, 'RefNum'],
171
+ account_holder: [:string, 'AccountHolder'],
172
+ client_ip: [:string, 'ClientIP'],
173
+ customer_id: [:string, 'CustomerID'],
174
+ customer_receipt: [:boolean, 'CustReceipt'],
175
+ customer_template: [:boolean, 'CustReceiptName'],
176
+ software: [:string, 'Software']
177
+ } #:nodoc:
178
+
179
+ TRANSACTION_DETAIL_OPTIONS = {
180
+ invoice: [:string, 'Invoice'],
181
+ po_number: [:string, 'PONum'],
182
+ order_id: [:string, 'OrderID'],
183
+ clerk: [:string, 'Clerk'],
184
+ terminal: [:string, 'Terminal'],
185
+ table: [:string, 'Table'],
186
+ description: [:string, 'Description'],
187
+ comments: [:string, 'Comments'],
188
+ allow_partial_auth: [:boolean, 'AllowPartialAuth'],
189
+ currency: [:string, 'Currency'],
190
+ non_tax: [:boolean, 'NonTax']
191
+ } #:nodoc:
192
+
193
+ TRANSACTION_DETAIL_MONEY_OPTIONS = {
194
+ amount: [:double, 'Amount'],
195
+ tax: [:double, 'Tax'],
196
+ tip: [:double, 'Tip'],
197
+ non_tax: [:boolean, 'NonTax'],
198
+ shipping: [:double, 'Shipping'],
199
+ discount: [:double, 'Discount'],
200
+ subtotal: [:double, 'Subtotal']
201
+ } #:nodoc:
202
+
203
+ CREDIT_CARD_DATA_OPTIONS = {
204
+ magnetic_stripe: [:string, 'MagStripe'],
205
+ dukpt: [:string, 'DUKPT'],
206
+ signature: [:string, 'Signature'],
207
+ terminal_type: [:string, 'TermType'],
208
+ magnetic_support: [:string, 'MagSupport'],
209
+ xid: [:string, 'XID'],
210
+ cavv: [:string, 'CAVV'],
211
+ eci: [:integer, 'ECI'],
212
+ internal_card_authorization: [:boolean, 'InternalCardAuth'],
213
+ pares: [:string, 'Pares']
214
+ } #:nodoc:
215
+
216
+ CHECK_DATA_OPTIONS = {
217
+ drivers_license: [:string, 'DriversLicense'],
218
+ drivers_license_state: [:string, 'DriversLicenseState'],
219
+ record_type: [:string, 'RecordType'],
220
+ aux_on_us: [:string, 'AuxOnUS'],
221
+ epc_code: [:string, 'EpcCode'],
222
+ front_image: [:string, 'FrontImage'],
223
+ back_image: [:string, 'BackImage']
224
+ } #:nodoc:
225
+
226
+ RECURRING_BILLING_OPTIONS = {
227
+ schedule: [:string, 'Schedule'],
228
+ number_left: [:integer, 'NumLeft'],
229
+ enabled: [:boolean, 'Enabled']
230
+ } #:nodoc:
231
+
232
+ AVS_RESULTS = {
233
+ 'Y' => %w(YYY Y YYA YYD),
234
+ 'Z' => %w(NYZ Z),
235
+ 'A' => %w(YNA A YNY),
236
+ 'N' => %w(NNN N NN),
237
+ 'X' => %w(YYX X),
238
+ 'W' => %w(NYW W),
239
+ 'XXW' => %w(XXW),
240
+ 'XXU' => %w(XXU),
241
+ 'R' => %w(XXR R U E),
242
+ 'S' => %w(XXS S),
243
+ 'XXE' => %w(XXE),
244
+ 'G' => %w(XXG G C I),
245
+ 'B' => %w(YYG B M),
246
+ 'D' => %w(GGG D),
247
+ 'P' => %w(YGG P)
248
+ }.inject({}) do |map, (type, codes)|
249
+ codes.each { |code| map[code] = type }
250
+ map
251
+ end #:nodoc:
252
+
253
+ AVS_CUSTOM_MESSAGES = {
254
+ 'XXW' => 'Card number not on file.',
255
+ 'XXU' => 'Address information not verified for domestic transaction.',
256
+ 'XXE' => 'Address verification not allowed for card type.'
257
+ } #:nodoc:
258
+
259
+ # Create a new gateway.
260
+ #
261
+ # ==== Required
262
+ # * At least the live_url OR the software_id must be present.
263
+ # * <tt>:software_id</tt> -- 8 character software id
264
+ # OR
265
+ # * <tt>:test_url</tt> -- full url for testing
266
+ # * <tt>:live_url</tt> -- full url for live/production
267
+ #
268
+ # ==== Optional
269
+ # * <tt>:soap_response</tt> -- set to +true+ to add :soap_response to the params hash containing the entire soap xml message
270
+ #
271
+ def initialize(options = {})
272
+ requires!(options, :login, :password)
273
+
274
+ if options[:software_id]
275
+ self.live_url = "#{LIVE_URL_BASE}#{options[:software_id]}"
276
+ self.test_url = "#{TEST_URL_BASE}#{options[:software_id]}"
277
+ else
278
+ self.live_url = options[:live_url].to_s
279
+ self.test_url = options[:test_url].to_s if options[:test_url]
280
+ end
281
+
282
+ super
283
+ end
284
+
285
+ # Standard Gateway Methods ======================================
286
+
287
+ # Make a purchase with a credit card. (Authorize and
288
+ # capture for settlement.)
289
+ #
290
+ # Note: See run_transaction for additional options.
291
+ #
292
+ def purchase(money, creditcard, options = {})
293
+ run_sale(options.merge!(amount: money, payment_method: creditcard))
294
+ end
295
+
296
+ # Authorize an amount on a credit card or account.
297
+ #
298
+ # Note: See run_transaction for additional options.
299
+ #
300
+ def authorize(money, creditcard, options = {})
301
+ run_auth_only(options.merge!(amount: money, payment_method: creditcard))
302
+ end
303
+
304
+ # Capture an authorized transaction.
305
+ #
306
+ # Note: See run_transaction for additional options.
307
+ #
308
+ def capture(money, identification, options = {})
309
+ capture_transaction(options.merge!(amount: money, reference_number: identification))
310
+ end
311
+
312
+ # Void a previous transaction that has not been settled.
313
+ #
314
+ # Note: See run_transaction for additional options.
315
+ #
316
+ def void(identification, options = {})
317
+ void_transaction(options.merge!(reference_number: identification))
318
+ end
319
+
320
+ # Refund a previous transaction.
321
+ #
322
+ # Note: See run_transaction for additional options.
323
+ #
324
+ def refund(money, identification, options = {})
325
+ refund_transaction(options.merge!(amount: money, reference_number: identification))
326
+ end
327
+
328
+ def credit(money, identification, options = {})
329
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
330
+ refund(money, identification, options)
331
+ end
332
+
333
+ # Customer ======================================================
334
+
335
+ # Add a customer.
336
+ #
337
+ # ==== Options
338
+ # * <tt>:id</tt> -- merchant assigned id
339
+ # * <tt>:notes</tt> -- notes about customer
340
+ # * <tt>:data</tt> -- base64 data about customer
341
+ # * <tt>:url</tt> -- customer website
342
+ # * <tt>:billing_address</tt> -- usual options
343
+ # * <tt>:payment_methods</tt> -- array of payment method hashes.
344
+ # * <tt>:method</tt> -- credit_card or check
345
+ # * <tt>:name</tt> -- optional name/label for the method
346
+ # * <tt>:sort</tt> -- optional integer value specifying the backup sort order, 0 is default
347
+ #
348
+ # ==== Recurring Options
349
+ # * <tt>:enabled</tt> -- +true+ enables recurring
350
+ # * <tt>:schedule</tt> -- daily, weekly, bi-weekly (every two weeks), monthly, bi-monthly (every two months), quarterly, bi-annually (every six months), annually, first of month, last day of month
351
+ # * <tt>:number_left</tt> -- number of payments left; -1 for unlimited
352
+ # * <tt>:next</tt> -- date of next payment (Date/Time)
353
+ # * <tt>:amount</tt> -- amount of recurring payment
354
+ # * <tt>:tax</tt> -- tax portion of amount
355
+ # * <tt>:currency</tt> -- numeric currency code
356
+ # * <tt>:description</tt> -- description of transaction
357
+ # * <tt>:order_id</tt> -- transaction order id
358
+ # * <tt>:user</tt> -- merchant username assigned to transaction
359
+ # * <tt>:source</tt> -- name of source key assigned to billing
360
+ # * <tt>:send_receipt</tt> -- +true+ to send client a receipt
361
+ # * <tt>:receipt_note</tt> -- leave a note on the receipt
362
+ #
363
+ # ==== Point of Sale Options
364
+ # * <tt>:price_tier</tt> -- name of customer price tier
365
+ # * <tt>:tax_class</tt> -- tax class
366
+ # * <tt>:lookup_code</tt> -- lookup code from customer/member id card; barcode or magnetic stripe; can be assigned by merchant; defaults to system assigned if blank
367
+ #
368
+ # ==== Response
369
+ # * <tt>#message</tt> -- customer number assigned by gateway
370
+ #
371
+ def add_customer(options = {})
372
+ request = build_request(__method__, options)
373
+ commit(__method__, request)
374
+ end
375
+
376
+ # Update a customer by replacing all of the customer details.
377
+ #
378
+ # ==== Required
379
+ # * <tt>:customer_number</tt> -- customer to update
380
+ #
381
+ # ==== Options
382
+ # * Same as add_customer
383
+ #
384
+ def update_customer(options = {})
385
+ requires! options, :customer_number
386
+
387
+ request = build_request(__method__, options)
388
+ commit(__method__, request)
389
+ end
390
+
391
+ # Update a customer by replacing only the provided fields.
392
+ #
393
+ # ==== Required
394
+ # * <tt>:customer_number</tt> -- customer to update
395
+ # * <tt>:update_data</tt> -- FieldValue array of fields to retrieve
396
+ # * <tt>:first_name</tt>
397
+ # * <tt>:last_name</tt>
398
+ # * <tt>:id</tt>
399
+ # * <tt>:company</tt>
400
+ # * <tt>:address</tt>
401
+ # * <tt>:address2</tt>
402
+ # * <tt>:city</tt>
403
+ # * <tt>:state</tt>
404
+ # * <tt>:zip</tt>
405
+ # * <tt>:country</tt>
406
+ # * <tt>:phone</tt>
407
+ # * <tt>:fax</tt>
408
+ # * <tt>:email</tt>
409
+ # * <tt>:url</tt>
410
+ # * <tt>:receipt_note</tt>
411
+ # * <tt>:send_receipt</tt>
412
+ # * <tt>:notes</tt>
413
+ # * <tt>:description</tt>
414
+ # * <tt>:order_id</tt>
415
+ # * <tt>:enabled</tt>
416
+ # * <tt>:schedule</tt>
417
+ # * <tt>:next</tt>
418
+ # * <tt>:num_left</tt>
419
+ # * <tt>:amount</tt>
420
+ # * <tt>:custom_data</tt>
421
+ # * <tt>:source</tt>
422
+ # * <tt>:user</tt>
423
+ # * <tt>:card_number</tt>
424
+ # * <tt>:card_exp</tt>
425
+ # * <tt>:account</tt>
426
+ # * <tt>:routing</tt>
427
+ # * <tt>:check_format</tt> or <tt>:record_type</tt>
428
+ #
429
+ # ==== Response
430
+ # * <tt>#message</tt> -- boolean; Returns true if successful. Exception thrown all failures.
431
+ #
432
+ def quick_update_customer(options = {})
433
+ requires! options, :customer_number
434
+ requires! options, :update_data
435
+
436
+ request = build_request(__method__, options)
437
+ commit(__method__, request)
438
+ end
439
+
440
+ # Enable a customer for recurring billing.
441
+ #
442
+ # Note: Customer does not need to have all recurring parameters to succeed.
443
+ #
444
+ # ==== Required
445
+ # * <tt>:customer_number</tt>
446
+ #
447
+ def enable_customer(options = {})
448
+ requires! options, :customer_number
449
+
450
+ request = build_request(__method__, options)
451
+ commit(__method__, request)
452
+ end
453
+
454
+ # Disable a customer for recurring billing.
455
+ #
456
+ # ==== Required
457
+ # * <tt>:customer_number</tt>
458
+ #
459
+ def disable_customer(options = {})
460
+ requires! options, :customer_number
461
+
462
+ request = build_request(__method__, options)
463
+ commit(__method__, request)
464
+ end
465
+
466
+ # Add a payment method to a customer.
467
+ #
468
+ # ==== Required
469
+ # * <tt>:customer_number</tt> -- number returned by add_customer response.message
470
+ # * <tt>:payment_method</tt>
471
+ # * <tt>:method</tt> -- credit_card or check
472
+ # * <tt>:name</tt> -- optional name/label for the method
473
+ # * <tt>:sort</tt> -- an integer value specifying the backup sort order, 0 is default
474
+ #
475
+ # ==== Optional
476
+ # * <tt>:make_default</tt> -- set +true+ to make default
477
+ # * <tt>:verify</tt> -- set +true+ to run auth_only verification; throws fault if cannot verify
478
+ #
479
+ # ==== Response
480
+ # * <tt>#message</tt> -- method_id of new customer payment method
481
+ #
482
+ def add_customer_payment_method(options = {})
483
+ requires! options, :customer_number
484
+
485
+ request = build_request(__method__, options)
486
+ commit(__method__, request)
487
+ end
488
+
489
+ # Retrieve all of the payment methods belonging to a customer
490
+ #
491
+ # ==== Required
492
+ # * <tt>:customer_number</tt>
493
+ #
494
+ # ==== Response
495
+ # * <tt>#message</tt> -- either a single hash or an array of hashes of payment methods
496
+ #
497
+ def get_customer_payment_methods(options = {})
498
+ requires! options, :customer_number
499
+
500
+ request = build_request(__method__, options)
501
+ commit(__method__, request)
502
+ end
503
+
504
+ # Retrieve one of the payment methods belonging to a customer
505
+ #
506
+ # ==== Required
507
+ # * <tt>:customer_number</tt>
508
+ # * <tt>:method_id</tt>
509
+ #
510
+ # ==== Response
511
+ # * <tt>#message</tt> -- hash of payment method
512
+ #
513
+ def get_customer_payment_method(options = {})
514
+ requires! options, :customer_number, :method_id
515
+
516
+ request = build_request(__method__, options)
517
+ commit(__method__, request)
518
+ end
519
+
520
+ # Update a customer payment method.
521
+ #
522
+ # ==== Required
523
+ # * <tt>:method_id</tt> -- method_id to update
524
+ #
525
+ # ==== Options
526
+ # * <tt>:method</tt> -- credit_card or check
527
+ # * <tt>:name</tt> -- optional name/label for the method
528
+ # * <tt>:sort</tt> -- an integer value specifying the backup sort order, 0 is default
529
+ # * <tt>:verify</tt> -- set +true+ to run auth_only verification; throws fault if cannot verify
530
+ #
531
+ # ==== Response
532
+ # * <tt>#message</tt> -- hash of payment method
533
+ #
534
+ def update_customer_payment_method(options = {})
535
+ requires! options, :method_id
536
+
537
+ request = build_request(__method__, options)
538
+ commit(__method__, request)
539
+ end
540
+
541
+ # Delete one the payment methods belonging to a customer
542
+ #
543
+ # ==== Required
544
+ # * <tt>:customer_number</tt>
545
+ # * <tt>:method_id</tt>
546
+ #
547
+ def delete_customer_payment_method(options = {})
548
+ requires! options, :customer_number, :method_id
549
+
550
+ request = build_request(__method__, options)
551
+ commit(__method__, request)
552
+ end
553
+
554
+ # Delete a customer.
555
+ #
556
+ # ==== Required
557
+ # * <tt>:customer_number</tt>
558
+ #
559
+ def delete_customer(options = {})
560
+ requires! options, :customer_number
561
+
562
+ request = build_request(__method__, options)
563
+ commit(__method__, request)
564
+ end
565
+
566
+ # Run a transaction for an existing customer in the database.
567
+ #
568
+ # ==== Required Options
569
+ # * <tt>:customer_number</tt> -- gateway assigned identifier
570
+ # * <tt>:command</tt> -- Sale, AuthOnly, Credit, Check, CheckCredit
571
+ # * <tt>:amount</tt> -- total amount
572
+ #
573
+ # ==== Options
574
+ # * <tt>:method_id</tt> -- which payment method to use, 0/nil/omitted for default method
575
+ # * <tt>:ignore_duplicate</tt> -- +true+ overrides duplicate transaction
576
+ # * <tt>:client_ip</tt> -- client ip address
577
+ # * <tt>:customer_receipt</tt> -- +true+, sends receipt to customer. active_merchant defaults to +false+
578
+ # * <tt>:customer_email</tt> -- specify if different than customer record
579
+ # * <tt>:customer_template</tt> -- name of template
580
+ # * <tt>:merchant_receipt</tt> -- +true+, sends receipt to merchant. active_merchant defaults to +false+
581
+ # * <tt>:merchant_email</tt> -- required if :merchant_receipt set to +true+
582
+ # * <tt>:merchant_template</tt> -- name of template
583
+ # * <tt>:recurring</tt> -- defaults to +false+ *see documentation*
584
+ # * <tt>:verification_value</tt> -- pci forbids storage of this value, only required for CVV2 validation
585
+ # * <tt>:software</tt> -- active_merchant sets to required gateway option value
586
+ # * <tt>:line_items</tt> -- XXX not implemented yet
587
+ # * <tt>:custom_fields</tt> -- XXX not implemented yet
588
+ #
589
+ # ==== Transaction Options
590
+ # * <tt>:invoice</tt> -- transaction invoice number; truncated to 10 characters; defaults to reference_number
591
+ # * <tt>:po_number</tt> -- commercial purchase order number; upto 25 characters
592
+ # * <tt>:order_id</tt> -- should be used to assign a unique id; upto 64 characters
593
+ # * <tt>:clerk</tt> -- sales clerk
594
+ # * <tt>:terminal</tt> -- terminal name
595
+ # * <tt>:table</tt> -- table name/number
596
+ # * <tt>:description</tt> -- description
597
+ # * <tt>:comments</tt> -- comments
598
+ # * <tt>:allow_partial_auth</tt> -- allow partial authorization if full amount is not available; defaults +false+
599
+ # * <tt>:currency</tt> -- numeric currency code
600
+ # * <tt>:tax</tt> -- tax portion of amount
601
+ # * <tt>:tip</tt> -- tip portion of amount
602
+ # * <tt>:non_tax</tt> -- +true+ if transaction is non-taxable
603
+ # * <tt>:shipping</tt> -- shipping portion of amount
604
+ # * <tt>:discount</tt> -- amount of discount
605
+ # * <tt>:subtotal</tt> -- amount of transaction before tax, tip, shipping, and discount are applied
606
+ #
607
+ # ==== Response
608
+ # * <tt>#message</tt> -- transaction response hash
609
+ #
610
+ def run_customer_transaction(options = {})
611
+ requires! options, :customer_number, :command, :amount
612
+
613
+ request = build_request(__method__, options)
614
+ commit(__method__, request)
615
+ end
616
+
617
+ # Transactions ==================================================
618
+
619
+ # Run a transaction.
620
+ #
621
+ # Note: run_sale, run_auth_only, run_credit, run_check_sale, run_check_credit
622
+ # methods are also available. Each takes the same options as
623
+ # run_transaction, but the :command option is not required.
624
+ #
625
+ # Recurring Note: If recurring options are included USA ePay will create a
626
+ # new customer record with the supplied information. The customer number
627
+ # will be returned in the response.
628
+ #
629
+ # ==== Options
630
+ # * <tt>:payment_method</tt> -- credit_card or check
631
+ # * <tt>:command</tt> -- sale, credit, void, creditvoid, authonly, capture, postauth, check, checkcredit; defaults to sale; only required for run_transaction when other than sale
632
+ # * <tt>:reference_number</tt> -- for the original transaction; obtained by sale or authonly
633
+ # * <tt>:authorization_code</tt> -- required for postauth; obtained offline
634
+ # * <tt>:ignore_duplicate</tt> -- set +true+ if you want to override the duplicate transaction handling
635
+ # * <tt>:account_holder</tt> -- name of account holder
636
+ # * <tt>:customer_id</tt> -- merchant assigned id
637
+ # * <tt>:customer_receipt</tt> -- set +true+ to email receipt to billing email address
638
+ # * <tt>:customer_template</tt> -- name of template
639
+ # * <tt>:software</tt> -- stamp merchant software version for tracking
640
+ # * <tt>:billing_address</tt> -- see UsaEpayCimGateway documentation for all address fields
641
+ # * <tt>:shipping_address</tt> -- see UsaEpayCimGateway documentation for all address fields
642
+ # * <tt>:recurring</tt> -- used for recurring billing transactions
643
+ # * <tt>:schedule</tt> -- disabled, daily, weekly, bi-weekly (every two weeks), monthly, bi-monthly (every two months), quarterly, bi-annually (every six months), annually
644
+ # * <tt>:next</tt> -- date customer billed next (Date/Time)
645
+ # * <tt>:expire</tt> -- date the recurring transactions end (Date/Time)
646
+ # * <tt>:number_left</tt> -- transactions remaining in billing cycle
647
+ # * <tt>:amount</tt> -- amount to be billed each recurring transaction
648
+ # * <tt>:enabled</tt> -- states if currently active
649
+ # * <tt>:line_items</tt> -- XXX not implemented yet
650
+ # * <tt>:custom_fields</tt> -- XXX not implemented yet
651
+ #
652
+ # ==== Transaction Options
653
+ # * <tt>:amount</tt> -- total amount
654
+ # * <tt>:invoice</tt> -- transaction invoice number; truncated to 10 characters; defaults to reference_number
655
+ # * <tt>:po_number</tt> -- commercial purchase order number; upto 25 characters
656
+ # * <tt>:order_id</tt> -- should be used to assign a unique id; upto 64 characters
657
+ # * <tt>:clerk</tt> -- sales clerk
658
+ # * <tt>:terminal</tt> -- terminal name
659
+ # * <tt>:table</tt> -- table name/number
660
+ # * <tt>:description</tt> -- description
661
+ # * <tt>:comments</tt> -- comments
662
+ # * <tt>:allow_partial_auth</tt> -- allow partial authorization if full amount is not available; defaults +false+
663
+ # * <tt>:currency</tt> -- numeric currency code
664
+ # * <tt>:tax</tt> -- tax portion of amount
665
+ # * <tt>:tip</tt> -- tip portion of amount
666
+ # * <tt>:non_tax</tt> -- +true+ if transaction is non-taxable
667
+ # * <tt>:shipping</tt> -- shipping portion of amount
668
+ # * <tt>:discount</tt> -- amount of discount
669
+ # * <tt>:subtotal</tt> -- amount of transaction before tax, tip, shipping, and discount are applied
670
+ #
671
+ # ==== Response
672
+ # * <tt>#message</tt> -- transaction response hash
673
+ #
674
+ def run_transaction(options = {})
675
+ request = build_request(__method__, options)
676
+ commit(__method__, request)
677
+ end
678
+
679
+ TRANSACTION_METHODS = %i[
680
+ run_sale run_auth_only run_credit
681
+ run_check_sale run_check_credit
682
+ ] #:nodoc:
683
+
684
+ TRANSACTION_METHODS.each do |method|
685
+ define_method method do |options|
686
+ request = build_request(method, options)
687
+ commit(method, request)
688
+ end
689
+ end
690
+
691
+ # Post an authorization code obtained offline.
692
+ #
693
+ # ==== Required
694
+ # * <tt>:authorization_code</tt> -- obtained offline
695
+ #
696
+ # ==== Options
697
+ # * Same as run_transaction
698
+ #
699
+ # ==== Response
700
+ # * <tt>#message</tt> -- transaction response hash
701
+ #
702
+ def post_auth(options = {})
703
+ requires! options, :authorization_code
704
+
705
+ request = build_request(__method__, options)
706
+ commit(__method__, request)
707
+ end
708
+
709
+ # Capture an authorized transaction and move it into the current batch
710
+ # for settlement.
711
+ #
712
+ # Note: Check with merchant bank for details/restrictions on differing
713
+ # amounts than the original authorization.
714
+ #
715
+ # ==== Required
716
+ # * <tt>:reference_number</tt>
717
+ #
718
+ # ==== Options
719
+ # * <tt>:amount</tt> -- may be different than original amount; 0 will void authorization
720
+ #
721
+ # ==== Response
722
+ # * <tt>#message</tt> -- transaction response hash
723
+ #
724
+ def capture_transaction(options = {})
725
+ requires! options, :reference_number
726
+
727
+ request = build_request(__method__, options)
728
+ commit(__method__, request)
729
+ end
730
+
731
+ # Void a transaction.
732
+ #
733
+ # Note: Can only be voided before being settled.
734
+ #
735
+ # ==== Required
736
+ # * <tt>:reference_number</tt>
737
+ #
738
+ # ==== Response
739
+ # * <tt>#message</tt> -- transaction response hash
740
+ #
741
+ def void_transaction(options = {})
742
+ requires! options, :reference_number
743
+
744
+ request = build_request(__method__, options)
745
+ commit(__method__, request)
746
+ end
747
+
748
+ # Refund transaction.
749
+ #
750
+ # Note: Required after a transaction has been settled. Refunds
751
+ # both credit card and check transactions.
752
+ #
753
+ # ==== Required
754
+ # * <tt>:reference_number</tt>
755
+ # * <tt>:amount</tt> -- amount to refund; 0 will refund original amount
756
+ #
757
+ # ==== Response
758
+ # * <tt>#message</tt> -- transaction response hash
759
+ #
760
+ def refund_transaction(options = {})
761
+ requires! options, :reference_number, :amount
762
+
763
+ request = build_request(__method__, options)
764
+ commit(__method__, request)
765
+ end
766
+
767
+ # Override transaction flagged for manager approval.
768
+ #
769
+ # Note: Checks only!
770
+ #
771
+ # ==== Required
772
+ # * <tt>:reference_number</tt>
773
+ #
774
+ # ==== Options
775
+ # * <tt>:reason</tt>
776
+ #
777
+ # ==== Response
778
+ # * <tt>#message</tt> -- transaction response hash
779
+ #
780
+ def override_transaction(options = {})
781
+ requires! options, :reference_number
782
+
783
+ request = build_request(__method__, options)
784
+ commit(__method__, request)
785
+ end
786
+
787
+ # Quick Transactions ============================================
788
+
789
+ # Run a sale transaction based off of a past transaction.
790
+ #
791
+ # Transfers referenced transaction's payment method to this
792
+ # transaction. As of 6/2011, USA ePay blocks credit card numbers
793
+ # at 3 years.
794
+ #
795
+ # ==== Required
796
+ # * <tt>:reference_number</tt> -- transaction to reference payment from
797
+ # * <tt>:amount</tt> -- total amount
798
+ #
799
+ # ==== Options
800
+ # * <tt>:authorize_only</tt> -- set +true+ if you just want to authorize
801
+ #
802
+ # ==== Transaction Options
803
+ # * <tt>:invoice</tt> -- transaction invoice number; truncated to 10 characters; defaults to reference_number
804
+ # * <tt>:po_number</tt> -- commercial purchase order number; upto 25 characters
805
+ # * <tt>:order_id</tt> -- should be used to assign a unique id; upto 64 characters
806
+ # * <tt>:clerk</tt> -- sales clerk
807
+ # * <tt>:terminal</tt> -- terminal name
808
+ # * <tt>:table</tt> -- table name/number
809
+ # * <tt>:description</tt> -- description
810
+ # * <tt>:comments</tt> -- comments
811
+ # * <tt>:allow_partial_auth</tt> -- allow partial authorization if full amount is not available; defaults +false+
812
+ # * <tt>:currency</tt> -- numeric currency code
813
+ # * <tt>:tax</tt> -- tax portion of amount
814
+ # * <tt>:tip</tt> -- tip portion of amount
815
+ # * <tt>:non_tax</tt> -- +true+ if transaction is non-taxable
816
+ # * <tt>:shipping</tt> -- shipping portion of amount
817
+ # * <tt>:discount</tt> -- amount of discount
818
+ # * <tt>:subtotal</tt> -- amount of transaction before tax, tip, shipping, and discount are applied
819
+ #
820
+ # ==== Response
821
+ # * <tt>#message</tt> -- transaction response hash
822
+ #
823
+ def run_quick_sale(options = {})
824
+ requires! options, :reference_number, :amount
825
+
826
+ request = build_request(__method__, options)
827
+ commit(__method__, request)
828
+ end
829
+
830
+ # Run a credit based off of a past transaction.
831
+ #
832
+ # Transfers referenced transaction's payment method to this
833
+ # transaction. As of 6/2011, USA ePay blocks credit card numbers
834
+ # at 3 years.
835
+ #
836
+ # ==== Required
837
+ # * <tt>:reference_number</tt> -- transaction to reference payment from
838
+ #
839
+ # ==== Transaction Options
840
+ # * <tt>:amount</tt> -- total amount
841
+ # * <tt>:invoice</tt> -- transaction invoice number; truncated to 10 characters; defaults to reference_number
842
+ # * <tt>:po_number</tt> -- commercial purchase order number; upto 25 characters
843
+ # * <tt>:order_id</tt> -- should be used to assign a unique id; upto 64 characters
844
+ # * <tt>:clerk</tt> -- sales clerk
845
+ # * <tt>:terminal</tt> -- terminal name
846
+ # * <tt>:table</tt> -- table name/number
847
+ # * <tt>:description</tt> -- description
848
+ # * <tt>:comments</tt> -- comments
849
+ # * <tt>:allow_partial_auth</tt> -- allow partial authorization if full amount is not available; defaults +false+
850
+ # * <tt>:currency</tt> -- numeric currency code
851
+ # * <tt>:tax</tt> -- tax portion of amount
852
+ # * <tt>:tip</tt> -- tip portion of amount
853
+ # * <tt>:non_tax</tt> -- +true+ if transaction is non-taxable
854
+ # * <tt>:shipping</tt> -- shipping portion of amount
855
+ # * <tt>:discount</tt> -- amount of discount
856
+ # * <tt>:subtotal</tt> -- amount of transaction before tax, tip, shipping, and discount are applied
857
+ #
858
+ # ==== Response
859
+ # * <tt>#message</tt> -- transaction response hash
860
+ #
861
+ def run_quick_credit(options = {})
862
+ requires! options, :reference_number
863
+
864
+ request = build_request(__method__, options)
865
+ commit(__method__, request)
866
+ end
867
+
868
+ # Transaction Status ============================================
869
+
870
+ # Retrieve details of a specified transaction.
871
+ #
872
+ # ==== Required
873
+ # * <tt>:reference_number</tt>
874
+ #
875
+ # ==== Response
876
+ # * <tt>#message</tt> -- transaction hash
877
+ #
878
+ def get_transaction(options = {})
879
+ requires! options, :reference_number
880
+
881
+ request = build_request(__method__, options)
882
+ commit(__method__, request)
883
+ end
884
+
885
+ # Check status of a transaction.
886
+ #
887
+ # ==== Required
888
+ # * <tt>:reference_number</tt>
889
+ #
890
+ # ==== Response
891
+ # * <tt>response.success</tt> -- success of the referenced transaction
892
+ # * <tt>response.message</tt> -- message of the referenced transaction
893
+ # * <tt>response.authorization</tt> -- same as :reference_number in options
894
+ #
895
+ def get_transaction_status(options = {})
896
+ requires! options, :reference_number
897
+
898
+ request = build_request(__method__, options)
899
+ commit(__method__, request)
900
+ end
901
+
902
+ # Check status of a transaction (custom).
903
+ #
904
+ # ==== Required
905
+ # * <tt>:reference_number</tt>
906
+ # * <tt>:fields</tt> -- string array of fields to retrieve
907
+ # * <tt>Response.AuthCode</tt>
908
+ # * <tt>Response.AvsResult</tt>
909
+ # * <tt>Response.AvsResultCode</tt>
910
+ # * <tt>Response.BatchNum</tt>
911
+ # * <tt>Response.CardCodeResult</tt>
912
+ # * <tt>Response.CardCodeResultCode</tt>
913
+ # * <tt>Response.ConversionRate</tt>
914
+ # * <tt>Response.ConvertedAmount</tt>
915
+ # * <tt>Response.ConvertedAmountCurrency</tt>
916
+ # * <tt>Response.Error</tt>
917
+ # * <tt>Response.ErrorCode</tt>
918
+ # * <tt>Response.RefNum</tt>
919
+ # * <tt>Response.Result</tt>
920
+ # * <tt>Response.ResultCode</tt>
921
+ # * <tt>Response.Status</tt>
922
+ # * <tt>Response.StatusCode</tt>
923
+ # * <tt>CheckTrace.TrackingNum</tt>
924
+ # * <tt>CheckTrace.Effective</tt>
925
+ # * <tt>CheckTrace.Processed</tt>
926
+ # * <tt>CheckTrace.Settled</tt>
927
+ # * <tt>CheckTrace.Returned</tt>
928
+ # * <tt>CheckTrace.BankNote</tt>
929
+ # * <tt>DateTime</tt>
930
+ # * <tt>AccountHolder</tt>
931
+ # * <tt>Details.Invoice</tt>
932
+ # * <tt>Details.PoNum</tt>
933
+ # * <tt>Details.OrderID</tt>
934
+ # * <tt>Details.Clerk</tt>
935
+ # * <tt>Details.Terminal</tt>
936
+ # * <tt>Details.Table</tt>
937
+ # * <tt>Details.Description</tt>
938
+ # * <tt>Details.Amount</tt>
939
+ # * <tt>Details.Currency</tt>
940
+ # * <tt>Details.Tax</tt>
941
+ # * <tt>Details.Tip</tt>
942
+ # * <tt>Details.NonTax</tt>
943
+ # * <tt>Details.Shipping</tt>
944
+ # * <tt>Details.Discount</tt>
945
+ # * <tt>Details.Subtotal</tt>
946
+ # * <tt>CreditCardData.CardType</tt>
947
+ # * <tt>CreditCardData.CardNumber</tt>
948
+ # * <tt>CreditCardData.CardExpiration</tt>
949
+ # * <tt>CreditCardData.CardCode</tt>
950
+ # * <tt>CreditCardData.AvsStreet</tt>
951
+ # * <tt>CreditCardData.AvsZip</tt>
952
+ # * <tt>CreditCardData.CardPresent</tt>
953
+ # * <tt>CheckData.CheckNumber</tt>
954
+ # * <tt>CheckData.Routing</tt>
955
+ # * <tt>CheckData.Account</tt>
956
+ # * <tt>CheckData.SSN</tt>
957
+ # * <tt>CheckData.DriversLicense</tt>
958
+ # * <tt>CheckData.DriversLicenseState</tt>
959
+ # * <tt>CheckData.RecordType</tt>
960
+ # * <tt>User</tt>
961
+ # * <tt>Source</tt>
962
+ # * <tt>ServerIP</tt>
963
+ # * <tt>ClientIP</tt>
964
+ # * <tt>CustomerID</tt>
965
+ # * <tt>BillingAddress.FirstName</tt>
966
+ # * <tt>BillingAddress.LastName</tt>
967
+ # * <tt>BillingAddress.Company</tt>
968
+ # * <tt>BillingAddress.Street</tt>
969
+ # * <tt>BillingAddress.Street2</tt>
970
+ # * <tt>BillingAddress.City</tt>
971
+ # * <tt>BillingAddress.State</tt>
972
+ # * <tt>BillingAddress.Zip</tt>
973
+ # * <tt>BillingAddress.Country</tt>
974
+ # * <tt>BillingAddress.Phone</tt>
975
+ # * <tt>BillingAddress.Fax</tt>
976
+ # * <tt>BillingAddress.Email</tt>
977
+ # * <tt>ShippingAddress.FirstName</tt>
978
+ # * <tt>ShippingAddress.LastName</tt>
979
+ # * <tt>ShippingAddress.Company</tt>
980
+ # * <tt>ShippingAddress.Street</tt>
981
+ # * <tt>ShippingAddress.Street2</tt>
982
+ # * <tt>ShippingAddress.City</tt>
983
+ # * <tt>ShippingAddress.State</tt>
984
+ # * <tt>ShippingAddress.Zip</tt>
985
+ # * <tt>ShippingAddress.Country</tt>
986
+ # * <tt>ShippingAddress.Phone</tt>
987
+ # * <tt>ShippingAddress.Fax</tt>
988
+ # * <tt>ShippingAddress.Email</tt>
989
+ #
990
+ # ==== Response
991
+ # * <tt>#message</tt> -- hash; keys are the field values
992
+ #
993
+ def get_transaction_custom(options = {})
994
+ requires! options, :reference_number, :fields
995
+
996
+ request = build_request(__method__, options)
997
+ commit(__method__, request)
998
+ end
999
+
1000
+ # Check status of a check transaction.
1001
+ #
1002
+ # ==== Required
1003
+ # * <tt>:reference_number</tt>
1004
+ #
1005
+ # ==== Response
1006
+ # * <tt>#message</tt> -- check trace hash
1007
+ #
1008
+ def get_check_trace(options = {})
1009
+ requires! options, :reference_number
1010
+
1011
+ request = build_request(__method__, options)
1012
+ commit(__method__, request)
1013
+ end
1014
+
1015
+ # Account =======================================================
1016
+
1017
+ # Retrieve merchant account details
1018
+ #
1019
+ # ==== Response
1020
+ # * <tt>#message</tt> -- account hash
1021
+ #
1022
+ def get_account_details
1023
+ request = build_request(__method__)
1024
+ commit(__method__, request)
1025
+ end
1026
+
1027
+ # Builders ======================================================
1028
+
1029
+ private
1030
+
1031
+ # Build soap header, etc.
1032
+ def build_request(action, options = {})
1033
+ soap = Builder::XmlMarkup.new
1034
+ soap.instruct!(:xml, version: '1.0', encoding: 'utf-8')
1035
+ soap.tag! 'SOAP-ENV:Envelope',
1036
+ 'xmlns:SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
1037
+ 'xmlns:ns1' => 'urn:usaepay',
1038
+ 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
1039
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
1040
+ 'xmlns:SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/',
1041
+ 'SOAP-ENV:encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/' do
1042
+ soap.tag! 'SOAP-ENV:Body' do
1043
+ send("build_#{action}", soap, options)
1044
+ end
1045
+ end
1046
+ soap.target!
1047
+ end
1048
+
1049
+ # Build generic tag.
1050
+ def build_tag(soap, type, tag, value)
1051
+ soap.tag!(tag, value, 'xsi:type' => "xsd:#{type}") if value != nil
1052
+ end
1053
+
1054
+ # Build token.
1055
+ def build_token(soap, options)
1056
+ seed = SecureRandom.base64(32)
1057
+ hash = Digest::SHA1.hexdigest("#{@options[:login]}#{seed}#{@options[:password].to_s.strip}")
1058
+ soap.Token 'xsi:type' => 'ns1:ueSecurityToken' do
1059
+ build_tag soap, :string, 'ClientIP', options[:client_ip]
1060
+ soap.PinHash 'xsi:type' => 'ns1:ueHash' do
1061
+ build_tag soap, :string, 'HashValue', hash
1062
+ build_tag soap, :string, 'Seed', seed
1063
+ build_tag soap, :string, 'Type', 'sha1'
1064
+ end
1065
+ build_tag soap, :string, 'SourceKey', @options[:login]
1066
+ end
1067
+ end
1068
+
1069
+ # Customer ======================================================
1070
+
1071
+ def build_add_customer(soap, options)
1072
+ soap.tag! 'ns1:addCustomer' do
1073
+ build_token soap, options
1074
+ build_customer_data soap, options
1075
+ build_tag soap, :double, 'Amount', amount(options[:amount])
1076
+ build_tag soap, :double, 'Tax', amount(options[:tax])
1077
+ build_tag soap, :string, 'Next', options[:next].strftime('%Y-%m-%d') if options[:next]
1078
+ end
1079
+ end
1080
+
1081
+ def build_customer(soap, options, type, add_customer_data = false)
1082
+ soap.tag! "ns1:#{type}" do
1083
+ build_token soap, options
1084
+ build_tag soap, :integer, 'CustNum', options[:customer_number]
1085
+ build_customer_data soap, options if add_customer_data
1086
+ end
1087
+ end
1088
+
1089
+ def build_update_customer(soap, options)
1090
+ build_customer(soap, options, 'updateCustomer', true)
1091
+ end
1092
+
1093
+ def build_enable_customer(soap, options)
1094
+ build_customer(soap, options, 'enableCustomer')
1095
+ end
1096
+
1097
+ def build_disable_customer(soap, options)
1098
+ build_customer(soap, options, 'disableCustomer')
1099
+ end
1100
+
1101
+ def build_delete_customer(soap, options)
1102
+ build_customer(soap, options, 'deleteCustomer')
1103
+ end
1104
+
1105
+ def build_quick_update_customer(soap, options)
1106
+ soap.tag! 'ns1:quickUpdateCustomer' do
1107
+ build_token soap, options
1108
+ build_tag soap, :integer, 'CustNum', options[:customer_number]
1109
+ build_field_value_array soap, 'UpdateData', 'FieldValue', options[:update_data], CUSTOMER_UPDATE_DATA_FIELDS
1110
+ end
1111
+ end
1112
+
1113
+ def build_add_customer_payment_method(soap, options)
1114
+ soap.tag! 'ns1:addCustomerPaymentMethod' do
1115
+ build_token soap, options
1116
+ build_tag soap, :integer, 'CustNum', options[:customer_number]
1117
+ build_customer_payment_methods soap, options
1118
+ build_tag soap, :boolean, 'MakeDefault', options[:make_default]
1119
+ build_tag soap, :boolean, 'Verify', options[:verify]
1120
+ end
1121
+ end
1122
+
1123
+ def build_get_customer_payment_method(soap, options)
1124
+ soap.tag! 'ns1:getCustomerPaymentMethod' do
1125
+ build_token soap, options
1126
+ build_tag soap, :integer, 'CustNum', options[:customer_number]
1127
+ build_tag soap, :integer, 'MethodID', options[:method_id]
1128
+ end
1129
+ end
1130
+
1131
+ def build_get_customer_payment_methods(soap, options)
1132
+ build_customer(soap, options, 'getCustomerPaymentMethods')
1133
+ end
1134
+
1135
+ def build_update_customer_payment_method(soap, options)
1136
+ soap.tag! 'ns1:updateCustomerPaymentMethod' do
1137
+ build_token soap, options
1138
+ build_customer_payment_methods soap, options
1139
+ build_tag soap, :boolean, 'Verify', options[:verify]
1140
+ end
1141
+ end
1142
+
1143
+ def build_delete_customer_payment_method(soap, options)
1144
+ soap.tag! 'ns1:deleteCustomerPaymentMethod' do
1145
+ build_token soap, options
1146
+ build_tag soap, :integer, 'Custnum', options[:customer_number]
1147
+ build_tag soap, :integer, 'PaymentMethodID', options[:method_id]
1148
+ end
1149
+ end
1150
+
1151
+ def build_run_customer_transaction(soap, options)
1152
+ soap.tag! 'ns1:runCustomerTransaction' do
1153
+ build_token soap, options
1154
+ build_tag soap, :integer, 'CustNum', options[:customer_number]
1155
+ build_tag soap, :integer, 'PaymentMethodID', options[:method_id] || 0
1156
+ build_customer_transaction soap, options
1157
+ end
1158
+ end
1159
+
1160
+ # Transactions ==================================================
1161
+
1162
+ def build_run_transaction(soap, options)
1163
+ soap.tag! 'ns1:runTransaction' do
1164
+ build_token soap, options
1165
+ build_transaction_request_object soap, options, 'Parameters'
1166
+ end
1167
+ end
1168
+
1169
+ def build_run_sale(soap, options)
1170
+ soap.tag! 'ns1:runSale' do
1171
+ build_token soap, options
1172
+ build_transaction_request_object soap, options
1173
+ end
1174
+ end
1175
+
1176
+ def build_run_auth_only(soap, options)
1177
+ soap.tag! 'ns1:runAuthOnly' do
1178
+ build_token soap, options
1179
+ build_transaction_request_object soap, options
1180
+ end
1181
+ end
1182
+
1183
+ def build_run_credit(soap, options)
1184
+ soap.tag! 'ns1:runCredit' do
1185
+ build_token soap, options
1186
+ build_transaction_request_object soap, options
1187
+ end
1188
+ end
1189
+
1190
+ def build_run_check_sale(soap, options)
1191
+ soap.tag! 'ns1:runCheckSale' do
1192
+ build_token soap, options
1193
+ build_transaction_request_object soap, options
1194
+ end
1195
+ end
1196
+
1197
+ def build_run_check_credit(soap, options)
1198
+ soap.tag! 'ns1:runCheckCredit' do
1199
+ build_token soap, options
1200
+ build_transaction_request_object soap, options
1201
+ end
1202
+ end
1203
+
1204
+ def build_post_auth(soap, options)
1205
+ soap.tag! 'ns1:postAuth' do
1206
+ build_token soap, options
1207
+ build_transaction_request_object soap, options
1208
+ end
1209
+ end
1210
+
1211
+ def build_run_quick_sale(soap, options)
1212
+ soap.tag! 'ns1:runQuickSale' do
1213
+ build_token soap, options
1214
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1215
+ build_transaction_detail soap, options
1216
+ build_tag soap, :boolean, 'AuthOnly', options[:authorize_only] || false
1217
+ end
1218
+ end
1219
+
1220
+ def build_run_quick_credit(soap, options)
1221
+ soap.tag! 'ns1:runQuickCredit' do
1222
+ build_token soap, options
1223
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1224
+ build_transaction_detail soap, options
1225
+ end
1226
+ end
1227
+
1228
+ def build_get_transaction(soap, options)
1229
+ soap.tag! 'ns1:getTransaction' do
1230
+ build_token soap, options
1231
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1232
+ end
1233
+ end
1234
+
1235
+ def build_get_transaction_status(soap, options)
1236
+ soap.tag! 'ns1:getTransactionStatus' do
1237
+ build_token soap, options
1238
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1239
+ end
1240
+ end
1241
+
1242
+ def build_get_transaction_custom(soap, options)
1243
+ soap.tag! 'ns1:getTransactionCustom' do
1244
+ build_token soap, options
1245
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1246
+ build_transaction_field_array soap, options
1247
+ end
1248
+ end
1249
+
1250
+ def build_get_check_trace(soap, options)
1251
+ soap.tag! 'ns1:getCheckTrace' do
1252
+ build_token soap, options
1253
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1254
+ end
1255
+ end
1256
+
1257
+ def build_capture_transaction(soap, options)
1258
+ soap.tag! 'ns1:captureTransaction' do
1259
+ build_token soap, options
1260
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1261
+ build_tag soap, :double, 'Amount', amount(options[:amount])
1262
+ end
1263
+ end
1264
+
1265
+ def build_void_transaction(soap, options)
1266
+ soap.tag! 'ns1:voidTransaction' do
1267
+ build_token soap, options
1268
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1269
+ end
1270
+ end
1271
+
1272
+ def build_refund_transaction(soap, options)
1273
+ soap.tag! 'ns1:refundTransaction' do
1274
+ build_token soap, options
1275
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1276
+ build_tag soap, :integer, 'Amount', amount(options[:amount])
1277
+ end
1278
+ end
1279
+
1280
+ def build_override_transaction(soap, options)
1281
+ soap.tag! 'ns1:overrideTransaction' do
1282
+ build_token soap, options
1283
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1284
+ build_tag soap, :string, 'Reason', options[:reason]
1285
+ end
1286
+ end
1287
+
1288
+ # Account =======================================================
1289
+
1290
+ def build_get_account_details(soap, options)
1291
+ soap.tag! 'ns1:getAccountDetails' do
1292
+ build_token soap, options
1293
+ end
1294
+ end
1295
+
1296
+ # Customer Helpers ==============================================
1297
+
1298
+ def build_customer_data(soap, options)
1299
+ soap.CustomerData 'xsi:type' => 'ns1:CustomerObject' do
1300
+ CUSTOMER_OPTIONS.each do |k, v|
1301
+ build_tag soap, v[0], v[1], options[k]
1302
+ end
1303
+ build_billing_address soap, options
1304
+ build_customer_payments soap, options
1305
+ build_custom_fields soap, options
1306
+ end
1307
+ end
1308
+
1309
+ def build_customer_payments(soap, options)
1310
+ if options[:payment_methods]
1311
+ length = options[:payment_methods].length
1312
+ soap.PaymentMethods 'SOAP-ENC:arrayType' => "ns1:PaymentMethod[#{length}]",
1313
+ 'xsi:type' => 'ns1:PaymentMethodArray' do
1314
+ build_customer_payment_methods soap, options
1315
+ end
1316
+ end
1317
+ end
1318
+
1319
+ def extract_methods_and_tag(options)
1320
+ case
1321
+ when options[:payment_method] && !options[:payment_methods]
1322
+ payment_methods = [options[:payment_method]]
1323
+ tag_name = 'PaymentMethod'
1324
+ when options[:payment_methods] && !options[:payment_method]
1325
+ payment_methods = options[:payment_methods]
1326
+ tag_name = 'item'
1327
+ else
1328
+ payment_methods = [options]
1329
+ tag_name = 'PaymentMethod'
1330
+ end
1331
+ [payment_methods, tag_name]
1332
+ end
1333
+
1334
+ def build_credit_card_or_check(soap, payment_method)
1335
+ case
1336
+ when payment_method[:method].kind_of?(ActiveMerchant::Billing::CreditCard)
1337
+ build_tag soap, :string, 'CardNumber', payment_method[:method].number
1338
+ build_tag soap, :string, 'CardExpiration',
1339
+ "#{'%02d' % payment_method[:method].month}#{payment_method[:method].year.to_s[-2..-1]}"
1340
+ if options[:billing_address]
1341
+ build_tag soap, :string, 'AvsStreet', options[:billing_address][:address1]
1342
+ build_tag soap, :string, 'AvsZip', options[:billing_address][:zip]
1343
+ end
1344
+ build_tag soap, :string, 'CardCode', payment_method[:method].verification_value
1345
+ when payment_method[:method].kind_of?(ActiveMerchant::Billing::Check)
1346
+ build_tag soap, :string, 'Account', payment_method[:method].account_number
1347
+ build_tag soap, :string, 'Routing', payment_method[:method].routing_number
1348
+ build_tag soap, :string, 'AccountType', payment_method[:method].account_type.capitalize unless payment_method[:method].account_type.nil?
1349
+ build_tag soap, :string, 'DriversLicense', options[:drivers_license]
1350
+ build_tag soap, :string, 'DriversLicenseState', options[:drivers_license_state]
1351
+ build_tag soap, :string, 'RecordType', options[:record_type]
1352
+ end
1353
+ end
1354
+
1355
+ def build_customer_payment_methods(soap, options)
1356
+ payment_methods, tag_name = extract_methods_and_tag(options)
1357
+ payment_methods.each do |payment_method|
1358
+ soap.tag! tag_name, 'xsi:type' => 'ns1:PaymentMethod' do
1359
+ build_tag soap, :integer, 'MethodID', payment_method[:method_id]
1360
+ build_tag soap, :string, 'MethodType', payment_method[:type]
1361
+ build_tag soap, :string, 'MethodName', payment_method[:name]
1362
+ build_tag soap, :integer, 'SecondarySort', payment_method[:sort]
1363
+ build_credit_card_or_check(soap, payment_method)
1364
+ end
1365
+ end
1366
+ end
1367
+
1368
+ def build_customer_transaction(soap, options)
1369
+ soap.Parameters 'xsi:type' => 'ns1:CustomerTransactionRequest' do
1370
+ build_transaction_detail soap, options
1371
+ CUSTOMER_TRANSACTION_REQUEST_OPTIONS.each do |k, v|
1372
+ build_tag soap, v[0], v[1], options[k]
1373
+ end
1374
+ build_custom_fields soap, options
1375
+ build_line_items soap, options
1376
+ end
1377
+ end
1378
+
1379
+ # Transaction Helpers ===========================================
1380
+
1381
+ def build_transaction_request_object(soap, options, name = 'Params')
1382
+ soap.tag! name, 'xsi:type' => 'ns1:TransactionRequestObject' do
1383
+ TRANSACTION_REQUEST_OBJECT_OPTIONS.each do |k, v|
1384
+ build_tag soap, v[0], v[1], options[k]
1385
+ end
1386
+ case
1387
+ when options[:payment_method].nil?
1388
+ nil
1389
+ when options[:payment_method].kind_of?(ActiveMerchant::Billing::CreditCard)
1390
+ build_credit_card_data soap, options
1391
+ when options[:payment_method].kind_of?(ActiveMerchant::Billing::Check)
1392
+ build_check_data soap, options
1393
+ else
1394
+ raise ArgumentError, 'options[:payment_method] must be a CreditCard or Check'
1395
+ end
1396
+ build_transaction_detail soap, options
1397
+ build_billing_address soap, options
1398
+ build_shipping_address soap, options
1399
+ build_recurring_billing soap, options
1400
+ build_line_items soap, options
1401
+ build_custom_fields soap, options
1402
+ end
1403
+ end
1404
+
1405
+ def build_transaction_detail(soap, options)
1406
+ soap.Details 'xsi:type' => 'ns1:TransactionDetail' do
1407
+ TRANSACTION_DETAIL_OPTIONS.each do |k, v|
1408
+ build_tag soap, v[0], v[1], options[k]
1409
+ end
1410
+ TRANSACTION_DETAIL_MONEY_OPTIONS.each do |k, v|
1411
+ build_tag soap, v[0], v[1], amount(options[k])
1412
+ end
1413
+ end
1414
+ end
1415
+
1416
+ def build_credit_card_data(soap, options)
1417
+ soap.CreditCardData 'xsi:type' => 'ns1:CreditCardData' do
1418
+ build_tag soap, :string, 'CardNumber', options[:payment_method].number
1419
+ build_tag soap, :string, 'CardExpiration', build_card_expiration(options)
1420
+ if options[:billing_address]
1421
+ build_tag soap, :string, 'AvsStreet', options[:billing_address][:address1]
1422
+ build_tag soap, :string, 'AvsZip', options[:billing_address][:zip]
1423
+ end
1424
+ build_tag soap, :string, 'CardCode', options[:payment_method].verification_value
1425
+ build_tag soap, :boolean, 'CardPresent', options[:card_present] || false
1426
+ CREDIT_CARD_DATA_OPTIONS.each do |k, v|
1427
+ build_tag soap, v[0], v[1], options[k]
1428
+ end
1429
+ end
1430
+ end
1431
+
1432
+ def build_card_expiration(options)
1433
+ month = options[:payment_method].month
1434
+ year = options[:payment_method].year
1435
+ "#{'%02d' % month}#{year.to_s[-2..-1]}" unless month.nil? || year.nil?
1436
+ end
1437
+
1438
+ def build_check_data(soap, options)
1439
+ soap.CheckData 'xsi:type' => 'ns1:CheckData' do
1440
+ build_tag soap, :integer, 'CheckNumber', options[:payment_method].number
1441
+ build_tag soap, :string, 'Account', options[:payment_method].account_number
1442
+ build_tag soap, :string, 'Routing', options[:payment_method].routing_number
1443
+ build_tag soap, :string, 'AccountType', options[:payment_method].account_type.capitalize
1444
+ CHECK_DATA_OPTIONS.each do |k, v|
1445
+ build_tag soap, v[0], v[1], options[k]
1446
+ end
1447
+ end
1448
+ end
1449
+
1450
+ def build_recurring_billing(soap, options)
1451
+ if options[:recurring]
1452
+ soap.RecurringBilling 'xsi:type' => 'ns1:RecurringBilling' do
1453
+ build_tag soap, :double, 'Amount', amount(options[:recurring][:amount])
1454
+ build_tag soap, :string, 'Next', options[:recurring][:next].strftime('%Y-%m-%d') if options[:recurring][:next]
1455
+ build_tag soap, :string, 'Expire', options[:recurring][:expire].strftime('%Y-%m-%d') if options[:recurring][:expire]
1456
+ RECURRING_BILLING_OPTIONS.each do |k, v|
1457
+ build_tag soap, v[0], v[1], options[:recurring][k]
1458
+ end
1459
+ end
1460
+ end
1461
+ end
1462
+
1463
+ def build_transaction_field_array(soap, options)
1464
+ soap.Fields 'SOAP-ENC:arryType' => "xsd:string[#{options[:fields].length}]", 'xsi:type' => 'ns1:stringArray' do
1465
+ options[:fields].each do |field|
1466
+ build_tag soap, :string, 'item', field
1467
+ end
1468
+ end
1469
+ end
1470
+
1471
+ # General Helpers ===============================================
1472
+
1473
+ def build_billing_address(soap, options)
1474
+ if options[:billing_address]
1475
+ options[:billing_address][:first_name], options[:billing_address][:last_name] = split_names(options[:billing_address][:name]) if options[:billing_address][:name]
1476
+ soap.BillingAddress 'xsi:type' => 'ns1:Address' do
1477
+ ADDRESS_OPTIONS.each do |k, v|
1478
+ build_tag soap, v[0], v[1], options[:billing_address][k]
1479
+ end
1480
+ end
1481
+ end
1482
+ end
1483
+
1484
+ def build_shipping_address(soap, options)
1485
+ if options[:shipping_address]
1486
+ options[:shipping_address][:first_name], options[:shipping_address][:last_name] = split_names(options[:shipping_address][:name]) if options[:shipping_address][:name]
1487
+ soap.ShippingAddress 'xsi:type' => 'ns1:Address' do
1488
+ ADDRESS_OPTIONS.each do |k, v|
1489
+ build_tag soap, v[0], v[1], options[:shipping_address][k]
1490
+ end
1491
+ end
1492
+ end
1493
+ end
1494
+
1495
+ def build_field_value_array(soap, tag_name, type, custom_data, fields)
1496
+ soap.tag! tag_name, 'SOAP-ENC:arryType' => "xsd:#{type}[#{options.length}]", 'xsi:type' => "ns1:#{type}Array" do
1497
+ custom_data.each do |k, v|
1498
+ build_field_value soap, fields[k][1], v, fields[k][0] if fields.key?(k)
1499
+ end
1500
+ end
1501
+ end
1502
+
1503
+ def build_field_value(soap, field, value, value_type)
1504
+ soap.FieldValue 'xsi:type' => 'ns1:FieldValue' do
1505
+ build_tag soap, :string, 'Field', field
1506
+ build_tag soap, value_type, 'Value', value
1507
+ end
1508
+ end
1509
+
1510
+ def build_line_items(soap, options) # TODO
1511
+ end
1512
+
1513
+ def build_custom_fields(soap, options) # TODO
1514
+ end
1515
+
1516
+ # Request =======================================================
1517
+
1518
+ def commit(action, request)
1519
+ url = test? ? test_url : live_url
1520
+
1521
+ begin
1522
+ soap = ssl_post(url, request, 'Content-Type' => 'text/xml')
1523
+ rescue ActiveMerchant::ResponseError => error
1524
+ soap = error.response.body
1525
+ end
1526
+
1527
+ build_response(action, soap)
1528
+ end
1529
+
1530
+ def build_response(action, soap)
1531
+ response_params, success, message, authorization, avs, cvv = parse(action, soap)
1532
+
1533
+ response_params['soap_response'] = soap if @options[:soap_response]
1534
+
1535
+ Response.new(
1536
+ success,
1537
+ message,
1538
+ response_params,
1539
+ test: test?,
1540
+ authorization: authorization,
1541
+ avs_result: avs_from(avs),
1542
+ cvv_result: cvv
1543
+ )
1544
+ end
1545
+
1546
+ def avs_from(avs)
1547
+ avs_params = { code: avs }
1548
+ avs_params[:message] = AVS_CUSTOM_MESSAGES[avs] if AVS_CUSTOM_MESSAGES.key?(avs)
1549
+ avs_params
1550
+ end
1551
+
1552
+ def parse(action, soap)
1553
+ xml = REXML::Document.new(soap)
1554
+ root = REXML::XPath.first(xml, '//SOAP-ENV:Body')
1555
+ response = root ? parse_element(root[0]) : { response: soap }
1556
+
1557
+ success, message, authorization, avs, cvv = false, FAILURE_MESSAGE, nil, nil, nil
1558
+
1559
+ fault = !response || (response.length < 1) || response.has_key?('faultcode')
1560
+ return [response, success, response['faultstring'], authorization, avs, cvv] if fault
1561
+
1562
+ if response.respond_to?(:[]) && p = response["#{action}_return"]
1563
+ if p.respond_to?(:key?) && p.key?('result_code')
1564
+ success = p['result_code'] == 'A'
1565
+ authorization = p['ref_num']
1566
+ avs = AVS_RESULTS[p['avs_result_code']]
1567
+ cvv = p['card_code_result_code']
1568
+ else
1569
+ success = true
1570
+ end
1571
+ message =
1572
+ case action
1573
+ when :get_customer_payment_methods
1574
+ p['item']
1575
+ when :get_transaction_custom
1576
+ items = p['item'].kind_of?(Array) ? p['item'] : [p['item']]
1577
+ items.inject({}) { |hash, item| hash[item['field']] = item['value']; hash }
1578
+ else
1579
+ p
1580
+ end
1581
+ elsif response.respond_to?(:[]) && p = response[:response]
1582
+ message = p # when response is html
1583
+ end
1584
+
1585
+ [response, success, message, authorization, avs, cvv]
1586
+ end
1587
+
1588
+ def parse_element(node)
1589
+ if node.has_elements?
1590
+ response = {}
1591
+ node.elements.each do |e|
1592
+ key = e.name.underscore
1593
+ value = parse_element(e)
1594
+ if response.has_key?(key)
1595
+ if response[key].is_a?(Array)
1596
+ response[key].push(value)
1597
+ else
1598
+ response[key] = [response[key], value]
1599
+ end
1600
+ else
1601
+ response[key] = parse_element(e)
1602
+ end
1603
+ end
1604
+ else
1605
+ response = node.text
1606
+ end
1607
+
1608
+ response
1609
+ end
1610
+ end
1611
+ end
1612
+ end