activemerchant 1.38.0 → 1.79.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (400) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +1402 -3
  3. data/CONTRIBUTORS +154 -0
  4. data/README.md +157 -144
  5. data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
  6. data/lib/active_merchant/billing/base.rb +21 -17
  7. data/lib/active_merchant/billing/check.rb +32 -22
  8. data/lib/active_merchant/billing/compatibility.rb +120 -0
  9. data/lib/active_merchant/billing/credit_card.rb +215 -67
  10. data/lib/active_merchant/billing/credit_card_formatting.rb +4 -1
  11. data/lib/active_merchant/billing/credit_card_methods.rb +152 -53
  12. data/lib/active_merchant/billing/cvv_result.rb +15 -15
  13. data/lib/active_merchant/billing/gateway.rb +170 -24
  14. data/lib/active_merchant/billing/gateways/adyen.rb +299 -0
  15. data/lib/active_merchant/billing/gateways/allied_wallet.rb +206 -0
  16. data/lib/active_merchant/billing/gateways/authorize_net.rb +904 -606
  17. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +43 -18
  19. data/lib/active_merchant/billing/gateways/axcessms.rb +181 -0
  20. data/lib/active_merchant/billing/gateways/balanced.rb +134 -346
  21. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  22. data/lib/active_merchant/billing/gateways/banwire.rb +13 -2
  23. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +326 -0
  24. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  25. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +96 -15
  26. data/lib/active_merchant/billing/gateways/beanstream.rb +52 -9
  27. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +12 -8
  28. data/lib/active_merchant/billing/gateways/blue_pay.rb +520 -501
  29. data/lib/active_merchant/billing/gateways/blue_snap.rb +343 -0
  30. data/lib/active_merchant/billing/gateways/bogus.rb +94 -50
  31. data/lib/active_merchant/billing/gateways/borgun.rb +221 -0
  32. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  33. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +15 -2
  34. data/lib/active_merchant/billing/gateways/braintree.rb +2 -2
  35. data/lib/active_merchant/billing/gateways/braintree_blue.rb +387 -139
  36. data/lib/active_merchant/billing/gateways/braintree_orange.rb +4 -4
  37. data/lib/active_merchant/billing/gateways/bridge_pay.rb +245 -0
  38. data/lib/active_merchant/billing/gateways/cams.rb +230 -0
  39. data/lib/active_merchant/billing/gateways/card_connect.rb +286 -0
  40. data/lib/active_merchant/billing/gateways/card_stream.rb +269 -118
  41. data/lib/active_merchant/billing/gateways/cardknox.rb +328 -0
  42. data/lib/active_merchant/billing/gateways/cardprocess.rb +254 -0
  43. data/lib/active_merchant/billing/gateways/cashnet.rb +219 -0
  44. data/lib/active_merchant/billing/gateways/cc5.rb +45 -0
  45. data/lib/active_merchant/billing/gateways/cecabank.rb +239 -0
  46. data/lib/active_merchant/billing/gateways/cenpos.rb +327 -0
  47. data/lib/active_merchant/billing/gateways/checkout.rb +214 -0
  48. data/lib/active_merchant/billing/gateways/checkout_v2.rb +233 -0
  49. data/lib/active_merchant/billing/gateways/citrus_pay.rb +23 -0
  50. data/lib/active_merchant/billing/gateways/clearhaus.rb +220 -0
  51. data/lib/active_merchant/billing/gateways/commercegate.rb +143 -0
  52. data/lib/active_merchant/billing/gateways/conekta.rb +225 -0
  53. data/lib/active_merchant/billing/gateways/creditcall.rb +272 -0
  54. data/lib/active_merchant/billing/gateways/credorax.rb +345 -0
  55. data/lib/active_merchant/billing/gateways/culqi.rb +279 -0
  56. data/lib/active_merchant/billing/gateways/cyber_source.rb +237 -98
  57. data/lib/active_merchant/billing/gateways/data_cash.rb +41 -314
  58. data/lib/active_merchant/billing/gateways/dibs.rb +205 -0
  59. data/lib/active_merchant/billing/gateways/digitzs.rb +292 -0
  60. data/lib/active_merchant/billing/gateways/ebanx.rb +296 -0
  61. data/lib/active_merchant/billing/gateways/efsnet.rb +3 -14
  62. data/lib/active_merchant/billing/gateways/elavon.rb +143 -142
  63. data/lib/active_merchant/billing/gateways/element.rb +356 -0
  64. data/lib/active_merchant/billing/gateways/epay.rb +23 -12
  65. data/lib/active_merchant/billing/gateways/eway.rb +12 -12
  66. data/lib/active_merchant/billing/gateways/eway_managed.rb +1 -1
  67. data/lib/active_merchant/billing/gateways/eway_rapid.rb +417 -204
  68. data/lib/active_merchant/billing/gateways/exact.rb +10 -1
  69. data/lib/active_merchant/billing/gateways/ezic.rb +196 -0
  70. data/lib/active_merchant/billing/gateways/fat_zebra.rb +65 -37
  71. data/lib/active_merchant/billing/gateways/federated_canada.rb +1 -8
  72. data/lib/active_merchant/billing/gateways/finansbank.rb +3 -2
  73. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  74. data/lib/active_merchant/billing/gateways/first_pay.rb +110 -124
  75. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +155 -29
  76. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  77. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  78. data/lib/active_merchant/billing/gateways/forte.rb +256 -0
  79. data/lib/active_merchant/billing/gateways/garanti.rb +11 -5
  80. data/lib/active_merchant/billing/gateways/global_collect.rb +334 -0
  81. data/lib/active_merchant/billing/gateways/global_transport.rb +194 -0
  82. data/lib/active_merchant/billing/gateways/hps.rb +305 -0
  83. data/lib/active_merchant/billing/gateways/iats_payments.rb +271 -16
  84. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +2 -5
  85. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +0 -0
  86. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +1 -1
  87. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  88. data/lib/active_merchant/billing/gateways/inspire.rb +8 -10
  89. data/lib/active_merchant/billing/gateways/instapay.rb +0 -0
  90. data/lib/active_merchant/billing/gateways/ipp.rb +175 -0
  91. data/lib/active_merchant/billing/gateways/iridium.rb +210 -4
  92. data/lib/active_merchant/billing/gateways/iveri.rb +251 -0
  93. data/lib/active_merchant/billing/gateways/jetpay.rb +176 -49
  94. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +437 -0
  95. data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
  96. data/lib/active_merchant/billing/gateways/kushki.rb +227 -0
  97. data/lib/active_merchant/billing/gateways/latitude19.rb +416 -0
  98. data/lib/active_merchant/billing/gateways/linkpoint.rb +17 -13
  99. data/lib/active_merchant/billing/gateways/litle.rb +329 -439
  100. data/lib/active_merchant/billing/gateways/mastercard.rb +268 -0
  101. data/lib/active_merchant/billing/gateways/maxipago.rb +220 -0
  102. data/lib/active_merchant/billing/gateways/mercado_pago.rb +262 -0
  103. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +26 -7
  104. data/lib/active_merchant/billing/gateways/merchant_one.rb +0 -1
  105. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  106. data/lib/active_merchant/billing/gateways/merchant_ware.rb +12 -15
  107. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +24 -13
  108. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +33 -14
  109. data/lib/active_merchant/billing/gateways/mercury.rb +74 -29
  110. data/lib/active_merchant/billing/gateways/metrics_global.rb +2 -21
  111. data/lib/active_merchant/billing/gateways/micropayment.rb +185 -0
  112. data/lib/active_merchant/billing/gateways/migs.rb +73 -14
  113. data/lib/active_merchant/billing/gateways/modern_payments.rb +1 -1
  114. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +1 -3
  115. data/lib/active_merchant/billing/gateways/monei.rb +307 -0
  116. data/lib/active_merchant/billing/gateways/moneris.rb +119 -36
  117. data/lib/active_merchant/billing/gateways/moneris_us.rb +146 -45
  118. data/lib/active_merchant/billing/gateways/money_movers.rb +152 -0
  119. data/lib/active_merchant/billing/gateways/mundipagg.rb +292 -0
  120. data/lib/active_merchant/billing/gateways/nab_transact.rb +81 -56
  121. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +165 -0
  122. data/lib/active_merchant/billing/gateways/net_registry.rb +8 -3
  123. data/lib/active_merchant/billing/gateways/netbanx.rb +289 -0
  124. data/lib/active_merchant/billing/gateways/netbilling.rb +61 -26
  125. data/lib/active_merchant/billing/gateways/netpay.rb +1 -1
  126. data/lib/active_merchant/billing/gateways/network_merchants.rb +242 -0
  127. data/lib/active_merchant/billing/gateways/nmi.rb +265 -10
  128. data/lib/active_merchant/billing/gateways/ogone.rb +85 -27
  129. data/lib/active_merchant/billing/gateways/omise.rb +324 -0
  130. data/lib/active_merchant/billing/gateways/openpay.rb +227 -0
  131. data/lib/active_merchant/billing/gateways/opp.rb +372 -0
  132. data/lib/active_merchant/billing/gateways/optimal_payment.rb +59 -28
  133. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +22 -21
  134. data/lib/active_merchant/billing/gateways/orbital.rb +346 -56
  135. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +207 -0
  136. data/lib/active_merchant/billing/gateways/pagarme.rb +248 -0
  137. data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
  138. data/lib/active_merchant/billing/gateways/pay_conex.rb +246 -0
  139. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +30 -14
  140. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  141. data/lib/active_merchant/billing/gateways/pay_junction.rb +19 -25
  142. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +190 -0
  143. data/lib/active_merchant/billing/gateways/pay_secure.rb +0 -7
  144. data/lib/active_merchant/billing/gateways/paybox_direct.rb +16 -12
  145. data/lib/active_merchant/billing/gateways/payeezy.rb +386 -0
  146. data/lib/active_merchant/billing/gateways/payex.rb +412 -0
  147. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +38 -17
  148. data/lib/active_merchant/billing/gateways/payflow.rb +100 -19
  149. data/lib/active_merchant/billing/gateways/payflow_express.rb +22 -22
  150. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +2 -2
  151. data/lib/active_merchant/billing/gateways/payflow_uk.rb +6 -6
  152. data/lib/active_merchant/billing/gateways/payment_express.rb +15 -3
  153. data/lib/active_merchant/billing/gateways/paymentez.rb +276 -0
  154. data/lib/active_merchant/billing/gateways/paymill.rb +237 -48
  155. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +55 -8
  156. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +4 -0
  157. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +18 -4
  158. data/lib/active_merchant/billing/gateways/paypal.rb +37 -20
  159. data/lib/active_merchant/billing/gateways/paypal_ca.rb +1 -1
  160. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +6 -5
  161. data/lib/active_merchant/billing/gateways/paypal_express.rb +32 -4
  162. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +3 -3
  163. data/lib/active_merchant/billing/gateways/payscout.rb +162 -0
  164. data/lib/active_merchant/billing/gateways/paystation.rb +32 -24
  165. data/lib/active_merchant/billing/gateways/payu_in.rb +248 -0
  166. data/lib/active_merchant/billing/gateways/payu_latam.rb +440 -0
  167. data/lib/active_merchant/billing/gateways/pin.rb +68 -13
  168. data/lib/active_merchant/billing/gateways/plugnpay.rb +1 -12
  169. data/lib/active_merchant/billing/gateways/pro_pay.rb +326 -0
  170. data/lib/active_merchant/billing/gateways/psigate.rb +14 -14
  171. data/lib/active_merchant/billing/gateways/psl_card.rb +3 -3
  172. data/lib/active_merchant/billing/gateways/qbms.rb +12 -1
  173. data/lib/active_merchant/billing/gateways/quantum.rb +2 -2
  174. data/lib/active_merchant/billing/gateways/quickbooks.rb +290 -0
  175. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +188 -0
  176. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +299 -0
  177. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +227 -0
  178. data/lib/active_merchant/billing/gateways/quickpay.rb +10 -319
  179. data/lib/active_merchant/billing/gateways/qvalent.rb +236 -0
  180. data/lib/active_merchant/billing/gateways/realex.rb +40 -25
  181. data/lib/active_merchant/billing/gateways/redsys.rb +212 -80
  182. data/lib/active_merchant/billing/gateways/s5.rb +247 -0
  183. data/lib/active_merchant/billing/gateways/safe_charge.rb +262 -0
  184. data/lib/active_merchant/billing/gateways/sage.rb +412 -119
  185. data/lib/active_merchant/billing/gateways/sage_pay.rb +176 -59
  186. data/lib/active_merchant/billing/gateways/secure_net.rb +35 -29
  187. data/lib/active_merchant/billing/gateways/secure_pay.rb +182 -9
  188. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +21 -7
  189. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +0 -7
  190. data/lib/active_merchant/billing/gateways/securion_pay.rb +267 -0
  191. data/lib/active_merchant/billing/gateways/skip_jack.rb +1 -3
  192. data/lib/active_merchant/billing/gateways/smart_ps.rb +14 -3
  193. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  194. data/lib/active_merchant/billing/gateways/spreedly_core.rb +74 -14
  195. data/lib/active_merchant/billing/gateways/stripe.rb +472 -83
  196. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +156 -0
  197. data/lib/active_merchant/billing/gateways/telr.rb +275 -0
  198. data/lib/active_merchant/billing/gateways/tns.rb +22 -0
  199. data/lib/active_merchant/billing/gateways/trans_first.rb +142 -28
  200. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +608 -0
  201. data/lib/active_merchant/billing/gateways/transact_pro.rb +224 -0
  202. data/lib/active_merchant/billing/gateways/transnational.rb +2 -231
  203. data/lib/active_merchant/billing/gateways/trexle.rb +217 -0
  204. data/lib/active_merchant/billing/gateways/trust_commerce.rb +17 -11
  205. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +193 -75
  206. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +156 -64
  207. data/lib/active_merchant/billing/gateways/vanco.rb +294 -0
  208. data/lib/active_merchant/billing/gateways/verifi.rb +1 -8
  209. data/lib/active_merchant/billing/gateways/viaklix.rb +1 -15
  210. data/lib/active_merchant/billing/gateways/visanet_peru.rb +209 -0
  211. data/lib/active_merchant/billing/gateways/webpay.rb +45 -28
  212. data/lib/active_merchant/billing/gateways/wepay.rb +238 -0
  213. data/lib/active_merchant/billing/gateways/wirecard.rb +167 -49
  214. data/lib/active_merchant/billing/gateways/world_net.rb +344 -0
  215. data/lib/active_merchant/billing/gateways/worldpay.rb +171 -45
  216. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +218 -0
  217. data/lib/active_merchant/billing/gateways/worldpay_us.rb +221 -0
  218. data/lib/active_merchant/billing/gateways.rb +8 -11
  219. data/lib/active_merchant/billing/model.rb +30 -0
  220. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
  221. data/lib/active_merchant/billing/payment_token.rb +21 -0
  222. data/lib/active_merchant/billing/rails.rb +3 -0
  223. data/lib/active_merchant/billing/response.rb +24 -17
  224. data/lib/active_merchant/billing.rb +7 -1
  225. data/lib/active_merchant/connection.rb +208 -0
  226. data/lib/active_merchant/country.rb +334 -0
  227. data/lib/active_merchant/empty.rb +20 -0
  228. data/lib/active_merchant/errors.rb +35 -0
  229. data/lib/active_merchant/net_http_ssl_connection.rb +9 -0
  230. data/lib/active_merchant/network_connection_retries.rb +81 -0
  231. data/lib/active_merchant/post_data.rb +24 -0
  232. data/lib/active_merchant/posts_data.rb +94 -0
  233. data/lib/active_merchant/version.rb +1 -1
  234. data/lib/active_merchant.rb +22 -22
  235. data/lib/certs/cacert.pem +3951 -0
  236. data/lib/support/gateway_support.rb +16 -10
  237. data/lib/support/outbound_hosts.rb +13 -10
  238. data/lib/support/ssl_version.rb +87 -0
  239. metadata +164 -306
  240. data/gem-public_cert.pem +0 -20
  241. data/lib/active_merchant/billing/expiry_date.rb +0 -34
  242. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +0 -314
  243. data/lib/active_merchant/billing/gateways/card_stream_modern.rb +0 -155
  244. data/lib/active_merchant/billing/gateways/certo_direct.rb +0 -277
  245. data/lib/active_merchant/billing/gateways/orbital/avs_result.rb +0 -93
  246. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +0 -93
  247. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +0 -114
  248. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +0 -102
  249. data/lib/active_merchant/billing/gateways/samurai.rb +0 -118
  250. data/lib/active_merchant/billing/gateways/vindicia.rb +0 -361
  251. data/lib/active_merchant/billing/integrations/a1agregator/helper.rb +0 -31
  252. data/lib/active_merchant/billing/integrations/a1agregator/notification.rb +0 -186
  253. data/lib/active_merchant/billing/integrations/a1agregator/status.rb +0 -38
  254. data/lib/active_merchant/billing/integrations/a1agregator.rb +0 -26
  255. data/lib/active_merchant/billing/integrations/action_view_helper.rb +0 -73
  256. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +0 -229
  257. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +0 -340
  258. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +0 -38
  259. data/lib/active_merchant/billing/integrations/bogus/helper.rb +0 -17
  260. data/lib/active_merchant/billing/integrations/bogus/notification.rb +0 -11
  261. data/lib/active_merchant/billing/integrations/bogus/return.rb +0 -10
  262. data/lib/active_merchant/billing/integrations/bogus.rb +0 -23
  263. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +0 -120
  264. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +0 -158
  265. data/lib/active_merchant/billing/integrations/chronopay/return.rb +0 -10
  266. data/lib/active_merchant/billing/integrations/chronopay.rb +0 -23
  267. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +0 -200
  268. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +0 -76
  269. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +0 -32
  270. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +0 -37
  271. data/lib/active_merchant/billing/integrations/direc_pay.rb +0 -41
  272. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +0 -90
  273. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +0 -120
  274. data/lib/active_merchant/billing/integrations/directebanking/return.rb +0 -11
  275. data/lib/active_merchant/billing/integrations/directebanking.rb +0 -47
  276. data/lib/active_merchant/billing/integrations/dotpay/helper.rb +0 -77
  277. data/lib/active_merchant/billing/integrations/dotpay/notification.rb +0 -86
  278. data/lib/active_merchant/billing/integrations/dotpay/return.rb +0 -11
  279. data/lib/active_merchant/billing/integrations/dotpay.rb +0 -22
  280. data/lib/active_merchant/billing/integrations/dwolla/common.rb +0 -23
  281. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +0 -43
  282. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +0 -64
  283. data/lib/active_merchant/billing/integrations/dwolla/return.rb +0 -49
  284. data/lib/active_merchant/billing/integrations/dwolla.rb +0 -23
  285. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +0 -34
  286. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +0 -84
  287. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +0 -48
  288. data/lib/active_merchant/billing/integrations/easy_pay/common.rb +0 -40
  289. data/lib/active_merchant/billing/integrations/easy_pay/helper.rb +0 -36
  290. data/lib/active_merchant/billing/integrations/easy_pay/notification.rb +0 -59
  291. data/lib/active_merchant/billing/integrations/easy_pay.rb +0 -30
  292. data/lib/active_merchant/billing/integrations/epay/helper.rb +0 -55
  293. data/lib/active_merchant/billing/integrations/epay/notification.rb +0 -110
  294. data/lib/active_merchant/billing/integrations/epay.rb +0 -21
  295. data/lib/active_merchant/billing/integrations/first_data/helper.rb +0 -61
  296. data/lib/active_merchant/billing/integrations/first_data/notification.rb +0 -56
  297. data/lib/active_merchant/billing/integrations/first_data.rb +0 -38
  298. data/lib/active_merchant/billing/integrations/gestpay/common.rb +0 -42
  299. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +0 -70
  300. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +0 -85
  301. data/lib/active_merchant/billing/integrations/gestpay/return.rb +0 -10
  302. data/lib/active_merchant/billing/integrations/gestpay.rb +0 -25
  303. data/lib/active_merchant/billing/integrations/helper.rb +0 -117
  304. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +0 -58
  305. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +0 -59
  306. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +0 -68
  307. data/lib/active_merchant/billing/integrations/hi_trust.rb +0 -27
  308. data/lib/active_merchant/billing/integrations/ipay88/helper.rb +0 -114
  309. data/lib/active_merchant/billing/integrations/ipay88/return.rb +0 -95
  310. data/lib/active_merchant/billing/integrations/ipay88.rb +0 -19
  311. data/lib/active_merchant/billing/integrations/liqpay/helper.rb +0 -43
  312. data/lib/active_merchant/billing/integrations/liqpay/notification.rb +0 -89
  313. data/lib/active_merchant/billing/integrations/liqpay/return.rb +0 -83
  314. data/lib/active_merchant/billing/integrations/liqpay.rb +0 -30
  315. data/lib/active_merchant/billing/integrations/maksuturva/helper.rb +0 -119
  316. data/lib/active_merchant/billing/integrations/maksuturva/notification.rb +0 -48
  317. data/lib/active_merchant/billing/integrations/maksuturva.rb +0 -86
  318. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +0 -75
  319. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +0 -129
  320. data/lib/active_merchant/billing/integrations/moneybookers.rb +0 -26
  321. data/lib/active_merchant/billing/integrations/nochex/helper.rb +0 -68
  322. data/lib/active_merchant/billing/integrations/nochex/notification.rb +0 -94
  323. data/lib/active_merchant/billing/integrations/nochex/return.rb +0 -10
  324. data/lib/active_merchant/billing/integrations/nochex.rb +0 -88
  325. data/lib/active_merchant/billing/integrations/notification.rb +0 -71
  326. data/lib/active_merchant/billing/integrations/paxum/common.rb +0 -24
  327. data/lib/active_merchant/billing/integrations/paxum/helper.rb +0 -42
  328. data/lib/active_merchant/billing/integrations/paxum/notification.rb +0 -33
  329. data/lib/active_merchant/billing/integrations/paxum.rb +0 -44
  330. data/lib/active_merchant/billing/integrations/pay_fast/common.rb +0 -42
  331. data/lib/active_merchant/billing/integrations/pay_fast/helper.rb +0 -50
  332. data/lib/active_merchant/billing/integrations/pay_fast/notification.rb +0 -134
  333. data/lib/active_merchant/billing/integrations/pay_fast/return.rb +0 -10
  334. data/lib/active_merchant/billing/integrations/pay_fast.rb +0 -70
  335. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +0 -116
  336. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +0 -78
  337. data/lib/active_merchant/billing/integrations/payflow_link.rb +0 -21
  338. data/lib/active_merchant/billing/integrations/paypal/helper.rb +0 -119
  339. data/lib/active_merchant/billing/integrations/paypal/notification.rb +0 -227
  340. data/lib/active_merchant/billing/integrations/paypal/return.rb +0 -10
  341. data/lib/active_merchant/billing/integrations/paypal.rb +0 -39
  342. data/lib/active_merchant/billing/integrations/paypal_payments_advanced/helper.rb +0 -15
  343. data/lib/active_merchant/billing/integrations/paypal_payments_advanced.rb +0 -20
  344. data/lib/active_merchant/billing/integrations/paysbuy/helper.rb +0 -15
  345. data/lib/active_merchant/billing/integrations/paysbuy/notification.rb +0 -28
  346. data/lib/active_merchant/billing/integrations/paysbuy.rb +0 -36
  347. data/lib/active_merchant/billing/integrations/payu_in/helper.rb +0 -74
  348. data/lib/active_merchant/billing/integrations/payu_in/notification.rb +0 -165
  349. data/lib/active_merchant/billing/integrations/payu_in/return.rb +0 -36
  350. data/lib/active_merchant/billing/integrations/payu_in.rb +0 -43
  351. data/lib/active_merchant/billing/integrations/platron/helper.rb +0 -32
  352. data/lib/active_merchant/billing/integrations/platron/notification.rb +0 -113
  353. data/lib/active_merchant/billing/integrations/platron.rb +0 -28
  354. data/lib/active_merchant/billing/integrations/pxpay/helper.rb +0 -112
  355. data/lib/active_merchant/billing/integrations/pxpay/notification.rb +0 -157
  356. data/lib/active_merchant/billing/integrations/pxpay/return.rb +0 -25
  357. data/lib/active_merchant/billing/integrations/pxpay.rb +0 -31
  358. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +0 -74
  359. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +0 -137
  360. data/lib/active_merchant/billing/integrations/quickpay.rb +0 -21
  361. data/lib/active_merchant/billing/integrations/rbkmoney/helper.rb +0 -23
  362. data/lib/active_merchant/billing/integrations/rbkmoney/notification.rb +0 -91
  363. data/lib/active_merchant/billing/integrations/rbkmoney.rb +0 -17
  364. data/lib/active_merchant/billing/integrations/return.rb +0 -42
  365. data/lib/active_merchant/billing/integrations/robokassa/common.rb +0 -19
  366. data/lib/active_merchant/billing/integrations/robokassa/helper.rb +0 -50
  367. data/lib/active_merchant/billing/integrations/robokassa/notification.rb +0 -55
  368. data/lib/active_merchant/billing/integrations/robokassa/return.rb +0 -17
  369. data/lib/active_merchant/billing/integrations/robokassa.rb +0 -49
  370. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +0 -33
  371. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +0 -136
  372. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +0 -210
  373. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +0 -31
  374. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +0 -37
  375. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +0 -91
  376. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +0 -139
  377. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +0 -17
  378. data/lib/active_merchant/billing/integrations/two_checkout.rb +0 -44
  379. data/lib/active_merchant/billing/integrations/valitor/helper.rb +0 -86
  380. data/lib/active_merchant/billing/integrations/valitor/notification.rb +0 -13
  381. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +0 -97
  382. data/lib/active_merchant/billing/integrations/valitor/return.rb +0 -13
  383. data/lib/active_merchant/billing/integrations/valitor.rb +0 -33
  384. data/lib/active_merchant/billing/integrations/verkkomaksut/helper.rb +0 -88
  385. data/lib/active_merchant/billing/integrations/verkkomaksut/notification.rb +0 -59
  386. data/lib/active_merchant/billing/integrations/verkkomaksut.rb +0 -20
  387. data/lib/active_merchant/billing/integrations/web_pay/common.rb +0 -50
  388. data/lib/active_merchant/billing/integrations/web_pay/helper.rb +0 -68
  389. data/lib/active_merchant/billing/integrations/web_pay/notification.rb +0 -51
  390. data/lib/active_merchant/billing/integrations/web_pay.rb +0 -45
  391. data/lib/active_merchant/billing/integrations/webmoney/common.rb +0 -17
  392. data/lib/active_merchant/billing/integrations/webmoney/helper.rb +0 -40
  393. data/lib/active_merchant/billing/integrations/webmoney/notification.rb +0 -47
  394. data/lib/active_merchant/billing/integrations/webmoney.rb +0 -43
  395. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +0 -101
  396. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +0 -160
  397. data/lib/active_merchant/billing/integrations/world_pay.rb +0 -34
  398. data/lib/active_merchant/billing/integrations.rb +0 -17
  399. data.tar.gz.sig +0 -0
  400. metadata.gz.sig +0 -0
@@ -1,501 +1,520 @@
1
- require 'digest/md5'
2
-
3
- module ActiveMerchant #:nodoc:
4
- module Billing #:nodoc:
5
- class BluePayGateway < Gateway
6
- class_attribute :rebilling_url, :ignore_http_status
7
-
8
- self.live_url = 'https://secure.bluepay.com/interfaces/bp20post'
9
- self.rebilling_url = 'https://secure.bluepay.com/interfaces/bp20rebadmin'
10
-
11
- self.ignore_http_status = true
12
-
13
- CARD_CODE_ERRORS = %w( N S )
14
- AVS_ERRORS = %w( A E N R W Z )
15
- AVS_REASON_CODES = %w(27 45)
16
-
17
- FRAUD_REVIEW_STATUSES = %w( E 0 )
18
-
19
- FIELD_MAP = {
20
- 'TRANS_ID' => :transaction_id,
21
- 'STATUS' => :response_code,
22
- 'AVS' => :avs_result_code,
23
- 'CVV2'=> :card_code,
24
- 'AUTH_CODE' => :authorization,
25
- 'MESSAGE' => :message,
26
- 'REBID' => :rebid,
27
- 'TRANS_TYPE' => :trans_type,
28
- 'PAYMENT_ACCOUNT_MASK' => :acct_mask,
29
- 'CARD_TYPE' => :card_type,
30
- }
31
-
32
- REBILL_FIELD_MAP = {
33
- 'REBILL_ID' => :rebill_id,
34
- 'ACCOUNT_ID'=> :account_id,
35
- 'USER_ID' => :user_id,
36
- 'TEMPLATE_ID' => :template_id,
37
- 'STATUS' => :status,
38
- 'CREATION_DATE' => :creation_date,
39
- 'NEXT_DATE' => :next_date,
40
- 'LAST_DATE' => :last_date,
41
- 'SCHED_EXPR' => :schedule,
42
- 'CYCLES_REMAIN' => :cycles_remain,
43
- 'REB_AMOUNT' => :rebill_amount,
44
- 'NEXT_AMOUNT' => :next_amount,
45
- 'USUAL_DATE' => :undoc_usual_date, # Not found in the bp20rebadmin API doc.
46
- }
47
-
48
- self.supported_countries = ['US']
49
- self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club, :jcb]
50
- self.homepage_url = 'http://www.bluepay.com/'
51
- self.display_name = 'BluePay'
52
- self.money_format = :dollars
53
-
54
- # Creates a new BluepayGateway
55
- #
56
- # The gateway requires that a valid Account ID and Secret Key be passed
57
- # in the +options+ hash.
58
- #
59
- # ==== Options
60
- #
61
- # * <tt>:account_id</tt> -- The BluePay gateway Account ID (REQUIRED)
62
- # * <tt>:secret_key</tt> -- The BluePay gateway Secret Key (REQUIRED)
63
- # * <tt>:test</tt> -- set to true for TEST mode or false for LIVE mode
64
- def initialize(options = {})
65
- requires!(options, :login, :password)
66
- super
67
- end
68
-
69
- # Performs an authorization, which reserves the funds on the customer's credit card. This does not actually take funds from the customer
70
- # This is referred to an AUTH transaction in BluePay
71
- #
72
- # ==== Parameters
73
- #
74
- # * <tt>money</tt> -- The amount to be authorized as an Integer value in cents.
75
- # * <tt>payment_object</tt> -- This can either be one of three things:
76
- # A CreditCard object,
77
- # A Check object,
78
- # or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.
79
- # * <tt>options</tt> -- A hash of optional parameters.
80
- def authorize(money, payment_object, options = {})
81
- post = {}
82
- add_payment_method(post, payment_object)
83
- add_invoice(post, options)
84
- add_address(post, options)
85
- add_customer_data(post, options)
86
- add_rebill(post, options) if options[:rebill]
87
- add_duplicate_override(post, options)
88
- post[:TRANS_TYPE] = 'AUTH'
89
- commit('AUTH_ONLY', money, post)
90
- end
91
-
92
- # Perform a purchase, which is essentially an authorization and capture in a single operation.
93
- # This is referred to a SALE transaction in BluePay
94
- #
95
- # ==== Parameters
96
- #
97
- # * <tt>money</tt> -- The amount to be purchased as an Integer value in cents.
98
- # * <tt>payment_object</tt> -- This can either be one of three things:
99
- # A CreditCard object,
100
- # A Check object,
101
- # or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.
102
- # * <tt>options</tt> -- A hash of optional parameters.,
103
- def purchase(money, payment_object, options = {})
104
- post = {}
105
- add_payment_method(post, payment_object)
106
- add_invoice(post, options)
107
- add_address(post, options)
108
- add_customer_data(post, options)
109
- add_rebill(post, options) if options[:rebill]
110
- add_duplicate_override(post, options)
111
- post[:TRANS_TYPE] = 'SALE'
112
- commit('AUTH_CAPTURE', money, post)
113
- end
114
-
115
- # Captures the funds from an authorize transaction.
116
- # This is referred to a CAPTURE transaction in BluePay
117
- #
118
- # ==== Parameters
119
- #
120
- # * <tt>money</tt> -- The amount to be captured as an Integer value in cents.
121
- # * <tt>identification</tt> -- The Master ID, or token, returned from the previous authorize transaction.
122
- def capture(money, identification, options = {})
123
- post = {}
124
- add_address(post, options)
125
- add_customer_data(post, options)
126
- post[:MASTER_ID] = identification
127
- post[:TRANS_TYPE] = 'CAPTURE'
128
- commit('PRIOR_AUTH_CAPTURE', money, post)
129
- end
130
-
131
- # Void a previous transaction
132
- # This is referred to a VOID transaction in BluePay
133
- #
134
- # ==== Parameters
135
- #
136
- # * <tt>identification</tt> - The Master ID, or token, returned from a previous authorize transaction.
137
- def void(identification, options = {})
138
- post = {}
139
- post[:MASTER_ID] = identification
140
- post[:TRANS_TYPE] = 'VOID'
141
- commit('VOID', nil, post)
142
- end
143
-
144
- # Performs a credit.
145
- #
146
- # This transaction indicates that money should flow from the merchant to the customer.
147
- #
148
- # ==== Parameters
149
- #
150
- # * <tt>money</tt> -- The amount to be credited to the customer as an Integer value in cents.
151
- # * <tt>payment_object</tt> -- This can either be one of three things:
152
- # A CreditCard object,
153
- # A Check object,
154
- # or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.
155
- # If the payment_object is a token, then the transaction type will reverse a previous capture or purchase transaction, returning the funds to the customer. If the amount is nil, a full credit will be processed. This is referred to a REFUND transaction in BluePay.
156
- # If the payment_object is either a CreditCard or Check object, then the transaction type will be an unmatched credit placing funds in the specified account. This is referred to a CREDIT transaction in BluePay.
157
- # * <tt>options</tt> -- A hash of parameters.
158
- def refund(money, identification, options = {})
159
- if(identification && !identification.kind_of?(String))
160
- deprecated "refund should only be used to refund a referenced transaction"
161
- return credit(money, identification, options)
162
- end
163
-
164
- post = {}
165
- post[:PAYMENT_ACCOUNT] = ''
166
- post[:MASTER_ID] = identification
167
- post[:TRANS_TYPE] = 'REFUND'
168
- post[:NAME1] = (options[:first_name] ? options[:first_name] : "")
169
- post[:NAME2] = options[:last_name] if options[:last_name]
170
- post[:ZIP] = options[:zip] if options[:zip]
171
- add_invoice(post, options)
172
- add_address(post, options)
173
- add_customer_data(post, options)
174
- commit('CREDIT', money, post)
175
- end
176
-
177
- def credit(money, payment_object, options = {})
178
- if(payment_object && payment_object.kind_of?(String))
179
- deprecated "credit should only be used to credit a payment method"
180
- return refund(money, payment_object, options)
181
- end
182
-
183
- post = {}
184
- post[:PAYMENT_ACCOUNT] = ''
185
- add_payment_method(post, payment_object)
186
- post[:TRANS_TYPE] = 'CREDIT'
187
-
188
- post[:NAME1] = (options[:first_name] ? options[:first_name] : "")
189
- post[:NAME2] = options[:last_name] if options[:last_name]
190
- post[:ZIP] = options[:zip] if options[:zip]
191
- add_invoice(post, options)
192
- add_address(post, options)
193
- add_customer_data(post, options)
194
- commit('CREDIT', money, post)
195
- end
196
-
197
- # Create a new recurring payment.
198
- #
199
- # ==== Parameters
200
- #
201
- # * <tt>money</tt> -- The amount to charge the customer at the time of the recurring payment setup, in cents. Set to zero if you do not want the customer to be charged at this time.
202
- # * <tt>payment_object</tt> -- This can either be one of three things:
203
- # A CreditCard object,
204
- # A Check object,
205
- # or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.
206
- # * <tt>options</tt> -- A hash of optional parameters.,
207
-
208
- # ==== Options
209
- #
210
- # * <tt>:rebill_start_date</tt> is a string that tells the gateway when to start the rebill. (REQUIRED)
211
- # Has two valid formats:
212
- # "YYYY-MM-DD HH:MM:SS" Hours, minutes, and seconds are optional.
213
- # "XX UNITS" Relative date as explained below. Marked from the time of the
214
- # transaction (i.e.: 10 DAYS, 1 MONTH, 1 YEAR)
215
- # * <tt>:rebill_expression</tt> is the period of time in-between rebillings. (REQUIRED)
216
- # It uses the same "XX UNITS" format as rebill_start_date, explained above.
217
- # Optional parameters include:
218
- # * <tt>rebill_cycles</tt>: Number of times to rebill. Don't send or set to nil for infinite rebillings (or
219
- # until canceled).
220
- # * <tt>rebill_amount</tt>: Amount to rebill. Defaults to amount of transaction for rebillings.
221
- #
222
- # For example, to charge the customer $19.95 now and then charge $39.95 in 60 days every 3 months for 5 times, the options hash would be as follows:
223
- # :rebill_start_date => '60 DAYS',
224
- # :rebill_expression => '3 MONTHS',
225
- # :rebill_cycles => '5',
226
- # :rebill_amount => '39.95'
227
- # A money object of 1995 cents would be passed into the 'money' parameter.
228
- def recurring(money, payment_object, options = {})
229
- requires!(options, :rebill_start_date, :rebill_expression)
230
- options[:rebill] = true
231
- if money
232
- purchase(money, payment_object, options)
233
- else
234
- authorize(money, payment_object, options)
235
- end
236
- end
237
-
238
- # View a recurring payment
239
- #
240
- # This will pull data associated with a current recurring billing
241
- #
242
- # ==== Parameters
243
- #
244
- # * <tt>rebill_id</tt> -- A string containing the rebill_id of the recurring billing that is already active (REQUIRED)
245
- def status_recurring(rebill_id)
246
- post = {}
247
- requires!(rebill_id)
248
- post[:REBILL_ID] = rebill_id
249
- post[:TRANS_TYPE] = 'GET'
250
- commit('rebill', 'nil', post)
251
- end
252
-
253
- # Update a recurring payment's details.
254
- #
255
- # This transaction updates an existing recurring billing
256
- #
257
- # ==== Options
258
- #
259
- # * <tt>:rebill_id</tt> -- The 12 digit rebill ID used to update a particular rebilling cycle. (REQUIRED)
260
- # * <tt>:rebill_amount</tt> -- A string containing the new rebilling amount.
261
- # * <tt>:rebill_next_date</tt> -- A string containing the new rebilling next date.
262
- # * <tt>:rebill_expression</tt> -- A string containing the new rebilling expression.
263
- # * <tt>:rebill_cycles</tt> -- A string containing the new rebilling cycles.
264
- # * <tt>:rebill_next_amount</tt> -- A string containing the next rebilling amount to charge the customer. This ONLY affects the next scheduled charge; all other rebillings will continue at the regular (rebill_amount) amount.
265
- # Take a look above at the recurring_payment method for similar examples on how to use.
266
- def update_recurring(options = {})
267
- post = {}
268
- requires!(options, :rebill_id)
269
- post[:REBILL_ID] = options[:rebill_id]
270
- post[:TRANS_TYPE] = 'SET'
271
- post[:REB_AMOUNT] = amount(options[:rebill_amount]) if options[:rebill_amount]
272
- post[:NEXT_DATE] = options[:rebill_next_date]
273
- post[:REB_EXPR] = options[:rebill_expression]
274
- post[:REB_CYCLES] = options[:rebill_cycles]
275
- post[:NEXT_AMOUNT] = options[:rebill_next_amount]
276
- commit('rebill', 'nil', post)
277
- end
278
-
279
- # Cancel a recurring payment.
280
- #
281
- # This transaction cancels an existing recurring billing.
282
- #
283
- # ==== Parameters
284
- #
285
- # * <tt>rebill_id</tt> -- A string containing the rebill_id of the recurring billing that you wish to cancel/stop (REQUIRED)
286
- def cancel_recurring(rebill_id)
287
- post = {}
288
- requires!(rebill_id)
289
- post[:REBILL_ID] = rebill_id
290
- post[:TRANS_TYPE] = 'SET'
291
- post[:STATUS] = 'stopped'
292
- commit('rebill', 'nil', post)
293
- end
294
-
295
- private
296
-
297
- def commit(action, money, fields)
298
- fields[:AMOUNT] = amount(money) unless(fields[:TRANS_TYPE] == 'VOID' || action == 'rebill')
299
- fields[:MODE] = (test? ? 'TEST' : 'LIVE')
300
- fields[:ACCOUNT_ID] = @options[:login]
301
-
302
- if action == 'rebill'
303
- url = rebilling_url
304
- fields[:TAMPER_PROOF_SEAL] = calc_rebill_tps(fields)
305
- else
306
- url = live_url
307
- fields[:TAMPER_PROOF_SEAL] = calc_tps(amount(money), fields)
308
- end
309
- parse(ssl_post(url, post_data(action, fields)))
310
- end
311
-
312
- def parse_recurring(response_fields, opts={}) # expected status?
313
- parsed = {}
314
- response_fields.each do |k,v|
315
- mapped_key = REBILL_FIELD_MAP.include?(k) ? REBILL_FIELD_MAP[k] : k
316
- parsed[mapped_key] = v
317
- end
318
-
319
- success = parsed[:status] != 'error'
320
- message = parsed[:status]
321
-
322
- Response.new(success, message, parsed,
323
- :test => test?,
324
- :authorization => parsed[:rebill_id])
325
- end
326
-
327
- def parse(body)
328
- # The bp20api has max one value per form field.
329
- response_fields = Hash[CGI::parse(body).map{|k,v| [k.upcase,v.first]}]
330
-
331
- if response_fields.include? "REBILL_ID"
332
- return parse_recurring(response_fields)
333
- end
334
-
335
- parsed = {}
336
- response_fields.each do |k,v|
337
- mapped_key = FIELD_MAP.include?(k) ? FIELD_MAP[k] : k
338
- parsed[mapped_key] = v
339
- end
340
-
341
- # normalize message
342
- message = message_from(parsed)
343
- success = parsed[:response_code] == '1'
344
- Response.new(success, message, parsed,
345
- :test => test?,
346
- :authorization => (parsed[:rebid] && parsed[:rebid] != '' ? parsed[:rebid] : parsed[:transaction_id]),
347
- :fraud_review => FRAUD_REVIEW_STATUSES.include?(parsed[:response_code]),
348
- :avs_result => { :code => parsed[:avs_result_code] },
349
- :cvv_result => parsed[:card_code]
350
- )
351
- end
352
-
353
- def message_from(parsed)
354
- message = parsed[:message]
355
- if(parsed[:response_code].to_i == 2)
356
- if CARD_CODE_ERRORS.include?(parsed[:card_code])
357
- message = CVVResult.messages[parsed[:card_code]]
358
- elsif AVS_ERRORS.include?(parsed[:avs_result_code])
359
- message = AVSResult.messages[ parsed[:avs_result_code] ]
360
- else
361
- message = message.chomp('.')
362
- end
363
- elsif message == "Missing ACCOUNT_ID"
364
- message = "The merchant login ID or password is invalid"
365
- elsif message =~ /Approved/
366
- message = "This transaction has been approved"
367
- elsif message =~ /Expired/
368
- message = "The credit card has expired"
369
- end
370
- message
371
- end
372
-
373
- def add_invoice(post, options)
374
- post[:ORDER_ID] = options[:order_id]
375
- post[:INVOICE_ID] = options[:invoice]
376
- post[:invoice_num] = options[:order_id]
377
- post[:MEMO] = options[:description]
378
- post[:description] = options[:description]
379
- end
380
-
381
- def add_payment_method(post, payment_object)
382
- post[:MASTER_ID] = ''
383
- case payment_object
384
- when String
385
- post[:MASTER_ID] = payment_object
386
- when Check
387
- add_check(post, payment_object)
388
- else
389
- add_creditcard(post, payment_object)
390
- end
391
- end
392
-
393
- def add_creditcard(post, creditcard)
394
- post[:PAYMENT_TYPE] = 'CREDIT'
395
- post[:PAYMENT_ACCOUNT] = creditcard.number
396
- post[:CARD_CVV2] = creditcard.verification_value
397
- post[:CARD_EXPIRE] = expdate(creditcard)
398
- post[:NAME1] = creditcard.first_name
399
- post[:NAME2] = creditcard.last_name
400
- end
401
-
402
- CHECK_ACCOUNT_TYPES = {
403
- "checking" => "C",
404
- "savings" => "S"
405
- }
406
-
407
- def add_check(post, check)
408
- post[:PAYMENT_TYPE] = 'ACH'
409
- post[:PAYMENT_ACCOUNT] = [CHECK_ACCOUNT_TYPES[check.account_type], check.routing_number, check.account_number].join(":")
410
- post[:NAME1] = check.first_name
411
- post[:NAME2] = check.last_name
412
- end
413
-
414
- def add_customer_data(post, options)
415
- post[:EMAIL] = options[:email]
416
- post[:CUSTOM_ID] = options[:customer]
417
- end
418
-
419
- def add_duplicate_override(post, options)
420
- post[:DUPLICATE_OVERRIDE] = options[:duplicate_override]
421
- end
422
-
423
- def add_address(post, options)
424
- if address = (options[:shipping_address] || options[:billing_address] || options[:address])
425
- post[:ADDR1] = address[:address1]
426
- post[:ADDR2] = address[:address2]
427
- post[:COMPANY_NAME] = address[:company]
428
- post[:PHONE] = address[:phone]
429
- post[:CITY] = address[:city]
430
- post[:STATE] = (address[:state].blank? ? 'n/a' : address[:state])
431
- post[:ZIP] = address[:zip]
432
- post[:COUNTRY] = address[:country]
433
- end
434
- end
435
-
436
- def add_rebill(post, options)
437
- post[:DO_REBILL] = '1'
438
- post[:REB_AMOUNT] = amount(options[:rebill_amount])
439
- post[:REB_FIRST_DATE] = options[:rebill_start_date]
440
- post[:REB_EXPR] = options[:rebill_expression]
441
- post[:REB_CYCLES] = options[:rebill_cycles]
442
- end
443
-
444
- def post_data(action, parameters = {})
445
- post = {}
446
- post[:version] = '1'
447
- post[:login] = ''
448
- post[:tran_key] = ''
449
- post[:relay_response] = "FALSE"
450
- post[:type] = action
451
- post[:delim_data] = "TRUE"
452
- post[:delim_char] = ","
453
- post[:encap_char] = "$"
454
- post[:card_num] = '4111111111111111'
455
- post[:exp_date] = '1212'
456
- post[:solution_ID] = application_id if(application_id && application_id != "ActiveMerchant")
457
- post.merge(parameters).collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
458
- end
459
-
460
- def expdate(creditcard)
461
- year = format(creditcard.year, :two_digits)
462
- month = format(creditcard.month, :two_digits)
463
-
464
- "#{month}#{year}"
465
- end
466
-
467
- def calc_tps(amount, post)
468
- post[:NAME1] ||= ''
469
- Digest::MD5.hexdigest(
470
- [
471
- @options[:password],
472
- @options[:login],
473
- post[:TRANS_TYPE],
474
- amount,
475
- post[:MASTER_ID],
476
- post[:NAME1],
477
- post[:PAYMENT_ACCOUNT]
478
- ].join("")
479
- )
480
- end
481
-
482
- def calc_rebill_tps(post)
483
- Digest::MD5.hexdigest(
484
- [
485
- @options[:password],
486
- @options[:login],
487
- post[:TRANS_TYPE],
488
- post[:REBILL_ID]
489
- ].join("")
490
- )
491
- end
492
-
493
- def handle_response(response)
494
- if ignore_http_status || (200...300).include?(response.code.to_i)
495
- return response.body
496
- end
497
- raise ResponseError.new(response)
498
- end
499
- end
500
- end
501
- end
1
+ require 'digest/md5'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class BluePayGateway < Gateway
6
+ class_attribute :rebilling_url, :ignore_http_status
7
+
8
+ self.live_url = 'https://secure.bluepay.com/interfaces/bp20post'
9
+ self.rebilling_url = 'https://secure.bluepay.com/interfaces/bp20rebadmin'
10
+
11
+ self.ignore_http_status = true
12
+
13
+ CARD_CODE_ERRORS = %w( N S )
14
+ AVS_ERRORS = %w( A E N R W Z )
15
+ AVS_REASON_CODES = %w(27 45)
16
+
17
+ FIELD_MAP = {
18
+ 'TRANS_ID' => :transaction_id,
19
+ 'STATUS' => :response_code,
20
+ 'AVS' => :avs_result_code,
21
+ 'CVV2'=> :card_code,
22
+ 'AUTH_CODE' => :authorization,
23
+ 'MESSAGE' => :message,
24
+ 'REBID' => :rebid,
25
+ 'TRANS_TYPE' => :trans_type,
26
+ 'PAYMENT_ACCOUNT_MASK' => :acct_mask,
27
+ 'CARD_TYPE' => :card_type,
28
+ }
29
+
30
+ REBILL_FIELD_MAP = {
31
+ 'REBILL_ID' => :rebill_id,
32
+ 'ACCOUNT_ID'=> :account_id,
33
+ 'USER_ID' => :user_id,
34
+ 'TEMPLATE_ID' => :template_id,
35
+ 'STATUS' => :status,
36
+ 'CREATION_DATE' => :creation_date,
37
+ 'NEXT_DATE' => :next_date,
38
+ 'LAST_DATE' => :last_date,
39
+ 'SCHED_EXPR' => :schedule,
40
+ 'CYCLES_REMAIN' => :cycles_remain,
41
+ 'REB_AMOUNT' => :rebill_amount,
42
+ 'NEXT_AMOUNT' => :next_amount,
43
+ 'USUAL_DATE' => :undoc_usual_date, # Not found in the bp20rebadmin API doc.
44
+ }
45
+
46
+ self.supported_countries = ['US', 'CA']
47
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club, :jcb]
48
+ self.homepage_url = 'http://www.bluepay.com/'
49
+ self.display_name = 'BluePay'
50
+ self.money_format = :dollars
51
+
52
+ # Creates a new BluepayGateway
53
+ #
54
+ # The gateway requires that a valid Account ID and Secret Key be passed
55
+ # in the +options+ hash.
56
+ #
57
+ # ==== Options
58
+ #
59
+ # * <tt>:account_id</tt> -- The BluePay gateway Account ID (REQUIRED)
60
+ # * <tt>:secret_key</tt> -- The BluePay gateway Secret Key (REQUIRED)
61
+ # * <tt>:test</tt> -- set to true for TEST mode or false for LIVE mode
62
+ def initialize(options = {})
63
+ requires!(options, :login, :password)
64
+ super
65
+ end
66
+
67
+ # Performs an authorization, which reserves the funds on the customer's credit card. This does not actually take funds from the customer
68
+ # This is referred to an AUTH transaction in BluePay
69
+ #
70
+ # ==== Parameters
71
+ #
72
+ # * <tt>money</tt> -- The amount to be authorized as an Integer value in cents.
73
+ # * <tt>payment_object</tt> -- This can either be one of three things:
74
+ # A CreditCard object,
75
+ # A Check object,
76
+ # or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.
77
+ # * <tt>options</tt> -- A hash of optional parameters.
78
+ def authorize(money, payment_object, options = {})
79
+ post = {}
80
+ add_payment_method(post, payment_object)
81
+ add_invoice(post, options)
82
+ add_address(post, options)
83
+ add_customer_data(post, options)
84
+ add_rebill(post, options) if options[:rebill]
85
+ add_duplicate_override(post, options)
86
+ post[:TRANS_TYPE] = 'AUTH'
87
+ commit('AUTH_ONLY', money, post)
88
+ end
89
+
90
+ # Perform a purchase, which is essentially an authorization and capture in a single operation.
91
+ # This is referred to a SALE transaction in BluePay
92
+ #
93
+ # ==== Parameters
94
+ #
95
+ # * <tt>money</tt> -- The amount to be purchased as an Integer value in cents.
96
+ # * <tt>payment_object</tt> -- This can either be one of three things:
97
+ # A CreditCard object,
98
+ # A Check object,
99
+ # or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.
100
+ # * <tt>options</tt> -- A hash of optional parameters.,
101
+ def purchase(money, payment_object, options = {})
102
+ post = {}
103
+ add_payment_method(post, payment_object)
104
+ add_invoice(post, options)
105
+ add_address(post, options)
106
+ add_customer_data(post, options)
107
+ add_rebill(post, options) if options[:rebill]
108
+ add_duplicate_override(post, options)
109
+ post[:TRANS_TYPE] = 'SALE'
110
+ commit('AUTH_CAPTURE', money, post)
111
+ end
112
+
113
+ # Captures the funds from an authorize transaction.
114
+ # This is referred to a CAPTURE transaction in BluePay
115
+ #
116
+ # ==== Parameters
117
+ #
118
+ # * <tt>money</tt> -- The amount to be captured as an Integer value in cents.
119
+ # * <tt>identification</tt> -- The Master ID, or token, returned from the previous authorize transaction.
120
+ def capture(money, identification, options = {})
121
+ post = {}
122
+ add_address(post, options)
123
+ add_customer_data(post, options)
124
+ post[:MASTER_ID] = identification
125
+ post[:TRANS_TYPE] = 'CAPTURE'
126
+ commit('PRIOR_AUTH_CAPTURE', money, post)
127
+ end
128
+
129
+ # Void a previous transaction
130
+ # This is referred to a VOID transaction in BluePay
131
+ #
132
+ # ==== Parameters
133
+ #
134
+ # * <tt>identification</tt> - The Master ID, or token, returned from a previous authorize transaction.
135
+ def void(identification, options = {})
136
+ post = {}
137
+ post[:MASTER_ID] = identification
138
+ post[:TRANS_TYPE] = 'VOID'
139
+ commit('VOID', nil, post)
140
+ end
141
+
142
+ # Performs a credit.
143
+ #
144
+ # This transaction indicates that money should flow from the merchant to the customer.
145
+ #
146
+ # ==== Parameters
147
+ #
148
+ # * <tt>money</tt> -- The amount to be credited to the customer as an Integer value in cents.
149
+ # * <tt>payment_object</tt> -- This can either be one of three things:
150
+ # A CreditCard object,
151
+ # A Check object,
152
+ # or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.
153
+ # If the payment_object is a token, then the transaction type will reverse a previous capture or purchase transaction, returning the funds to the customer. If the amount is nil, a full credit will be processed. This is referred to a REFUND transaction in BluePay.
154
+ # If the payment_object is either a CreditCard or Check object, then the transaction type will be an unmatched credit placing funds in the specified account. This is referred to a CREDIT transaction in BluePay.
155
+ # * <tt>options</tt> -- A hash of parameters.
156
+ def refund(money, identification, options = {})
157
+ if(identification && !identification.kind_of?(String))
158
+ ActiveMerchant.deprecated "refund should only be used to refund a referenced transaction"
159
+ return credit(money, identification, options)
160
+ end
161
+
162
+ post = {}
163
+ post[:PAYMENT_ACCOUNT] = ''
164
+ post[:MASTER_ID] = identification
165
+ post[:TRANS_TYPE] = 'REFUND'
166
+ post[:NAME1] = (options[:first_name] ? options[:first_name] : "")
167
+ post[:NAME2] = options[:last_name] if options[:last_name]
168
+ post[:ZIP] = options[:zip] if options[:zip]
169
+ add_invoice(post, options)
170
+ add_address(post, options)
171
+ add_customer_data(post, options)
172
+ commit('CREDIT', money, post)
173
+ end
174
+
175
+ def credit(money, payment_object, options = {})
176
+ if(payment_object && payment_object.kind_of?(String))
177
+ ActiveMerchant.deprecated "credit should only be used to credit a payment method"
178
+ return refund(money, payment_object, options)
179
+ end
180
+
181
+ post = {}
182
+ post[:PAYMENT_ACCOUNT] = ''
183
+ add_payment_method(post, payment_object)
184
+ post[:TRANS_TYPE] = 'CREDIT'
185
+
186
+ post[:NAME1] = (options[:first_name] ? options[:first_name] : "")
187
+ post[:NAME2] = options[:last_name] if options[:last_name]
188
+ post[:ZIP] = options[:zip] if options[:zip]
189
+ add_invoice(post, options)
190
+ add_address(post, options)
191
+ add_customer_data(post, options)
192
+ commit('CREDIT', money, post)
193
+ end
194
+
195
+ # Create a new recurring payment.
196
+ #
197
+ # ==== Parameters
198
+ #
199
+ # * <tt>money</tt> -- The amount to charge the customer at the time of the recurring payment setup, in cents. Set to zero if you do not want the customer to be charged at this time.
200
+ # * <tt>payment_object</tt> -- This can either be one of three things:
201
+ # A CreditCard object,
202
+ # A Check object,
203
+ # or a token. The token is called the Master ID. This is a unique transaction ID returned from a previous transaction. This token associates all the stored information for a previous transaction.
204
+ # * <tt>options</tt> -- A hash of optional parameters.,
205
+
206
+ # ==== Options
207
+ #
208
+ # * <tt>:rebill_start_date</tt> is a string that tells the gateway when to start the rebill. (REQUIRED)
209
+ # Has two valid formats:
210
+ # "YYYY-MM-DD HH:MM:SS" Hours, minutes, and seconds are optional.
211
+ # "XX UNITS" Relative date as explained below. Marked from the time of the
212
+ # transaction (i.e.: 10 DAYS, 1 MONTH, 1 YEAR)
213
+ # * <tt>:rebill_expression</tt> is the period of time in-between rebillings. (REQUIRED)
214
+ # It uses the same "XX UNITS" format as rebill_start_date, explained above.
215
+ # Optional parameters include:
216
+ # * <tt>rebill_cycles</tt>: Number of times to rebill. Don't send or set to nil for infinite rebillings (or
217
+ # until canceled).
218
+ # * <tt>rebill_amount</tt>: Amount to rebill. Defaults to amount of transaction for rebillings.
219
+ #
220
+ # For example, to charge the customer $19.95 now and then charge $39.95 in 60 days every 3 months for 5 times, the options hash would be as follows:
221
+ # :rebill_start_date => '60 DAYS',
222
+ # :rebill_expression => '3 MONTHS',
223
+ # :rebill_cycles => '5',
224
+ # :rebill_amount => '39.95'
225
+ # A money object of 1995 cents would be passed into the 'money' parameter.
226
+ def recurring(money, payment_object, options = {})
227
+ ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE
228
+
229
+ requires!(options, :rebill_start_date, :rebill_expression)
230
+ options[:rebill] = true
231
+ if money
232
+ purchase(money, payment_object, options)
233
+ else
234
+ authorize(money, payment_object, options)
235
+ end
236
+ end
237
+
238
+ # View a recurring payment
239
+ #
240
+ # This will pull data associated with a current recurring billing
241
+ #
242
+ # ==== Parameters
243
+ #
244
+ # * <tt>rebill_id</tt> -- A string containing the rebill_id of the recurring billing that is already active (REQUIRED)
245
+ def status_recurring(rebill_id)
246
+ ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE
247
+
248
+ post = {}
249
+ requires!(rebill_id)
250
+ post[:REBILL_ID] = rebill_id
251
+ post[:TRANS_TYPE] = 'GET'
252
+ commit('rebill', 'nil', post)
253
+ end
254
+
255
+ # Update a recurring payment's details.
256
+ #
257
+ # This transaction updates an existing recurring billing
258
+ #
259
+ # ==== Options
260
+ #
261
+ # * <tt>:rebill_id</tt> -- The 12 digit rebill ID used to update a particular rebilling cycle. (REQUIRED)
262
+ # * <tt>:rebill_amount</tt> -- A string containing the new rebilling amount.
263
+ # * <tt>:rebill_next_date</tt> -- A string containing the new rebilling next date.
264
+ # * <tt>:rebill_expression</tt> -- A string containing the new rebilling expression.
265
+ # * <tt>:rebill_cycles</tt> -- A string containing the new rebilling cycles.
266
+ # * <tt>:rebill_next_amount</tt> -- A string containing the next rebilling amount to charge the customer. This ONLY affects the next scheduled charge; all other rebillings will continue at the regular (rebill_amount) amount.
267
+ # Take a look above at the recurring_payment method for similar examples on how to use.
268
+ def update_recurring(options = {})
269
+ ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE
270
+
271
+ post = {}
272
+ requires!(options, :rebill_id)
273
+ post[:REBILL_ID] = options[:rebill_id]
274
+ post[:TRANS_TYPE] = 'SET'
275
+ post[:REB_AMOUNT] = amount(options[:rebill_amount]) if options[:rebill_amount]
276
+ post[:NEXT_DATE] = options[:rebill_next_date]
277
+ post[:REB_EXPR] = options[:rebill_expression]
278
+ post[:REB_CYCLES] = options[:rebill_cycles]
279
+ post[:NEXT_AMOUNT] = options[:rebill_next_amount]
280
+ commit('rebill', 'nil', post)
281
+ end
282
+
283
+ # Cancel a recurring payment.
284
+ #
285
+ # This transaction cancels an existing recurring billing.
286
+ #
287
+ # ==== Parameters
288
+ #
289
+ # * <tt>rebill_id</tt> -- A string containing the rebill_id of the recurring billing that you wish to cancel/stop (REQUIRED)
290
+ def cancel_recurring(rebill_id)
291
+ ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE
292
+
293
+ post = {}
294
+ requires!(rebill_id)
295
+ post[:REBILL_ID] = rebill_id
296
+ post[:TRANS_TYPE] = 'SET'
297
+ post[:STATUS] = 'stopped'
298
+ commit('rebill', 'nil', post)
299
+ end
300
+
301
+ def supports_scrubbing
302
+ true
303
+ end
304
+
305
+ def scrub(transcript)
306
+ transcript.
307
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
308
+ gsub(%r((&?card_num=)[^&]*)i, '\1[FILTERED]').
309
+ gsub(%r((&?CARD_CVV2=)[^&]*)i, '\1[FILTERED]').
310
+ gsub(%r((&?PAYMENT_ACCOUNT=)[^&]*)i, '\1[FILTERED]').
311
+ gsub(%r((&?TAMPER_PROOF_SEAL=)[^&"]*)i, '\1[FILTERED]')
312
+ end
313
+
314
+ private
315
+
316
+ def commit(action, money, fields)
317
+ fields[:AMOUNT] = amount(money) unless(fields[:TRANS_TYPE] == 'VOID' || action == 'rebill')
318
+ fields[:MODE] = (test? ? 'TEST' : 'LIVE')
319
+ fields[:ACCOUNT_ID] = @options[:login]
320
+
321
+ if action == 'rebill'
322
+ url = rebilling_url
323
+ fields[:TAMPER_PROOF_SEAL] = calc_rebill_tps(fields)
324
+ else
325
+ url = live_url
326
+ fields[:TAMPER_PROOF_SEAL] = calc_tps(amount(money), fields)
327
+ end
328
+ parse(ssl_post(url, post_data(action, fields)))
329
+ end
330
+
331
+ def parse_recurring(response_fields, opts={}) # expected status?
332
+ parsed = {}
333
+ response_fields.each do |k,v|
334
+ mapped_key = REBILL_FIELD_MAP.include?(k) ? REBILL_FIELD_MAP[k] : k
335
+ parsed[mapped_key] = v
336
+ end
337
+
338
+ success = parsed[:status] != 'error'
339
+ message = parsed[:status]
340
+
341
+ Response.new(success, message, parsed,
342
+ :test => test?,
343
+ :authorization => parsed[:rebill_id])
344
+ end
345
+
346
+ def parse(body)
347
+ # The bp20api has max one value per form field.
348
+ response_fields = Hash[CGI::parse(body).map{|k,v| [k.upcase,v.first]}]
349
+
350
+ if response_fields.include? "REBILL_ID"
351
+ return parse_recurring(response_fields)
352
+ end
353
+
354
+ parsed = {}
355
+ response_fields.each do |k,v|
356
+ mapped_key = FIELD_MAP.include?(k) ? FIELD_MAP[k] : k
357
+ parsed[mapped_key] = v
358
+ end
359
+
360
+ # normalize message
361
+ message = message_from(parsed)
362
+ success = parsed[:response_code] == '1'
363
+ Response.new(success, message, parsed,
364
+ :test => test?,
365
+ :authorization => (parsed[:rebid] && parsed[:rebid] != '' ? parsed[:rebid] : parsed[:transaction_id]),
366
+ :avs_result => { :code => parsed[:avs_result_code] },
367
+ :cvv_result => parsed[:card_code]
368
+ )
369
+ end
370
+
371
+ def message_from(parsed)
372
+ message = parsed[:message]
373
+ if(parsed[:response_code].to_i == 2)
374
+ if CARD_CODE_ERRORS.include?(parsed[:card_code])
375
+ message = CVVResult.messages[parsed[:card_code]]
376
+ elsif AVS_ERRORS.include?(parsed[:avs_result_code])
377
+ message = AVSResult.messages[ parsed[:avs_result_code] ]
378
+ else
379
+ message = message.chomp('.')
380
+ end
381
+ elsif message == "Missing ACCOUNT_ID"
382
+ message = "The merchant login ID or password is invalid"
383
+ elsif message =~ /Approved/
384
+ message = "This transaction has been approved"
385
+ elsif message =~ /Expired/
386
+ message = "The credit card has expired"
387
+ end
388
+ message
389
+ end
390
+
391
+ def add_invoice(post, options)
392
+ post[:ORDER_ID] = options[:order_id]
393
+ post[:INVOICE_ID] = options[:invoice]
394
+ post[:invoice_num] = options[:order_id]
395
+ post[:MEMO] = options[:description]
396
+ post[:description] = options[:description]
397
+ end
398
+
399
+ def add_payment_method(post, payment_object)
400
+ post[:MASTER_ID] = ''
401
+ case payment_object
402
+ when String
403
+ post[:MASTER_ID] = payment_object
404
+ when Check
405
+ add_check(post, payment_object)
406
+ else
407
+ add_creditcard(post, payment_object)
408
+ end
409
+ end
410
+
411
+ def add_creditcard(post, creditcard)
412
+ post[:PAYMENT_TYPE] = 'CREDIT'
413
+ post[:PAYMENT_ACCOUNT] = creditcard.number
414
+ post[:CARD_CVV2] = creditcard.verification_value
415
+ post[:CARD_EXPIRE] = expdate(creditcard)
416
+ post[:NAME1] = creditcard.first_name
417
+ post[:NAME2] = creditcard.last_name
418
+ end
419
+
420
+ CHECK_ACCOUNT_TYPES = {
421
+ "checking" => "C",
422
+ "savings" => "S"
423
+ }
424
+
425
+ def add_check(post, check)
426
+ post[:PAYMENT_TYPE] = 'ACH'
427
+ post[:PAYMENT_ACCOUNT] = [CHECK_ACCOUNT_TYPES[check.account_type], check.routing_number, check.account_number].join(":")
428
+ post[:NAME1] = check.first_name
429
+ post[:NAME2] = check.last_name
430
+ end
431
+
432
+ def add_customer_data(post, options)
433
+ post[:EMAIL] = options[:email]
434
+ post[:CUSTOM_ID] = options[:customer]
435
+ post[:CUSTOM_ID2] = options[:custom_id2]
436
+ end
437
+
438
+ def add_duplicate_override(post, options)
439
+ post[:DUPLICATE_OVERRIDE] = options[:duplicate_override]
440
+ end
441
+
442
+ def add_address(post, options)
443
+ if address = (options[:shipping_address] || options[:billing_address] || options[:address])
444
+ post[:ADDR1] = address[:address1]
445
+ post[:ADDR2] = address[:address2]
446
+ post[:COMPANY_NAME] = address[:company]
447
+ post[:PHONE] = address[:phone]
448
+ post[:CITY] = address[:city]
449
+ post[:STATE] = (address[:state].blank? ? 'n/a' : address[:state])
450
+ post[:ZIP] = address[:zip]
451
+ post[:COUNTRY] = address[:country]
452
+ end
453
+ end
454
+
455
+ def add_rebill(post, options)
456
+ post[:DO_REBILL] = '1'
457
+ post[:REB_AMOUNT] = amount(options[:rebill_amount])
458
+ post[:REB_FIRST_DATE] = options[:rebill_start_date]
459
+ post[:REB_EXPR] = options[:rebill_expression]
460
+ post[:REB_CYCLES] = options[:rebill_cycles]
461
+ end
462
+
463
+ def post_data(action, parameters = {})
464
+ post = {}
465
+ post[:version] = '1'
466
+ post[:login] = ''
467
+ post[:tran_key] = ''
468
+ post[:relay_response] = "FALSE"
469
+ post[:type] = action
470
+ post[:delim_data] = "TRUE"
471
+ post[:delim_char] = ","
472
+ post[:encap_char] = "$"
473
+ post[:card_num] = '4111111111111111'
474
+ post[:exp_date] = '1212'
475
+ post[:solution_ID] = application_id if application_id
476
+ post.merge(parameters).collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
477
+ end
478
+
479
+ def expdate(creditcard)
480
+ year = format(creditcard.year, :two_digits)
481
+ month = format(creditcard.month, :two_digits)
482
+
483
+ "#{month}#{year}"
484
+ end
485
+
486
+ def calc_tps(amount, post)
487
+ post[:NAME1] ||= ''
488
+ Digest::MD5.hexdigest(
489
+ [
490
+ @options[:password],
491
+ @options[:login],
492
+ post[:TRANS_TYPE],
493
+ amount,
494
+ post[:MASTER_ID],
495
+ post[:NAME1],
496
+ post[:PAYMENT_ACCOUNT]
497
+ ].join("")
498
+ )
499
+ end
500
+
501
+ def calc_rebill_tps(post)
502
+ Digest::MD5.hexdigest(
503
+ [
504
+ @options[:password],
505
+ @options[:login],
506
+ post[:TRANS_TYPE],
507
+ post[:REBILL_ID]
508
+ ].join("")
509
+ )
510
+ end
511
+
512
+ def handle_response(response)
513
+ if ignore_http_status || (200...300).include?(response.code.to_i)
514
+ return response.body
515
+ end
516
+ raise ResponseError.new(response)
517
+ end
518
+ end
519
+ end
520
+ end