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,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/braintree/braintree_common'
1
+ require 'active_merchant/billing/gateways/braintree/braintree_common'
2
2
 
3
3
  begin
4
4
  require "braintree"
@@ -6,7 +6,9 @@ rescue LoadError
6
6
  raise "Could not load the braintree gem. Use `gem install braintree` to install it."
7
7
  end
8
8
 
9
- raise "Need braintree gem 2.x.y. Run `gem install braintree --version '~>2.0'` to get the correct version." unless Braintree::Version::Major == 2
9
+ unless Braintree::Version::Major == 2 && Braintree::Version::Minor >= 78
10
+ raise "Need braintree gem >= 2.78.0. Run `gem install braintree --version '~>2.78'` to get the correct version."
11
+ end
10
12
 
11
13
  module ActiveMerchant #:nodoc:
12
14
  module Billing #:nodoc:
@@ -23,56 +25,51 @@ module ActiveMerchant #:nodoc:
23
25
  # Setting an ActiveMerchant +wiredump_device+ will automatically
24
26
  # configure the Braintree logger (via the Braintree gem's
25
27
  # configuration) when the BraintreeBlueGateway is instantiated.
26
- # Additionally, the log level will be set to +DEBUG+. Therefore,
27
- # all you have to do is set the +wiredump_device+ and you'll
28
- # get your debug output from your HTTP interactions with the
29
- # remote gateway. (Don't enable this in production.)
30
- #
31
- # For example:
32
- #
33
- # ActiveMerchant::Billing::BraintreeBlueGateway.wiredump_device = Logger.new(STDOUT)
34
- # # => #<Logger:0x107d385f8 ...>
35
- #
36
- # Braintree::Configuration.logger
37
- # # => (some other logger, created by default by the gem)
38
- #
39
- # Braintree::Configuration.logger.level
40
- # # => 1 (INFO)
28
+ # Additionally, the log level will be set to +DEBUG+. Therefore,
29
+ # all you have to do is set the +wiredump_device+ and you'll get
30
+ # your debug output from your HTTP interactions with the remote
31
+ # gateway. (Don't enable this in production.) The ActiveMerchant
32
+ # implementation doesn't mess with the Braintree::Configuration
33
+ # globals at all, so there won't be any side effects outside
34
+ # Active Merchant.
41
35
  #
42
- # ActiveMerchant::Billing::BraintreeBlueGateway.new(:merchant_id => 'x', :public_key => 'x', :private_key => 'x')
36
+ # If no +wiredump_device+ is set, the logger in
37
+ # +Braintree::Configuration.logger+ will be cloned and the log
38
+ # level set to +WARN+.
43
39
  #
44
- # Braintree::Configuration.logger
45
- # # => #<Logger:0x107d385f8 ...>
46
- #
47
- # Braintree::Configuration.logger.level
48
- # # => 0 (DEBUG)
49
- #
50
- # Alternatively, you can avoid setting the +wiredump_device+
51
- # and set +Braintree::Configuration.logger+ and/or
52
- # +Braintree::Configuration.logger.level+ directly.
53
40
  class BraintreeBlueGateway < Gateway
54
41
  include BraintreeCommon
55
42
 
56
43
  self.display_name = 'Braintree (Blue Platform)'
57
44
 
45
+ ERROR_CODES = {
46
+ cannot_refund_if_unsettled: 91506
47
+ }
48
+
58
49
  def initialize(options = {})
59
50
  requires!(options, :merchant_id, :public_key, :private_key)
60
51
  @merchant_account_id = options[:merchant_account_id]
61
52
 
62
53
  super
63
54
 
64
- Braintree::Configuration.merchant_id = options[:merchant_id]
65
- Braintree::Configuration.public_key = options[:public_key]
66
- Braintree::Configuration.private_key = options[:private_key]
67
- Braintree::Configuration.environment = (options[:environment] || (test? ? :sandbox : :production)).to_sym
68
- Braintree::Configuration.custom_user_agent = "ActiveMerchant #{ActiveMerchant::VERSION}"
69
-
70
- if wiredump_device
71
- Braintree::Configuration.logger = ((Logger === wiredump_device) ? wiredump_device : Logger.new(wiredump_device))
72
- Braintree::Configuration.logger.level = Logger::DEBUG
55
+ if wiredump_device.present?
56
+ logger = ((Logger === wiredump_device) ? wiredump_device : Logger.new(wiredump_device))
57
+ logger.level = Logger::DEBUG
73
58
  else
74
- Braintree::Configuration.logger.level = Logger::WARN
59
+ logger = Braintree::Configuration.logger.clone
60
+ logger.level = Logger::WARN
75
61
  end
62
+
63
+ @configuration = Braintree::Configuration.new(
64
+ :merchant_id => options[:merchant_id],
65
+ :public_key => options[:public_key],
66
+ :private_key => options[:private_key],
67
+ :environment => (options[:environment] || (test? ? :sandbox : :production)).to_sym,
68
+ :custom_user_agent => "ActiveMerchant #{ActiveMerchant::VERSION}",
69
+ :logger => options[:logger] || logger,
70
+ )
71
+
72
+ @braintree_gateway = Braintree::Gateway.new( @configuration )
76
73
  end
77
74
 
78
75
  def authorize(money, credit_card_or_vault_id, options = {})
@@ -81,8 +78,8 @@ module ActiveMerchant #:nodoc:
81
78
 
82
79
  def capture(money, authorization, options = {})
83
80
  commit do
84
- result = Braintree::Transaction.submit_for_settlement(authorization, amount(money).to_s)
85
- Response.new(result.success?, message_from_result(result))
81
+ result = @braintree_gateway.transaction.submit_for_settlement(authorization, localized_amount(money, options[:currency] || default_currency).to_s)
82
+ response_from_result(result)
86
83
  end
87
84
  end
88
85
 
@@ -97,61 +94,59 @@ module ActiveMerchant #:nodoc:
97
94
  def refund(*args)
98
95
  # legacy signature: #refund(transaction_id, options = {})
99
96
  # new signature: #refund(money, transaction_id, options = {})
100
- money, transaction_id, _ = extract_refund_args(args)
101
- money = amount(money).to_s if money
97
+ money, transaction_id, options = extract_refund_args(args)
98
+ money = localized_amount(money, options[:currency] || default_currency).to_s if money
102
99
 
103
100
  commit do
104
- result = Braintree::Transaction.refund(transaction_id, money)
105
- Response.new(result.success?, message_from_result(result),
106
- {:braintree_transaction => (transaction_hash(result.transaction) if result.success?)},
107
- {:authorization => (result.transaction.id if result.success?)}
108
- )
101
+ response = response_from_result(@braintree_gateway.transaction.refund(transaction_id, money))
102
+ return response if response.success?
103
+ return response unless options[:force_full_refund_if_unsettled]
104
+
105
+ void(transaction_id) if response.message =~ /#{ERROR_CODES[:cannot_refund_if_unsettled]}/
109
106
  end
110
107
  end
111
108
 
112
109
  def void(authorization, options = {})
113
110
  commit do
114
- result = Braintree::Transaction.void(authorization)
115
- Response.new(result.success?, message_from_result(result),
116
- {:braintree_transaction => (transaction_hash(result.transaction) if result.success?)},
117
- {:authorization => (result.transaction.id if result.success?)}
118
- )
111
+ response_from_result(@braintree_gateway.transaction.void(authorization))
112
+ end
113
+ end
114
+
115
+ def verify(credit_card, options = {})
116
+ MultiResponse.run(:use_first_response) do |r|
117
+ r.process { authorize(100, credit_card, options) }
118
+ r.process(:ignore_result) { void(r.authorization, options) }
119
119
  end
120
120
  end
121
121
 
122
122
  def store(creditcard, options = {})
123
- commit do
124
- parameters = {
125
- :first_name => creditcard.first_name,
126
- :last_name => creditcard.last_name,
127
- :email => options[:email],
128
- :credit_card => {
129
- :number => creditcard.number,
130
- :cvv => creditcard.verification_value,
131
- :expiration_month => creditcard.month.to_s.rjust(2, "0"),
132
- :expiration_year => creditcard.year.to_s
133
- }
134
- }
135
- result = Braintree::Customer.create(merge_credit_card_options(parameters, options))
136
- Response.new(result.success?, message_from_result(result),
137
- {
138
- :braintree_customer => (customer_hash(result.customer) if result.success?),
139
- :customer_vault_id => (result.customer.id if result.success?)
140
- },
141
- :authorization => (result.customer.id if result.success?)
142
- )
123
+ if options[:customer].present?
124
+ MultiResponse.new.tap do |r|
125
+ customer_exists_response = nil
126
+ r.process{customer_exists_response = check_customer_exists(options[:customer])}
127
+ r.process do
128
+ if customer_exists_response.params["exists"]
129
+ add_credit_card_to_customer(creditcard, options)
130
+ else
131
+ add_customer_with_credit_card(creditcard, options)
132
+ end
133
+ end
134
+ end
135
+ else
136
+ add_customer_with_credit_card(creditcard, options)
143
137
  end
144
138
  end
145
139
 
146
140
  def update(vault_id, creditcard, options = {})
147
141
  braintree_credit_card = nil
148
142
  commit do
149
- braintree_credit_card = Braintree::Customer.find(vault_id).credit_cards.detect { |cc| cc.default? }
143
+ braintree_credit_card = @braintree_gateway.customer.find(vault_id).credit_cards.detect { |cc| cc.default? }
150
144
  return Response.new(false, 'Braintree::NotFoundError') if braintree_credit_card.nil?
151
145
 
152
146
  options.merge!(:update_existing_token => braintree_credit_card.token)
153
147
  credit_card_params = merge_credit_card_options({
154
148
  :credit_card => {
149
+ :cardholder_name => creditcard.name,
155
150
  :number => creditcard.number,
156
151
  :cvv => creditcard.verification_value,
157
152
  :expiration_month => creditcard.month.to_s.rjust(2, "0"),
@@ -159,14 +154,16 @@ module ActiveMerchant #:nodoc:
159
154
  }
160
155
  }, options)[:credit_card]
161
156
 
162
- result = Braintree::Customer.update(vault_id,
157
+ result = @braintree_gateway.customer.update(vault_id,
163
158
  :first_name => creditcard.first_name,
164
159
  :last_name => creditcard.last_name,
165
- :email => options[:email],
160
+ :email => scrub_email(options[:email]),
161
+ :phone => options[:phone] || (options[:billing_address][:phone] if options[:billing_address] &&
162
+ options[:billing_address][:phone]),
166
163
  :credit_card => credit_card_params
167
164
  )
168
165
  Response.new(result.success?, message_from_result(result),
169
- :braintree_customer => (customer_hash(Braintree::Customer.find(vault_id)) if result.success?),
166
+ :braintree_customer => (customer_hash(@braintree_gateway.customer.find(vault_id), :include_credit_cards) if result.success?),
170
167
  :customer_vault_id => (result.customer.id if result.success?)
171
168
  )
172
169
  end
@@ -174,20 +171,135 @@ module ActiveMerchant #:nodoc:
174
171
 
175
172
  def unstore(customer_vault_id, options = {})
176
173
  commit do
177
- Braintree::Customer.delete(customer_vault_id)
174
+ if(!customer_vault_id && options[:credit_card_token])
175
+ @braintree_gateway.credit_card.delete(options[:credit_card_token])
176
+ else
177
+ @braintree_gateway.customer.delete(customer_vault_id)
178
+ end
178
179
  Response.new(true, "OK")
179
180
  end
180
181
  end
181
182
  alias_method :delete, :unstore
182
183
 
184
+ def supports_network_tokenization?
185
+ true
186
+ end
187
+
188
+ def verify_credentials
189
+ begin
190
+ @braintree_gateway.transaction.find("non_existent_token")
191
+ rescue Braintree::AuthenticationError
192
+ return false
193
+ rescue Braintree::NotFoundError
194
+ return true
195
+ end
196
+
197
+ true
198
+ end
199
+
183
200
  private
184
201
 
202
+ def check_customer_exists(customer_vault_id)
203
+ commit do
204
+ begin
205
+ @braintree_gateway.customer.find(customer_vault_id)
206
+ ActiveMerchant::Billing::Response.new(true, "Customer found", {exists: true}, authorization: customer_vault_id)
207
+ rescue Braintree::NotFoundError
208
+ ActiveMerchant::Billing::Response.new(true, "Customer not found", {exists: false})
209
+ end
210
+ end
211
+ end
212
+
213
+ def add_customer_with_credit_card(creditcard, options)
214
+ commit do
215
+ if options[:payment_method_nonce]
216
+ credit_card_params = { payment_method_nonce: options[:payment_method_nonce] }
217
+ else
218
+ credit_card_params = {
219
+ :credit_card => {
220
+ :cardholder_name => creditcard.name,
221
+ :number => creditcard.number,
222
+ :cvv => creditcard.verification_value,
223
+ :expiration_month => creditcard.month.to_s.rjust(2, "0"),
224
+ :expiration_year => creditcard.year.to_s,
225
+ :token => options[:credit_card_token]
226
+ }
227
+ }
228
+ end
229
+ parameters = {
230
+ :first_name => creditcard.first_name,
231
+ :last_name => creditcard.last_name,
232
+ :email => scrub_email(options[:email]),
233
+ :phone => options[:phone] || (options[:billing_address][:phone] if options[:billing_address] &&
234
+ options[:billing_address][:phone]),
235
+ :id => options[:customer],
236
+ }.merge credit_card_params
237
+ result = @braintree_gateway.customer.create(merge_credit_card_options(parameters, options))
238
+ Response.new(result.success?, message_from_result(result),
239
+ {
240
+ :braintree_customer => (customer_hash(result.customer, :include_credit_cards) if result.success?),
241
+ :customer_vault_id => (result.customer.id if result.success?),
242
+ :credit_card_token => (result.customer.credit_cards[0].token if result.success?)
243
+ },
244
+ :authorization => (result.customer.id if result.success?)
245
+ )
246
+ end
247
+ end
248
+
249
+ def add_credit_card_to_customer(credit_card, options)
250
+ commit do
251
+ parameters = {
252
+ customer_id: options[:customer],
253
+ token: options[:credit_card_token],
254
+ cardholder_name: credit_card.name,
255
+ number: credit_card.number,
256
+ cvv: credit_card.verification_value,
257
+ expiration_month: credit_card.month.to_s.rjust(2, "0"),
258
+ expiration_year: credit_card.year.to_s,
259
+ }
260
+ parameters[:billing_address] = map_address(options[:billing_address]) if options[:billing_address]
261
+
262
+ result = @braintree_gateway.credit_card.create(parameters)
263
+ ActiveMerchant::Billing::Response.new(
264
+ result.success?,
265
+ message_from_result(result),
266
+ {
267
+ customer_vault_id: (result.credit_card.customer_id if result.success?),
268
+ credit_card_token: (result.credit_card.token if result.success?)
269
+ },
270
+ authorization: (result.credit_card.customer_id if result.success?)
271
+ )
272
+ end
273
+ end
274
+
275
+ def scrub_email(email)
276
+ return nil unless email.present?
277
+ return nil if (
278
+ email !~ /^.+@[^\.]+(\.[^\.]+)+[a-z]$/i ||
279
+ email =~ /\.(con|met)$/i
280
+ )
281
+ email
282
+ end
283
+
284
+ def scrub_zip(zip)
285
+ return nil unless zip.present?
286
+ return nil if(
287
+ zip.gsub(/[^a-z0-9]/i, '').length > 9 ||
288
+ zip =~ /[^a-z0-9\- ]/i
289
+ )
290
+ zip
291
+ end
292
+
185
293
  def merge_credit_card_options(parameters, options)
186
294
  valid_options = {}
187
295
  options.each do |key, value|
188
296
  valid_options[key] = value if [:update_existing_token, :verify_card, :verification_merchant_account_id].include?(key)
189
297
  end
190
298
 
299
+ if valid_options.include?(:verify_card) && @merchant_account_id
300
+ valid_options[:verification_merchant_account_id] ||= @merchant_account_id
301
+ end
302
+
191
303
  parameters[:credit_card] ||= {}
192
304
  parameters[:credit_card].merge!(:options => valid_options)
193
305
  parameters[:credit_card][:billing_address] = map_address(options[:billing_address]) if options[:billing_address]
@@ -202,9 +314,9 @@ module ActiveMerchant #:nodoc:
202
314
  :company => address[:company],
203
315
  :locality => address[:city],
204
316
  :region => address[:state],
205
- :postal_code => address[:zip],
317
+ :postal_code => scrub_zip(address[:zip]),
206
318
  }
207
- if(address[:country] || address[:country_code_alpha2])
319
+ if (address[:country] || address[:country_code_alpha2])
208
320
  mapped[:country_code_alpha2] = (address[:country] || address[:country_code_alpha2])
209
321
  elsif address[:country_name]
210
322
  mapped[:country_name] = address[:country_name]
@@ -225,40 +337,103 @@ module ActiveMerchant #:nodoc:
225
337
  def message_from_result(result)
226
338
  if result.success?
227
339
  "OK"
228
- elsif result.errors.size == 0 && result.credit_card_verification
340
+ elsif result.errors.any?
341
+ result.errors.map { |e| "#{e.message} (#{e.code})" }.join(" ")
342
+ elsif result.credit_card_verification
229
343
  "Processor declined: #{result.credit_card_verification.processor_response_text} (#{result.credit_card_verification.processor_response_code})"
230
344
  else
231
- result.errors.map { |e| "#{e.message} (#{e.code})" }.join(" ")
345
+ result.message.to_s
346
+ end
347
+ end
348
+
349
+ def response_from_result(result)
350
+ Response.new(result.success?, message_from_result(result),
351
+ { braintree_transaction: transaction_hash(result) },
352
+ { authorization: (result.transaction.id if result.transaction) }
353
+ )
354
+ end
355
+
356
+ def response_params(result)
357
+ params = {}
358
+ params[:customer_vault_id] = result.transaction.customer_details.id if result.success?
359
+ params[:braintree_transaction] = transaction_hash(result)
360
+ params
361
+ end
362
+
363
+ def response_options(result)
364
+ options = {}
365
+ if result.transaction
366
+ options[:authorization] = result.transaction.id
367
+ options[:avs_result] = { code: avs_code_from(result.transaction) }
368
+ options[:cvv_result] = result.transaction.cvv_response_code
369
+ end
370
+ options
371
+ end
372
+
373
+ def avs_code_from(transaction)
374
+ transaction.avs_error_response_code ||
375
+ avs_mapping["street: #{transaction.avs_street_address_response_code}, zip: #{transaction.avs_postal_code_response_code}"]
376
+ end
377
+
378
+ def avs_mapping
379
+ {
380
+ "street: M, zip: M" => "M",
381
+ "street: M, zip: N" => "A",
382
+ "street: M, zip: U" => "B",
383
+ "street: M, zip: I" => "B",
384
+ "street: M, zip: A" => "B",
385
+
386
+ "street: N, zip: M" => "Z",
387
+ "street: N, zip: N" => "C",
388
+ "street: N, zip: U" => "C",
389
+ "street: N, zip: I" => "C",
390
+ "street: N, zip: A" => "C",
391
+
392
+ "street: U, zip: M" => "P",
393
+ "street: U, zip: N" => "N",
394
+ "street: U, zip: U" => "I",
395
+ "street: U, zip: I" => "I",
396
+ "street: U, zip: A" => "I",
397
+
398
+ "street: I, zip: M" => "P",
399
+ "street: I, zip: N" => "C",
400
+ "street: I, zip: U" => "I",
401
+ "street: I, zip: I" => "I",
402
+ "street: I, zip: A" => "I",
403
+
404
+ "street: A, zip: M" => "P",
405
+ "street: A, zip: N" => "C",
406
+ "street: A, zip: U" => "I",
407
+ "street: A, zip: I" => "I",
408
+ "street: A, zip: A" => "I"
409
+ }
410
+ end
411
+
412
+ def message_from_transaction_result(result)
413
+ if result.transaction && result.transaction.status == "gateway_rejected"
414
+ "Transaction declined - gateway rejected"
415
+ elsif result.transaction
416
+ "#{result.transaction.processor_response_code} #{result.transaction.processor_response_text}"
417
+ else
418
+ message_from_result(result)
419
+ end
420
+ end
421
+
422
+ def response_code_from_result(result)
423
+ if result.transaction
424
+ result.transaction.processor_response_code
425
+ elsif result.errors.size == 0 && result.credit_card_verification
426
+ result.credit_card_verification.processor_response_code
427
+ elsif result.errors.size > 0
428
+ result.errors.first.code
232
429
  end
233
430
  end
234
431
 
235
432
  def create_transaction(transaction_type, money, credit_card_or_vault_id, options)
236
433
  transaction_params = create_transaction_parameters(money, credit_card_or_vault_id, options)
237
-
238
434
  commit do
239
- result = Braintree::Transaction.send(transaction_type, transaction_params)
240
- response_params, response_options, avs_result, cvv_result = {}, {}, {}, {}
241
- if result.success?
242
- response_params[:braintree_transaction] = transaction_hash(result.transaction)
243
- response_params[:customer_vault_id] = result.transaction.customer_details.id
244
- response_options[:authorization] = result.transaction.id
245
- end
246
- if result.transaction
247
- response_options[:avs_result] = {
248
- :code => nil, :message => nil,
249
- :street_match => result.transaction.avs_street_address_response_code,
250
- :postal_match => result.transaction.avs_postal_code_response_code
251
- }
252
- response_options[:cvv_result] = result.transaction.cvv_response_code
253
- if result.transaction.status == "gateway_rejected"
254
- message = "Transaction declined - gateway rejected"
255
- else
256
- message = "#{result.transaction.processor_response_code} #{result.transaction.processor_response_text}"
257
- end
258
- else
259
- message = message_from_result(result)
260
- end
261
- response = Response.new(result.success?, message, response_params, response_options)
435
+ result = @braintree_gateway.transaction.send(transaction_type, transaction_params)
436
+ response = Response.new(result.success?, message_from_transaction_result(result), response_params(result), response_options(result))
262
437
  response.cvv_result['message'] = ''
263
438
  response
264
439
  end
@@ -277,28 +452,37 @@ module ActiveMerchant #:nodoc:
277
452
  end
278
453
  end
279
454
 
280
- def customer_hash(customer)
281
- credit_cards = customer.credit_cards.map do |cc|
282
- {
283
- "bin" => cc.bin,
284
- "expiration_date" => cc.expiration_date,
285
- "token" => cc.token,
286
- "last_4" => cc.last_4,
287
- "card_type" => cc.card_type,
288
- "masked_number" => cc.masked_number
289
- }
290
- end
291
-
292
- {
455
+ def customer_hash(customer, include_credit_cards=false)
456
+ hash = {
293
457
  "email" => customer.email,
458
+ "phone" => customer.phone,
294
459
  "first_name" => customer.first_name,
295
460
  "last_name" => customer.last_name,
296
- "credit_cards" => credit_cards,
297
461
  "id" => customer.id
298
462
  }
463
+
464
+ if include_credit_cards
465
+ hash["credit_cards"] = customer.credit_cards.map do |cc|
466
+ {
467
+ "bin" => cc.bin,
468
+ "expiration_date" => cc.expiration_date,
469
+ "token" => cc.token,
470
+ "last_4" => cc.last_4,
471
+ "card_type" => cc.card_type,
472
+ "masked_number" => cc.masked_number
473
+ }
474
+ end
475
+ end
476
+
477
+ hash
299
478
  end
300
479
 
301
- def transaction_hash(transaction)
480
+ def transaction_hash(result)
481
+ unless result.success?
482
+ return { "processor_response_code" => response_code_from_result(result) }
483
+ end
484
+
485
+ transaction = result.transaction
302
486
  if transaction.vault_customer
303
487
  vault_customer = {
304
488
  }
@@ -313,7 +497,8 @@ module ActiveMerchant #:nodoc:
313
497
 
314
498
  customer_details = {
315
499
  "id" => transaction.customer_details.id,
316
- "email" => transaction.customer_details.email
500
+ "email" => transaction.customer_details.email,
501
+ "phone" => transaction.customer_details.phone,
317
502
  }
318
503
 
319
504
  billing_details = {
@@ -344,31 +529,43 @@ module ActiveMerchant #:nodoc:
344
529
  }
345
530
 
346
531
  {
347
- "order_id" => transaction.order_id,
348
- "status" => transaction.status,
349
- "credit_card_details" => credit_card_details,
350
- "customer_details" => customer_details,
351
- "billing_details" => billing_details,
352
- "shipping_details" => shipping_details,
353
- "vault_customer" => vault_customer,
354
- "merchant_account_id" => transaction.merchant_account_id
532
+ "order_id" => transaction.order_id,
533
+ "amount" => transaction.amount.to_s,
534
+ "status" => transaction.status,
535
+ "credit_card_details" => credit_card_details,
536
+ "customer_details" => customer_details,
537
+ "billing_details" => billing_details,
538
+ "shipping_details" => shipping_details,
539
+ "vault_customer" => vault_customer,
540
+ "merchant_account_id" => transaction.merchant_account_id,
541
+ "processor_response_code" => response_code_from_result(result)
355
542
  }
356
543
  end
357
544
 
358
545
  def create_transaction_parameters(money, credit_card_or_vault_id, options)
359
546
  parameters = {
360
- :amount => amount(money).to_s,
547
+ :amount => localized_amount(money, options[:currency] || default_currency).to_s,
361
548
  :order_id => options[:order_id],
362
549
  :customer => {
363
550
  :id => options[:store] == true ? "" : options[:store],
364
- :email => options[:email]
551
+ :email => scrub_email(options[:email]),
552
+ :phone => options[:phone] || (options[:billing_address][:phone] if options[:billing_address] &&
553
+ options[:billing_address][:phone])
365
554
  },
366
555
  :options => {
367
556
  :store_in_vault => options[:store] ? true : false,
368
- :submit_for_settlement => options[:submit_for_settlement]
557
+ :submit_for_settlement => options[:submit_for_settlement],
558
+ :hold_in_escrow => options[:hold_in_escrow],
369
559
  }
370
560
  }
371
561
 
562
+ if options[:skip_advanced_fraud_checking]
563
+ parameters[:options].merge!({ :skip_advanced_fraud_checking => options[:skip_advanced_fraud_checking] })
564
+ end
565
+
566
+ parameters[:custom_fields] = options[:custom_fields]
567
+ parameters[:device_data] = options[:device_data] if options[:device_data]
568
+ parameters[:service_fee_amount] = options[:service_fee_amount] if options[:service_fee_amount]
372
569
  if merchant_account_id = (options[:merchant_account_id] || @merchant_account_id)
373
570
  parameters[:merchant_account_id] = merchant_account_id
374
571
  end
@@ -378,24 +575,75 @@ module ActiveMerchant #:nodoc:
378
575
  end
379
576
 
380
577
  if credit_card_or_vault_id.is_a?(String) || credit_card_or_vault_id.is_a?(Integer)
381
- parameters[:customer_id] = credit_card_or_vault_id
578
+ if options[:payment_method_token]
579
+ parameters[:payment_method_token] = credit_card_or_vault_id
580
+ options.delete(:billing_address)
581
+ elsif options[:payment_method_nonce]
582
+ parameters[:payment_method_nonce] = credit_card_or_vault_id
583
+ else
584
+ parameters[:customer_id] = credit_card_or_vault_id
585
+ end
382
586
  else
383
587
  parameters[:customer].merge!(
384
588
  :first_name => credit_card_or_vault_id.first_name,
385
589
  :last_name => credit_card_or_vault_id.last_name
386
590
  )
387
- parameters[:credit_card] = {
388
- :number => credit_card_or_vault_id.number,
389
- :cvv => credit_card_or_vault_id.verification_value,
390
- :expiration_month => credit_card_or_vault_id.month.to_s.rjust(2, "0"),
391
- :expiration_year => credit_card_or_vault_id.year.to_s
392
- }
591
+ if credit_card_or_vault_id.is_a?(NetworkTokenizationCreditCard)
592
+ if credit_card_or_vault_id.source == :apple_pay
593
+ parameters[:apple_pay_card] = {
594
+ :number => credit_card_or_vault_id.number,
595
+ :expiration_month => credit_card_or_vault_id.month.to_s.rjust(2, "0"),
596
+ :expiration_year => credit_card_or_vault_id.year.to_s,
597
+ :cardholder_name => credit_card_or_vault_id.name,
598
+ :cryptogram => credit_card_or_vault_id.payment_cryptogram,
599
+ :eci_indicator => credit_card_or_vault_id.eci
600
+ }
601
+ elsif credit_card_or_vault_id.source == :android_pay
602
+ parameters[:android_pay_card] = {
603
+ :number => credit_card_or_vault_id.number,
604
+ :cryptogram => credit_card_or_vault_id.payment_cryptogram,
605
+ :expiration_month => credit_card_or_vault_id.month.to_s.rjust(2, "0"),
606
+ :expiration_year => credit_card_or_vault_id.year.to_s,
607
+ :google_transaction_id => credit_card_or_vault_id.transaction_id,
608
+ :source_card_type => credit_card_or_vault_id.brand,
609
+ :source_card_last_four => credit_card_or_vault_id.last_digits,
610
+ :eci_indicator => credit_card_or_vault_id.eci
611
+ }
612
+ end
613
+ else
614
+ parameters[:credit_card] = {
615
+ :number => credit_card_or_vault_id.number,
616
+ :cvv => credit_card_or_vault_id.verification_value,
617
+ :expiration_month => credit_card_or_vault_id.month.to_s.rjust(2, "0"),
618
+ :expiration_year => credit_card_or_vault_id.year.to_s,
619
+ :cardholder_name => credit_card_or_vault_id.name
620
+ }
621
+ end
393
622
  end
394
623
  parameters[:billing] = map_address(options[:billing_address]) if options[:billing_address]
395
624
  parameters[:shipping] = map_address(options[:shipping_address]) if options[:shipping_address]
625
+
626
+ channel = @options[:channel] || application_id
627
+ parameters[:channel] = channel if channel
628
+
629
+ if options[:descriptor_name] || options[:descriptor_phone] || options[:descriptor_url]
630
+ parameters[:descriptor] = {
631
+ name: options[:descriptor_name],
632
+ phone: options[:descriptor_phone],
633
+ url: options[:descriptor_url]
634
+ }
635
+ end
636
+
637
+ if options[:three_d_secure]
638
+ parameters[:three_d_secure_pass_thru] = {
639
+ cavv: options[:three_d_secure][:cavv],
640
+ eci_flag: options[:three_d_secure][:eci],
641
+ xid: options[:three_d_secure][:xid],
642
+ }
643
+ end
644
+
396
645
  parameters
397
646
  end
398
647
  end
399
648
  end
400
649
  end
401
-