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,474 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module BeanstreamCore
4
+ include Empty
5
+
6
+ RECURRING_URL = 'https://www.beanstream.com/scripts/recurring_billing.asp'
7
+ SECURE_PROFILE_URL = 'https://www.beanstream.com/scripts/payment_profile.asp'
8
+
9
+ SP_SERVICE_VERSION = '1.1'
10
+
11
+ TRANSACTIONS = {
12
+ authorization: 'PA',
13
+ purchase: 'P',
14
+ capture: 'PAC',
15
+ refund: 'R',
16
+ void: 'VP',
17
+ check_purchase: 'D',
18
+ check_refund: 'C',
19
+ void_purchase: 'VP',
20
+ void_refund: 'VR'
21
+ }
22
+
23
+ PROFILE_OPERATIONS = {
24
+ new: 'N',
25
+ modify: 'M'
26
+ }
27
+
28
+ CVD_CODES = {
29
+ '1' => 'M',
30
+ '2' => 'N',
31
+ '3' => 'I',
32
+ '4' => 'S',
33
+ '5' => 'U',
34
+ '6' => 'P'
35
+ }
36
+
37
+ AVS_CODES = {
38
+ '0' => 'R',
39
+ '5' => 'I',
40
+ '9' => 'I'
41
+ }
42
+
43
+ PERIODS = {
44
+ days: 'D',
45
+ weeks: 'W',
46
+ months: 'M',
47
+ years: 'Y'
48
+ }
49
+
50
+ PERIODICITIES = {
51
+ daily: [:days, 1],
52
+ weekly: [:weeks, 1],
53
+ biweekly: [:weeks, 2],
54
+ monthly: [:months, 1],
55
+ bimonthly: [:months, 2],
56
+ yearly: [:years, 1]
57
+ }
58
+
59
+ RECURRING_OPERATION = {
60
+ update: 'M',
61
+ cancel: 'C'
62
+ }
63
+
64
+ STATES = {
65
+ 'ALBERTA' => 'AB',
66
+ 'BRITISH COLUMBIA' => 'BC',
67
+ 'MANITOBA' => 'MB',
68
+ 'NEW BRUNSWICK' => 'NB',
69
+ 'NEWFOUNDLAND AND LABRADOR' => 'NL',
70
+ 'NOVA SCOTIA' => 'NS',
71
+ 'ONTARIO' => 'ON',
72
+ 'PRINCE EDWARD ISLAND' => 'PE',
73
+ 'QUEBEC' => 'QC',
74
+ 'SASKATCHEWAN' => 'SK',
75
+ 'NORTHWEST TERRITORIES' => 'NT',
76
+ 'NUNAVUT' => 'NU',
77
+ 'YUKON' => 'YT',
78
+ 'ALABAMA' => 'AL',
79
+ 'ALASKA' => 'AK',
80
+ 'ARIZONA' => 'AZ',
81
+ 'ARKANSAS' => 'AR',
82
+ 'CALIFORNIA' => 'CA',
83
+ 'COLORADO' => 'CO',
84
+ 'CONNECTICUT' => 'CT',
85
+ 'DELAWARE' => 'DE',
86
+ 'FLORIDA' => 'FL',
87
+ 'GEORGIA' => 'GA',
88
+ 'HAWAII' => 'HI',
89
+ 'IDAHO' => 'ID',
90
+ 'ILLINOIS' => 'IL',
91
+ 'INDIANA' => 'IN',
92
+ 'IOWA' => 'IA',
93
+ 'KANSAS' => 'KS',
94
+ 'KENTUCKY' => 'KY',
95
+ 'LOUISIANA' => 'LA',
96
+ 'MAINE' => 'ME',
97
+ 'MARYLAND' => 'MD',
98
+ 'MASSACHUSETTS' => 'MA',
99
+ 'MICHIGAN' => 'MI',
100
+ 'MINNESOTA' => 'MN',
101
+ 'MISSISSIPPI' => 'MS',
102
+ 'MISSOURI' => 'MO',
103
+ 'MONTANA' => 'MT',
104
+ 'NEBRASKA' => 'NE',
105
+ 'NEVADA' => 'NV',
106
+ 'NEW HAMPSHIRE' => 'NH',
107
+ 'NEW JERSEY' => 'NJ',
108
+ 'NEW MEXICO' => 'NM',
109
+ 'NEW YORK' => 'NY',
110
+ 'NORTH CAROLINA' => 'NC',
111
+ 'NORTH DAKOTA' => 'ND',
112
+ 'OHIO' => 'OH',
113
+ 'OKLAHOMA' => 'OK',
114
+ 'OREGON' => 'OR',
115
+ 'PENNSYLVANIA' => 'PA',
116
+ 'RHODE ISLAND' => 'RI',
117
+ 'SOUTH CAROLINA' => 'SC',
118
+ 'SOUTH DAKOTA' => 'SD',
119
+ 'TENNESSEE' => 'TN',
120
+ 'TEXAS' => 'TX',
121
+ 'UTAH' => 'UT',
122
+ 'VERMONT' => 'VT',
123
+ 'VIRGINIA' => 'VA',
124
+ 'WASHINGTON' => 'WA',
125
+ 'WEST VIRGINIA' => 'WV',
126
+ 'WISCONSIN' => 'WI',
127
+ 'WYOMING' => 'WY'
128
+ }
129
+
130
+ def self.included(base)
131
+ base.default_currency = 'CAD'
132
+
133
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
134
+ base.supported_countries = %w[CA US]
135
+
136
+ # The card types supported by the payment gateway
137
+ base.supported_cardtypes = %i[visa master american_express discover diners_club jcb]
138
+
139
+ # The homepage URL of the gateway
140
+ base.homepage_url = 'http://www.beanstream.com/'
141
+ base.live_url = 'https://api.na.bambora.com/scripts/process_transaction.asp'
142
+
143
+ # The name of the gateway
144
+ base.display_name = 'Beanstream.com'
145
+ end
146
+
147
+ # Only <tt>:login</tt> is required by default,
148
+ # which is the merchant's merchant ID. If you'd like to perform void,
149
+ # capture or refund transactions then you'll also need to add a username
150
+ # and password to your account under administration -> account settings ->
151
+ # order settings -> Use username/password validation
152
+ def initialize(options = {})
153
+ requires!(options, :login)
154
+ super
155
+ end
156
+
157
+ def capture(money, authorization, options = {})
158
+ reference, = split_auth(authorization)
159
+ post = {}
160
+ add_amount(post, money)
161
+ add_reference(post, reference)
162
+ add_transaction_type(post, :capture)
163
+ add_recurring_payment(post, options)
164
+ commit(post)
165
+ end
166
+
167
+ def refund(money, source, options = {})
168
+ post = {}
169
+ reference, _, type = split_auth(source)
170
+ add_reference(post, reference)
171
+ add_transaction_type(post, refund_action(type))
172
+ add_amount(post, money)
173
+ commit(post)
174
+ end
175
+
176
+ def credit(money, source, options = {})
177
+ ActiveMerchant.deprecated Gateway::CREDIT_DEPRECATION_MESSAGE
178
+ refund(money, source, options)
179
+ end
180
+
181
+ private
182
+
183
+ def purchase_action(source)
184
+ if source.is_a?(Check)
185
+ :check_purchase
186
+ else
187
+ :purchase
188
+ end
189
+ end
190
+
191
+ def add_customer_ip(post, options)
192
+ post[:customerIp] = options[:ip] if options[:ip]
193
+ end
194
+
195
+ def void_action(original_transaction_type)
196
+ original_transaction_type == TRANSACTIONS[:refund] ? :void_refund : :void_purchase
197
+ end
198
+
199
+ def refund_action(type)
200
+ type == TRANSACTIONS[:check_purchase] ? :check_refund : :refund
201
+ end
202
+
203
+ def secure_profile_action(type)
204
+ PROFILE_OPERATIONS[type] || PROFILE_OPERATIONS[:new]
205
+ end
206
+
207
+ def split_auth(string)
208
+ string.split(';')
209
+ end
210
+
211
+ def add_amount(post, money)
212
+ post[:trnAmount] = amount(money)
213
+ end
214
+
215
+ def add_original_amount(post, amount)
216
+ post[:trnAmount] = amount
217
+ end
218
+
219
+ def add_reference(post, reference)
220
+ post[:adjId] = reference
221
+ end
222
+
223
+ def add_address(post, options)
224
+ post[:ordEmailAddress] = options[:email] if options[:email]
225
+ post[:shipEmailAddress] = options[:shipping_email] || options[:email] if options[:email]
226
+
227
+ prepare_address_for_non_american_countries(options)
228
+
229
+ if billing_address = options[:billing_address] || options[:address]
230
+ post[:ordName] = billing_address[:name]
231
+ post[:ordPhoneNumber] = billing_address[:phone]
232
+ post[:ordAddress1] = billing_address[:address1]
233
+ post[:ordAddress2] = billing_address[:address2]
234
+ post[:ordCity] = billing_address[:city]
235
+ post[:ordProvince] = state_for(billing_address)
236
+ post[:ordPostalCode] = billing_address[:zip]
237
+ post[:ordCountry] = billing_address[:country]
238
+ end
239
+
240
+ if shipping_address = options[:shipping_address]
241
+ post[:shipName] = shipping_address[:name]
242
+ post[:shipPhoneNumber] = shipping_address[:phone]
243
+ post[:shipAddress1] = shipping_address[:address1]
244
+ post[:shipAddress2] = shipping_address[:address2]
245
+ post[:shipCity] = shipping_address[:city]
246
+ post[:shipProvince] = state_for(shipping_address)
247
+ post[:shipPostalCode] = shipping_address[:zip]
248
+ post[:shipCountry] = shipping_address[:country]
249
+ post[:shippingMethod] = shipping_address[:shipping_method]
250
+ post[:deliveryEstimate] = shipping_address[:delivery_estimate]
251
+ end
252
+ end
253
+
254
+ def state_for(address)
255
+ STATES[address[:state].upcase] || address[:state] if address[:state]
256
+ end
257
+
258
+ def prepare_address_for_non_american_countries(options)
259
+ [options[:billing_address], options[:shipping_address]].compact.each do |address|
260
+ next if empty?(address[:country])
261
+
262
+ unless %w[US CA].include?(address[:country])
263
+ address[:state] = '--'
264
+ address[:zip] = '000000' unless address[:zip]
265
+ end
266
+ end
267
+ end
268
+
269
+ def add_recurring_payment(post, options)
270
+ post[:recurringPayment] = 1 if options[:recurring].to_s == 'true'
271
+ end
272
+
273
+ def add_invoice(post, options)
274
+ post[:trnOrderNumber] = options[:order_id]
275
+ post[:trnComments] = options[:description]
276
+ post[:ordItemPrice] = amount(options[:subtotal])
277
+ post[:ordShippingPrice] = amount(options[:shipping])
278
+ post[:ordTax1Price] = amount(options[:tax1] || options[:tax])
279
+ post[:ordTax2Price] = amount(options[:tax2])
280
+ post[:ref1] = options[:custom]
281
+ end
282
+
283
+ def add_credit_card(post, credit_card)
284
+ if credit_card
285
+ post[:trnCardOwner] = credit_card.name
286
+ post[:trnCardNumber] = credit_card.number
287
+ post[:trnExpMonth] = format(credit_card.month, :two_digits)
288
+ post[:trnExpYear] = format(credit_card.year, :two_digits)
289
+ post[:trnCardCvd] = credit_card.verification_value
290
+ if credit_card.is_a?(NetworkTokenizationCreditCard)
291
+ post[:"3DSecureXID"] = credit_card.transaction_id
292
+ post[:"3DSecureECI"] = credit_card.eci
293
+ post[:"3DSecureCAVV"] = credit_card.payment_cryptogram
294
+ end
295
+ end
296
+ end
297
+
298
+ def add_check(post, check)
299
+ # The institution number of the consumer’s financial institution. Required for Canadian dollar EFT transactions.
300
+ post[:institutionNumber] = check.institution_number
301
+
302
+ # The bank transit number of the consumer’s bank account. Required for Canadian dollar EFT transactions.
303
+ post[:transitNumber] = check.transit_number
304
+
305
+ # The routing number of the consumer’s bank account. Required for US dollar EFT transactions.
306
+ post[:routingNumber] = check.routing_number
307
+
308
+ # The account number of the consumer’s bank account. Required for both Canadian and US dollar EFT transactions.
309
+ post[:accountNumber] = check.account_number
310
+ end
311
+
312
+ def add_secure_profile_variables(post, options = {})
313
+ post[:serviceVersion] = SP_SERVICE_VERSION
314
+ post[:responseFormat] = 'QS'
315
+ post[:cardValidation] = (options[:cardValidation].to_i == 1) || '0'
316
+ post[:operationType] = options[:operationType] || options[:operation] || secure_profile_action(:new)
317
+ post[:customerCode] = options[:billing_id] || options[:vault_id] || false
318
+ post[:status] = options[:status]
319
+
320
+ billing_address = options[:billing_address] || options[:address]
321
+ post[:trnCardOwner] = billing_address ? billing_address[:name] : nil
322
+ end
323
+
324
+ def add_recurring_amount(post, money)
325
+ post[:amount] = amount(money)
326
+ end
327
+
328
+ def add_recurring_invoice(post, options)
329
+ post[:rbApplyTax1] = options[:apply_tax1]
330
+ post[:rbApplyTax2] = options[:apply_tax2]
331
+ end
332
+
333
+ def add_recurring_operation_type(post, operation)
334
+ post[:operationType] = RECURRING_OPERATION[operation]
335
+ end
336
+
337
+ def add_recurring_service(post, options)
338
+ post[:serviceVersion] = '1.0'
339
+ post[:merchantId] = @options[:login]
340
+ post[:passCode] = @options[:recurring_api_key]
341
+ post[:rbAccountId] = options[:account_id]
342
+ end
343
+
344
+ def add_recurring_type(post, options)
345
+ # XXX requires!
346
+ post[:trnRecurring] = 1
347
+ period, increment = interval(options)
348
+ post[:rbBillingPeriod] = PERIODS[period]
349
+ post[:rbBillingIncrement] = increment
350
+
351
+ if options.include? :start_date
352
+ post[:rbCharge] = 0
353
+ post[:rbFirstBilling] = options[:start_date].strftime('%m%d%Y')
354
+ end
355
+
356
+ if count = options[:occurrences] || options[:payments]
357
+ post[:rbExpiry] = (options[:start_date] || Date.current).advance(period => count).strftime('%m%d%Y')
358
+ end
359
+ end
360
+
361
+ def interval(options)
362
+ if options.include? :periodicity
363
+ requires!(options, [:periodicity, *PERIODICITIES.keys])
364
+ PERIODICITIES[options[:periodicity]]
365
+ elsif options.include? :interval
366
+ interval = options[:interval]
367
+ if interval.respond_to? :parts
368
+ parts = interval.parts
369
+ raise ArgumentError.new("Cannot recur with mixed interval (#{interval}). Use only one of: days, weeks, months or years") if parts.length > 1
370
+
371
+ parts.first
372
+ elsif interval.kind_of? Hash
373
+ requires!(interval, :unit)
374
+ unit, length = interval.values_at(:unit, :length)
375
+ length ||= 1
376
+ [unit, length]
377
+ end
378
+ end
379
+ end
380
+
381
+ def parse(body)
382
+ results = {}
383
+ body&.split(/&/)&.each do |pair|
384
+ key, val = pair.split(/\=/)
385
+ results[key.to_sym] = val.nil? ? nil : CGI.unescape(val)
386
+ end
387
+
388
+ # Clean up the message text if there is any
389
+ if results[:messageText]
390
+ results[:messageText].gsub!(/<LI>/, '')
391
+ results[:messageText].gsub!(/(\.)?<br>/, '. ')
392
+ results[:messageText].strip!
393
+ end
394
+
395
+ results
396
+ end
397
+
398
+ def recurring_parse(data)
399
+ REXML::Document.new(data).root.elements.to_a.inject({}) do |response, element|
400
+ response[element.name.to_sym] = element.text
401
+ response
402
+ end
403
+ end
404
+
405
+ def commit(params, use_profile_api = false)
406
+ post(post_data(params, use_profile_api), use_profile_api)
407
+ end
408
+
409
+ def recurring_commit(params)
410
+ recurring_post(post_data(params, false))
411
+ end
412
+
413
+ def post(data, use_profile_api = nil)
414
+ response = parse(ssl_post((use_profile_api ? SECURE_PROFILE_URL : self.live_url), data))
415
+ response[:customer_vault_id] = response[:customerCode] if response[:customerCode]
416
+ build_response(success?(response), message_from(response), response,
417
+ test: test? || response[:authCode] == 'TEST',
418
+ authorization: authorization_from(response),
419
+ cvv_result: CVD_CODES[response[:cvdId]],
420
+ avs_result: { code: AVS_CODES.include?(response[:avsId]) ? AVS_CODES[response[:avsId]] : response[:avsId] })
421
+ end
422
+
423
+ def recurring_post(data)
424
+ response = recurring_parse(ssl_post(RECURRING_URL, data))
425
+ build_response(recurring_success?(response), recurring_message_from(response), response)
426
+ end
427
+
428
+ def authorization_from(response)
429
+ "#{response[:trnId]};#{response[:trnAmount]};#{response[:trnType]}"
430
+ end
431
+
432
+ def message_from(response)
433
+ response[:messageText] || response[:responseMessage]
434
+ end
435
+
436
+ def recurring_message_from(response)
437
+ response[:message]
438
+ end
439
+
440
+ def recurring_success?(response)
441
+ response[:code] == '1'
442
+ end
443
+
444
+ def add_source(post, source)
445
+ if source.is_a?(String) || source.is_a?(Integer)
446
+ post[:customerCode] = source
447
+ else
448
+ card_brand(source) == 'check' ? add_check(post, source) : add_credit_card(post, source)
449
+ end
450
+ end
451
+
452
+ def add_transaction_type(post, action)
453
+ post[:trnType] = TRANSACTIONS[action]
454
+ end
455
+
456
+ def post_data(params, use_profile_api)
457
+ params[:requestType] = 'BACKEND'
458
+ if use_profile_api
459
+ params[:merchantId] = @options[:login]
460
+ params[:passCode] = @options[:secure_profile_api_key]
461
+ else
462
+ params[:username] = @options[:user] if @options[:user]
463
+ params[:password] = @options[:password] if @options[:password]
464
+ params[:merchant_id] = @options[:login]
465
+ params[:passcode] = @options[:api_key]
466
+ end
467
+ params[:vbvEnabled] = '0'
468
+ params[:scEnabled] = '0'
469
+
470
+ params.reject { |_k, v| v.blank? }.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&')
471
+ end
472
+ end
473
+ end
474
+ end