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
@@ -0,0 +1,440 @@
1
+ require 'digest/md5'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class PayuLatamGateway < Gateway
6
+ self.display_name = "PayU Latam"
7
+ self.homepage_url = "http://www.payulatam.com"
8
+
9
+ self.test_url = "https://sandbox.api.payulatam.com/payments-api/4.0/service.cgi"
10
+ self.live_url = "https://api.payulatam.com/payments-api/4.0/service.cgi"
11
+
12
+ self.supported_countries = ["AR", "BR", "CL", "CO", "MX", "PA", "PE"]
13
+ self.default_currency = "USD"
14
+ self.money_format = :dollars
15
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club]
16
+
17
+ BRAND_MAP = {
18
+ "visa" => "VISA",
19
+ "master" => "MASTERCARD",
20
+ "american_express" => "AMEX",
21
+ "diners_club" => "DINERS"
22
+ }
23
+
24
+ MINIMUMS = {
25
+ "ARS" => 1700,
26
+ "BRL" => 600,
27
+ "MXN" => 3900,
28
+ "PEN" => 500
29
+ }
30
+
31
+ def initialize(options={})
32
+ requires!(options, :merchant_id, :account_id, :api_login, :api_key, :payment_country)
33
+ super
34
+ end
35
+
36
+ def purchase(amount, payment_method, options={})
37
+ post = {}
38
+ auth_or_sale(post, 'AUTHORIZATION_AND_CAPTURE', amount, payment_method, options)
39
+ commit('purchase', post)
40
+ end
41
+
42
+ def authorize(amount, payment_method, options={})
43
+ post = {}
44
+ auth_or_sale(post, 'AUTHORIZATION', amount, payment_method, options)
45
+ commit('auth', post)
46
+ end
47
+
48
+ def capture(amount, authorization, options={})
49
+ post = {}
50
+
51
+ add_credentials(post, 'SUBMIT_TRANSACTION', options)
52
+ add_transaction_elements(post, 'CAPTURE', options)
53
+ add_reference(post, authorization)
54
+
55
+ commit('capture', post)
56
+ end
57
+
58
+ def void(authorization, options={})
59
+ post = {}
60
+
61
+ add_credentials(post, 'SUBMIT_TRANSACTION', options)
62
+ add_transaction_elements(post, 'VOID', options)
63
+ add_reference(post, authorization)
64
+
65
+ commit('void', post)
66
+ end
67
+
68
+ def refund(amount, authorization, options={})
69
+ post = {}
70
+
71
+ add_credentials(post, 'SUBMIT_TRANSACTION', options)
72
+ add_transaction_elements(post, 'REFUND', options)
73
+ add_reference(post, authorization)
74
+
75
+ commit('refund', post)
76
+ end
77
+
78
+ def verify(credit_card, options={})
79
+ minimum = MINIMUMS[options[:currency].upcase] if options[:currency]
80
+ amount = options[:verify_amount] || minimum || 100
81
+
82
+ MultiResponse.run(:use_first_response) do |r|
83
+ r.process { authorize(amount, credit_card, options) }
84
+ r.process(:ignore_result) { void(r.authorization, options) }
85
+ end
86
+ end
87
+
88
+ def store(payment_method, options = {})
89
+ post = {}
90
+
91
+ add_credentials(post, 'CREATE_TOKEN')
92
+ add_payment_method_to_be_tokenized(post, payment_method)
93
+
94
+ commit('store', post)
95
+ end
96
+
97
+ def verify_credentials
98
+ post = {}
99
+ add_credentials(post, 'GET_PAYMENT_METHODS')
100
+ response = commit('verify_credentials', post)
101
+ response.success?
102
+ end
103
+
104
+ def supports_scrubbing?
105
+ true
106
+ end
107
+
108
+ def scrub(transcript)
109
+ transcript.
110
+ gsub(%r((\"creditCard\\\":{\\\"number\\\":\\\")\d+), '\1[FILTERED]').
111
+ gsub(%r((\"securityCode\\\":\\\")\d+), '\1[FILTERED]').
112
+ gsub(%r((\"apiKey\\\":\\\")\w+), '\1[FILTERED]')
113
+ end
114
+
115
+ private
116
+
117
+ def auth_or_sale(post, transaction_type, amount, payment_method, options)
118
+ add_credentials(post, 'SUBMIT_TRANSACTION', options)
119
+ add_transaction_elements(post, transaction_type, options)
120
+ add_order(post, options)
121
+ add_buyer(post, payment_method, options)
122
+ add_invoice(post, amount, options)
123
+ add_signature(post)
124
+ add_payment_method(post, payment_method, options)
125
+ add_payer(post, payment_method, options)
126
+ add_extra_parameters(post, options)
127
+ end
128
+
129
+ def add_credentials(post, command, options={})
130
+ post[:test] = test? unless command == 'CREATE_TOKEN'
131
+ post[:language] = options[:language] || 'en'
132
+ post[:command] = command
133
+ merchant = {}
134
+ merchant[:apiLogin] = @options[:api_login]
135
+ merchant[:apiKey] = @options[:api_key]
136
+ post[:merchant] = merchant
137
+ end
138
+
139
+ def add_transaction_elements(post, type, options)
140
+ transaction = {}
141
+ transaction[:paymentCountry] = @options[:payment_country]
142
+ transaction[:type] = type
143
+ transaction[:ipAddress] = options[:ip] || ''
144
+ transaction[:userAgent] = options[:user_agent] if options[:user_agent]
145
+ transaction[:cookie] = options[:cookie] if options[:cookie]
146
+ transaction[:deviceSessionId] = options[:device_session_id] if options[:device_session_id]
147
+ post[:transaction] = transaction
148
+ end
149
+
150
+ def add_order(post, options)
151
+ order = {}
152
+ order[:accountId] = @options[:account_id]
153
+ order[:partnerId] = options[:partner_id] if options[:partner_id]
154
+ order[:referenceCode] = options[:order_id] || generate_unique_id
155
+ order[:description] = options[:description] || 'Compra en ' + @options[:merchant_id]
156
+ order[:language] = options[:language] || 'en'
157
+ order[:shippingAddress] = shipping_address_fields(options) if options[:shipping_address]
158
+ post[:transaction][:order] = order
159
+ end
160
+
161
+ def add_payer(post, payment_method, options)
162
+ address = options[:billing_address]
163
+ payer = {}
164
+ payer[:fullName] = payment_method.name.strip
165
+ payer[:contactPhone] = address[:phone] if (address && address[:phone])
166
+ payer[:dniNumber] = options[:dni_number] if options[:dni_number]
167
+ payer[:dniType] = options[:dni_type] if options[:dni_type]
168
+ payer[:emailAddress] = options[:email] if options[:email]
169
+ payer[:birthdate] = options[:birth_date] if options[:birth_date] && @options[:payment_country] == 'MX'
170
+ payer[:billingAddress] = billing_address_fields(options)
171
+ post[:transaction][:payer] = payer
172
+ end
173
+
174
+ def billing_address_fields(options)
175
+ return unless address = options[:billing_address]
176
+ billing_address = {}
177
+ billing_address[:street1] = address[:address1]
178
+ billing_address[:street2] = address[:address2]
179
+ billing_address[:city] = address[:city]
180
+ billing_address[:state] = address[:state]
181
+ billing_address[:country] = address[:country]
182
+ billing_address[:postalCode] = address[:zip] if @options[:payment_country] == 'MX'
183
+ billing_address[:phone] = address[:phone]
184
+ billing_address
185
+ end
186
+
187
+ def add_buyer(post, payment_method, options)
188
+ buyer = {}
189
+ if buyer_hash = options[:buyer]
190
+ buyer[:fullName] = buyer_hash[:name]
191
+ buyer[:dniNumber] = buyer_hash[:dni_number]
192
+ buyer[:dniType] = buyer_hash[:dni_type]
193
+ buyer[:cnpj] = buyer_hash[:cnpj] if @options[:payment_country] == 'BR'
194
+ buyer[:emailAddress] = buyer_hash[:email]
195
+ buyer[:contactPhone] = (options[:billing_address][:phone] if options[:billing_address]) || (options[:shipping_address][:phone] if options[:shipping_address]) || ''
196
+ buyer[:shippingAddress] = shipping_address_fields(options) if options[:shipping_address]
197
+ else
198
+ buyer[:fullName] = payment_method.name.strip
199
+ buyer[:dniNumber] = options[:dni_number]
200
+ buyer[:dniType] = options[:dni_type]
201
+ buyer[:cnpj] = options[:cnpj] if @options[:payment_country] == 'BR'
202
+ buyer[:emailAddress] = options[:email]
203
+ buyer[:contactPhone] = (options[:billing_address][:phone] if options[:billing_address]) || (options[:shipping_address][:phone] if options[:shipping_address]) || ''
204
+ buyer[:shippingAddress] = shipping_address_fields(options) if options[:shipping_address]
205
+ end
206
+ post[:transaction][:order][:buyer] = buyer
207
+ end
208
+
209
+ def shipping_address_fields(options)
210
+ return unless address = options[:shipping_address]
211
+ shipping_address = {}
212
+ shipping_address[:street1] = address[:address1]
213
+ shipping_address[:street2] = address[:address2]
214
+ shipping_address[:city] = address[:city]
215
+ shipping_address[:state] = address[:state]
216
+ shipping_address[:country] = address[:country]
217
+ shipping_address[:postalCode] = address[:zip]
218
+ shipping_address[:phone] = address[:phone]
219
+ shipping_address
220
+ end
221
+
222
+ def add_invoice(post, money, options)
223
+ tx_value = {}
224
+ tx_value[:value] = amount(money)
225
+ tx_value[:currency] = options[:currency] || currency(money)
226
+
227
+ tx_tax = {}
228
+ tx_tax[:value] = options[:tax] || '0'
229
+ tx_tax[:currency] = options[:currency] || currency(money)
230
+
231
+ tx_tax_return_base = {}
232
+ tx_tax_return_base[:value] = options[:tax_return_base] || '0'
233
+ tx_tax_return_base[:currency] = options[:currency] || currency(money)
234
+
235
+ additional_values = {}
236
+ additional_values[:TX_VALUE] = tx_value
237
+ additional_values[:TX_TAX] = tx_tax if @options[:payment_country] == 'CO'
238
+ additional_values[:TX_TAX_RETURN_BASE] = tx_tax_return_base if @options[:payment_country] == 'CO'
239
+
240
+ post[:transaction][:order][:additionalValues] = additional_values
241
+ end
242
+
243
+ def add_signature(post)
244
+ post[:transaction][:order][:signature] = signature_from(post)
245
+ end
246
+
247
+ def signature_from(post)
248
+ signature_string = [
249
+ @options[:api_key],
250
+ @options[:merchant_id],
251
+ post[:transaction][:order][:referenceCode],
252
+ post[:transaction][:order][:additionalValues][:TX_VALUE][:value],
253
+ post[:transaction][:order][:additionalValues][:TX_VALUE][:currency]
254
+ ].compact.join("~")
255
+
256
+ Digest::MD5.hexdigest(signature_string)
257
+ end
258
+
259
+ def add_payment_method(post, payment_method, options)
260
+ if payment_method.is_a?(String)
261
+ brand, token = split_authorization(payment_method)
262
+ credit_card = {}
263
+ credit_card[:securityCode] = options[:cvv] if options[:cvv]
264
+ credit_card[:processWithoutCvv2] = true if options[:cvv].blank?
265
+ post[:transaction][:creditCard] = credit_card
266
+ post[:transaction][:creditCardTokenId] = token
267
+ post[:transaction][:paymentMethod] = brand.upcase
268
+ else
269
+ credit_card = {}
270
+ credit_card[:number] = payment_method.number
271
+ credit_card[:securityCode] = payment_method.verification_value || options[:cvv]
272
+ credit_card[:expirationDate] = format(payment_method.year, :four_digits).to_s + '/' + format(payment_method.month, :two_digits).to_s
273
+ credit_card[:name] = payment_method.name.strip
274
+ credit_card[:processWithoutCvv2] = true if add_process_without_cvv2(payment_method, options)
275
+ post[:transaction][:creditCard] = credit_card
276
+ post[:transaction][:paymentMethod] = BRAND_MAP[payment_method.brand.to_s]
277
+ end
278
+ end
279
+
280
+ def add_process_without_cvv2(payment_method, options)
281
+ return true if payment_method.verification_value.blank? && options[:cvv].blank?
282
+ false
283
+ end
284
+
285
+ def add_extra_parameters(post, options)
286
+ extra_parameters = {}
287
+ extra_parameters[:INSTALLMENTS_NUMBER] = options[:installments_number] || 1
288
+ post[:transaction][:extraParameters] = extra_parameters
289
+ end
290
+
291
+ def add_reference(post, authorization)
292
+ order_id, transaction_id = split_authorization(authorization)
293
+ order = {}
294
+ order[:id] = order_id
295
+ post[:transaction][:order] = order
296
+ post[:transaction][:parentTransactionId] = transaction_id
297
+ post[:transaction][:reason] = 'n/a'
298
+ end
299
+
300
+ def add_payment_method_to_be_tokenized(post, payment_method)
301
+ credit_card_token = {}
302
+ credit_card_token[:payerId] = generate_unique_id
303
+ credit_card_token[:name] = payment_method.name.strip
304
+ credit_card_token[:identificationNumber] = generate_unique_id
305
+ credit_card_token[:paymentMethod] = BRAND_MAP[payment_method.brand.to_s]
306
+ credit_card_token[:number] = payment_method.number
307
+ credit_card_token[:expirationDate] = format(payment_method.year, :four_digits).to_s + '/' + format(payment_method.month, :two_digits).to_s
308
+ credit_card_token[:securityCode] = payment_method.verification_value
309
+ post[:creditCardToken] = credit_card_token
310
+ end
311
+
312
+ def commit(action, params)
313
+ begin
314
+ raw_response = ssl_post(url, post_data(params), headers)
315
+ response = parse(raw_response)
316
+ rescue ResponseError => e
317
+ raw_response = e.response.body
318
+ response_error(raw_response)
319
+ rescue JSON::ParserError
320
+ unparsable_response(raw_response)
321
+ else
322
+ success = success_from(action, response)
323
+ Response.new(
324
+ success,
325
+ message_from(action, success, response),
326
+ response,
327
+ authorization: success ? authorization_from(action, response) : nil,
328
+ error_code: success ? nil : error_from(action, response),
329
+ test: test?
330
+ )
331
+ end
332
+ end
333
+
334
+ def headers
335
+ {
336
+ "Content-Type" => "application/json",
337
+ "Accept" => "application/json"
338
+ }
339
+ end
340
+
341
+ def post_data(params)
342
+ params.merge(test: test?)
343
+ params.to_json
344
+ end
345
+
346
+ def url
347
+ test? ? test_url : live_url
348
+ end
349
+
350
+ def parse(body)
351
+ JSON.parse(body)
352
+ end
353
+
354
+ def success_from(action, response)
355
+ case action
356
+ when 'store'
357
+ response["code"] == "SUCCESS" && response["creditCardToken"] && response["creditCardToken"]["creditCardTokenId"].present?
358
+ when 'verify_credentials'
359
+ response["code"] == "SUCCESS"
360
+ when 'refund', 'void'
361
+ response["code"] == "SUCCESS" && response["transactionResponse"] && (response["transactionResponse"]["state"] == "PENDING" || response["transactionResponse"]["state"] == "APPROVED")
362
+ else
363
+ response["code"] == "SUCCESS" && response["transactionResponse"] && (response["transactionResponse"]["state"] == "APPROVED")
364
+ end
365
+ end
366
+
367
+ def message_from(action, success, response)
368
+ case action
369
+ when 'store'
370
+ return response["code"] if success
371
+ error_description = response["creditCardToken"]["errorDescription"] if response["creditCardToken"]
372
+ response["error"] || error_description || "FAILED"
373
+ when 'verify_credentials'
374
+ return "VERIFIED" if success
375
+ "FAILED"
376
+ else
377
+ if response["transactionResponse"]
378
+ response_message = response["transactionResponse"]["responseMessage"]
379
+ response_code = response["transactionResponse"]["responseCode"] || response["transactionResponse"]["pendingReason"]
380
+ end
381
+ return response_code if success
382
+ response["error"] || response_message || response_code || "FAILED"
383
+ end
384
+ end
385
+
386
+ def authorization_from(action, response)
387
+ case action
388
+ when 'store'
389
+ [
390
+ response["creditCardToken"]["paymentMethod"],
391
+ response["creditCardToken"]["creditCardTokenId"]
392
+ ].compact.join("|")
393
+ when 'verify_credentials'
394
+ nil
395
+ else
396
+ [
397
+ response["transactionResponse"]["orderId"],
398
+ response["transactionResponse"]["transactionId"]
399
+ ].compact.join("|")
400
+ end
401
+ end
402
+
403
+ def split_authorization(authorization)
404
+ authorization.split("|")
405
+ end
406
+
407
+ def error_from(action, response)
408
+ case action
409
+ when 'store'
410
+ response["creditCardToken"]["errorDescription"] if response["creditCardToken"]
411
+ when 'verify_credentials'
412
+ response["error"] || "FAILED"
413
+ else
414
+ response["transactionResponse"]["errorCode"] || response["transactionResponse"]["responseCode"] if response["transactionResponse"]
415
+ end
416
+ end
417
+
418
+ def response_error(raw_response)
419
+ begin
420
+ response = parse(raw_response)
421
+ rescue JSON::ParserError
422
+ unparsable_response(raw_response)
423
+ else
424
+ return Response.new(
425
+ false,
426
+ message_from('', false, response),
427
+ response,
428
+ :test => test?
429
+ )
430
+ end
431
+ end
432
+
433
+ def unparsable_response(raw_response)
434
+ message = "Invalid JSON response received from PayuLatamGateway. Please contact PayuLatamGateway if you continue to receive this message."
435
+ message += " (The raw response returned by the API was #{raw_response.inspect})"
436
+ return Response.new(false, message)
437
+ end
438
+ end
439
+ end
440
+ end
@@ -7,9 +7,9 @@ module ActiveMerchant #:nodoc:
7
7
  self.default_currency = 'AUD'
8
8
  self.money_format = :cents
9
9
  self.supported_countries = ['AU']
10
- self.supported_cardtypes = [:visa, :master]
10
+ self.supported_cardtypes = [:visa, :master, :american_express]
11
11
  self.homepage_url = 'http://www.pin.net.au/'
12
- self.display_name = 'Pin'
12
+ self.display_name = 'Pin Payments'
13
13
 
14
14
  def initialize(options = {})
15
15
  requires!(options, :api_key)
@@ -28,8 +28,10 @@ module ActiveMerchant #:nodoc:
28
28
  add_invoice(post, options)
29
29
  add_creditcard(post, creditcard)
30
30
  add_address(post, creditcard, options)
31
+ add_capture(post, options)
32
+ add_metadata(post, options)
31
33
 
32
- commit('charges', post, options)
34
+ commit(:post, 'charges', post, options)
33
35
  end
34
36
 
35
37
  # Create a customer and associated credit card. The token that is returned
@@ -40,17 +42,50 @@ module ActiveMerchant #:nodoc:
40
42
  add_creditcard(post, creditcard)
41
43
  add_customer_data(post, options)
42
44
  add_address(post, creditcard, options)
43
- commit('customers', post, options)
45
+ commit(:post, 'customers', post, options)
44
46
  end
45
47
 
46
- # Refund a transaction, note that the money attribute is ignored at the
47
- # moment as the API does not support partial refunds. The parameter is
48
- # kept for compatibility reasons
48
+ # Refund a transaction
49
49
  def refund(money, token, options = {})
50
- commit("charges/#{CGI.escape(token)}/refunds", { :amount => amount(money) }, options)
50
+ commit(:post, "charges/#{CGI.escape(token)}/refunds", { :amount => amount(money) }, options)
51
51
  end
52
52
 
53
+ # Authorize an amount on a credit card. Once authorized, you can later
54
+ # capture this charge using the charge token that is returned.
55
+ def authorize(money, creditcard, options = {})
56
+ options[:capture] = false
57
+
58
+ purchase(money, creditcard, options)
59
+ end
60
+
61
+ # Captures a previously authorized charge. Capturing only part of the original
62
+ # authorization is currently not supported.
63
+ def capture(money, token, options = {})
64
+ commit(:put, "charges/#{CGI.escape(token)}/capture", { :amount => amount(money) }, options)
65
+ end
66
+
67
+ # Updates the credit card for the customer.
68
+ def update(token, creditcard, options = {})
69
+ post = {}
70
+
71
+ add_creditcard(post, creditcard)
72
+ add_customer_data(post, options)
73
+ add_address(post, creditcard, options)
74
+ commit(:put, "customers/#{CGI.escape(token)}", post, options)
75
+ end
76
+
77
+ def supports_scrubbing
78
+ true
79
+ end
80
+
81
+ def scrub(transcript)
82
+ transcript.
83
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
84
+ gsub(/(number\\?":\\?")(\d*)/, '\1[FILTERED]').
85
+ gsub(/(cvc\\?":\\?")(\d*)/, '\1[FILTERED]')
86
+ end
53
87
  private
88
+
54
89
  def add_amount(post, money, options)
55
90
  post[:amount] = amount(money)
56
91
  post[:currency] = (options[:currency] || currency(money))
@@ -58,8 +93,8 @@ module ActiveMerchant #:nodoc:
58
93
  end
59
94
 
60
95
  def add_customer_data(post, options)
61
- post[:email] = options[:email]
62
- post[:ip_address] = options[:ip]
96
+ post[:email] = options[:email] if options[:email]
97
+ post[:ip_address] = options[:ip] if options[:ip]
63
98
  end
64
99
 
65
100
  def add_address(post, creditcard, options)
@@ -81,6 +116,12 @@ module ActiveMerchant #:nodoc:
81
116
  post[:description] = options[:description] || "Active Merchant Purchase"
82
117
  end
83
118
 
119
+ def add_capture(post, options)
120
+ capture = options[:capture]
121
+
122
+ post[:capture] = capture == false ? false : true
123
+ end
124
+
84
125
  def add_creditcard(post, creditcard)
85
126
  if creditcard.respond_to?(:number)
86
127
  post[:card] ||= {}
@@ -90,7 +131,7 @@ module ActiveMerchant #:nodoc:
90
131
  :expiry_month => creditcard.month,
91
132
  :expiry_year => creditcard.year,
92
133
  :cvc => creditcard.verification_value,
93
- :name => "#{creditcard.first_name} #{creditcard.last_name}"
134
+ :name => creditcard.name
94
135
  )
95
136
  elsif creditcard.kind_of?(String)
96
137
  if creditcard =~ /^card_/
@@ -101,6 +142,10 @@ module ActiveMerchant #:nodoc:
101
142
  end
102
143
  end
103
144
 
145
+ def add_metadata(post, options)
146
+ post[:metadata] = options[:metadata] if options[:metadata]
147
+ end
148
+
104
149
  def headers(params = {})
105
150
  result = {
106
151
  "Content-Type" => "application/json",
@@ -112,11 +157,12 @@ module ActiveMerchant #:nodoc:
112
157
  result
113
158
  end
114
159
 
115
- def commit(action, params, options)
160
+ def commit(method, action, params, options)
116
161
  url = "#{test? ? test_url : live_url}/#{action}"
117
162
 
118
163
  begin
119
- body = parse(ssl_post(url, post_data(params), headers(options)))
164
+ raw_response = ssl_request(method, url, post_data(params), headers(options))
165
+ body = parse(raw_response)
120
166
  rescue ResponseError => e
121
167
  body = parse(e.response.body)
122
168
  end
@@ -126,6 +172,9 @@ module ActiveMerchant #:nodoc:
126
172
  elsif body["error"]
127
173
  error_response(body)
128
174
  end
175
+
176
+ rescue JSON::ParserError
177
+ return unparsable_response(raw_response)
129
178
  end
130
179
 
131
180
  def success_response(body)
@@ -149,6 +198,12 @@ module ActiveMerchant #:nodoc:
149
198
  )
150
199
  end
151
200
 
201
+ def unparsable_response(raw_response)
202
+ message = "Invalid JSON response received from Pin Payments. Please contact support@pin.net.au if you continue to receive this message."
203
+ message += " (The raw response returned by the API was #{raw_response.inspect})"
204
+ return Response.new(false, message)
205
+ end
206
+
152
207
  def token(response)
153
208
  response['token']
154
209
  end
@@ -153,7 +153,7 @@ module ActiveMerchant
153
153
  add_amount(post, money, options)
154
154
 
155
155
  if identification_or_creditcard.is_a?(String)
156
- deprecated CREDIT_DEPRECATION_MESSAGE
156
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
157
157
  refund(money, identification_or_creditcard, options)
158
158
  else
159
159
  add_creditcard(post, identification_or_creditcard)
@@ -268,17 +268,6 @@ module ActiveMerchant
268
268
  post[:currency] = options[:currency] || currency(money)
269
269
  end
270
270
 
271
- # Make a ruby type out of the response string
272
- def normalize(field)
273
- case field
274
- when "true" then true
275
- when "false" then false
276
- when "" then nil
277
- when "null" then nil
278
- else field
279
- end
280
- end
281
-
282
271
  def message_from(results)
283
272
  PAYMENT_GATEWAY_RESPONSES[results[:resp_code]]
284
273
  end