swiss-activemerchant 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (287) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +4033 -0
  3. data/CONTRIBUTORS +568 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +249 -0
  6. data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
  7. data/lib/active_merchant/billing/avs_result.rb +95 -0
  8. data/lib/active_merchant/billing/base.rb +48 -0
  9. data/lib/active_merchant/billing/check.rb +112 -0
  10. data/lib/active_merchant/billing/compatibility.rb +118 -0
  11. data/lib/active_merchant/billing/credit_card.rb +451 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +512 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +37 -0
  15. data/lib/active_merchant/billing/gateway.rb +332 -0
  16. data/lib/active_merchant/billing/gateways/adyen.rb +774 -0
  17. data/lib/active_merchant/billing/gateways/airwallex.rb +370 -0
  18. data/lib/active_merchant/billing/gateways/alelo.rb +256 -0
  19. data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
  20. data/lib/active_merchant/billing/gateways/authorize_net.rb +1125 -0
  21. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +424 -0
  22. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +977 -0
  23. data/lib/active_merchant/billing/gateways/axcessms.rb +243 -0
  24. data/lib/active_merchant/billing/gateways/balanced.rb +263 -0
  25. data/lib/active_merchant/billing/gateways/bambora_apac.rb +222 -0
  26. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  27. data/lib/active_merchant/billing/gateways/banwire.rb +116 -0
  28. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +397 -0
  29. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
  30. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  31. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +474 -0
  32. data/lib/active_merchant/billing/gateways/beanstream.rb +238 -0
  33. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +57 -0
  34. data/lib/active_merchant/billing/gateways/blue_pay.rb +549 -0
  35. data/lib/active_merchant/billing/gateways/blue_snap.rb +644 -0
  36. data/lib/active_merchant/billing/gateways/bogus.rb +190 -0
  37. data/lib/active_merchant/billing/gateways/borgun.rb +272 -0
  38. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  39. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +28 -0
  40. data/lib/active_merchant/billing/gateways/braintree/token_nonce.rb +113 -0
  41. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  42. data/lib/active_merchant/billing/gateways/braintree_blue.rb +952 -0
  43. data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
  44. data/lib/active_merchant/billing/gateways/bridge_pay.rb +244 -0
  45. data/lib/active_merchant/billing/gateways/cams.rb +230 -0
  46. data/lib/active_merchant/billing/gateways/card_connect.rb +338 -0
  47. data/lib/active_merchant/billing/gateways/card_save.rb +21 -0
  48. data/lib/active_merchant/billing/gateways/card_stream.rb +394 -0
  49. data/lib/active_merchant/billing/gateways/cardknox.rb +327 -0
  50. data/lib/active_merchant/billing/gateways/cardprocess.rb +256 -0
  51. data/lib/active_merchant/billing/gateways/cashnet.rb +235 -0
  52. data/lib/active_merchant/billing/gateways/cc5.rb +198 -0
  53. data/lib/active_merchant/billing/gateways/cecabank.rb +249 -0
  54. data/lib/active_merchant/billing/gateways/cenpos.rb +328 -0
  55. data/lib/active_merchant/billing/gateways/checkout.rb +212 -0
  56. data/lib/active_merchant/billing/gateways/checkout_v2.rb +587 -0
  57. data/lib/active_merchant/billing/gateways/citrus_pay.rb +21 -0
  58. data/lib/active_merchant/billing/gateways/clearhaus.rb +219 -0
  59. data/lib/active_merchant/billing/gateways/commerce_hub.rb +366 -0
  60. data/lib/active_merchant/billing/gateways/commercegate.rb +142 -0
  61. data/lib/active_merchant/billing/gateways/conekta.rb +230 -0
  62. data/lib/active_merchant/billing/gateways/creditcall.rb +272 -0
  63. data/lib/active_merchant/billing/gateways/credorax.rb +526 -0
  64. data/lib/active_merchant/billing/gateways/ct_payment.rb +269 -0
  65. data/lib/active_merchant/billing/gateways/culqi.rb +279 -0
  66. data/lib/active_merchant/billing/gateways/cyber_source/cyber_source_common.rb +36 -0
  67. data/lib/active_merchant/billing/gateways/cyber_source.rb +1148 -0
  68. data/lib/active_merchant/billing/gateways/cyber_source_rest.rb +454 -0
  69. data/lib/active_merchant/billing/gateways/d_local.rb +343 -0
  70. data/lib/active_merchant/billing/gateways/data_cash.rb +302 -0
  71. data/lib/active_merchant/billing/gateways/decidir.rb +358 -0
  72. data/lib/active_merchant/billing/gateways/decidir_plus.rb +344 -0
  73. data/lib/active_merchant/billing/gateways/dibs.rb +199 -0
  74. data/lib/active_merchant/billing/gateways/digitzs.rb +295 -0
  75. data/lib/active_merchant/billing/gateways/ebanx.rb +346 -0
  76. data/lib/active_merchant/billing/gateways/efsnet.rb +215 -0
  77. data/lib/active_merchant/billing/gateways/elavon.rb +475 -0
  78. data/lib/active_merchant/billing/gateways/element.rb +406 -0
  79. data/lib/active_merchant/billing/gateways/epay.rb +296 -0
  80. data/lib/active_merchant/billing/gateways/evo_ca.rb +307 -0
  81. data/lib/active_merchant/billing/gateways/eway.rb +226 -0
  82. data/lib/active_merchant/billing/gateways/eway_managed.rb +289 -0
  83. data/lib/active_merchant/billing/gateways/eway_rapid.rb +578 -0
  84. data/lib/active_merchant/billing/gateways/exact.rb +219 -0
  85. data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
  86. data/lib/active_merchant/billing/gateways/fat_zebra.rb +223 -0
  87. data/lib/active_merchant/billing/gateways/federated_canada.rb +158 -0
  88. data/lib/active_merchant/billing/gateways/finansbank.rb +22 -0
  89. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  90. data/lib/active_merchant/billing/gateways/first_pay.rb +182 -0
  91. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +452 -0
  92. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +505 -0
  93. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  94. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  95. data/lib/active_merchant/billing/gateways/fluidpay.rb +275 -0
  96. data/lib/active_merchant/billing/gateways/forte.rb +286 -0
  97. data/lib/active_merchant/billing/gateways/garanti.rb +256 -0
  98. data/lib/active_merchant/billing/gateways/global_collect.rb +580 -0
  99. data/lib/active_merchant/billing/gateways/global_transport.rb +193 -0
  100. data/lib/active_merchant/billing/gateways/hdfc.rb +205 -0
  101. data/lib/active_merchant/billing/gateways/hps.rb +472 -0
  102. data/lib/active_merchant/billing/gateways/iats_payments.rb +312 -0
  103. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  104. data/lib/active_merchant/billing/gateways/inspire.rb +213 -0
  105. data/lib/active_merchant/billing/gateways/instapay.rb +159 -0
  106. data/lib/active_merchant/billing/gateways/ipg.rb +420 -0
  107. data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
  108. data/lib/active_merchant/billing/gateways/iridium.rb +467 -0
  109. data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
  110. data/lib/active_merchant/billing/gateways/iveri.rb +290 -0
  111. data/lib/active_merchant/billing/gateways/ixopay.rb +320 -0
  112. data/lib/active_merchant/billing/gateways/jetpay.rb +395 -0
  113. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +432 -0
  114. data/lib/active_merchant/billing/gateways/klarna.rb +317 -0
  115. data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
  116. data/lib/active_merchant/billing/gateways/kushki.rb +297 -0
  117. data/lib/active_merchant/billing/gateways/latitude19.rb +412 -0
  118. data/lib/active_merchant/billing/gateways/linkpoint.rb +448 -0
  119. data/lib/active_merchant/billing/gateways/litle.rb +643 -0
  120. data/lib/active_merchant/billing/gateways/mastercard.rb +286 -0
  121. data/lib/active_merchant/billing/gateways/maxipago.rb +220 -0
  122. data/lib/active_merchant/billing/gateways/mercado_pago.rb +348 -0
  123. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +228 -0
  124. data/lib/active_merchant/billing/gateways/merchant_one.rb +110 -0
  125. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  126. data/lib/active_merchant/billing/gateways/merchant_ware.rb +313 -0
  127. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +284 -0
  128. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +248 -0
  129. data/lib/active_merchant/billing/gateways/mercury.rb +352 -0
  130. data/lib/active_merchant/billing/gateways/metrics_global.rb +293 -0
  131. data/lib/active_merchant/billing/gateways/micropayment.rb +182 -0
  132. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  133. data/lib/active_merchant/billing/gateways/migs.rb +329 -0
  134. data/lib/active_merchant/billing/gateways/mit.rb +260 -0
  135. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  136. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +215 -0
  137. data/lib/active_merchant/billing/gateways/moka.rb +290 -0
  138. data/lib/active_merchant/billing/gateways/monei.rb +424 -0
  139. data/lib/active_merchant/billing/gateways/moneris.rb +488 -0
  140. data/lib/active_merchant/billing/gateways/money_movers.rb +150 -0
  141. data/lib/active_merchant/billing/gateways/mundipagg.rb +366 -0
  142. data/lib/active_merchant/billing/gateways/nab_transact.rb +299 -0
  143. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +163 -0
  144. data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
  145. data/lib/active_merchant/billing/gateways/netaxept.rb +180 -0
  146. data/lib/active_merchant/billing/gateways/netbanx.rb +376 -0
  147. data/lib/active_merchant/billing/gateways/netbilling.rb +229 -0
  148. data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
  149. data/lib/active_merchant/billing/gateways/network_merchants.rb +238 -0
  150. data/lib/active_merchant/billing/gateways/nmi.rb +396 -0
  151. data/lib/active_merchant/billing/gateways/ogone.rb +509 -0
  152. data/lib/active_merchant/billing/gateways/omise.rb +323 -0
  153. data/lib/active_merchant/billing/gateways/openpay.rb +246 -0
  154. data/lib/active_merchant/billing/gateways/opp.rb +394 -0
  155. data/lib/active_merchant/billing/gateways/optimal_payment.rb +331 -0
  156. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +45 -0
  157. data/lib/active_merchant/billing/gateways/orbital.rb +1267 -0
  158. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +206 -0
  159. data/lib/active_merchant/billing/gateways/pagarme.rb +239 -0
  160. data/lib/active_merchant/billing/gateways/pago_facil.rb +120 -0
  161. data/lib/active_merchant/billing/gateways/pay_arc.rb +392 -0
  162. data/lib/active_merchant/billing/gateways/pay_conex.rb +245 -0
  163. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +277 -0
  164. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  165. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  166. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +206 -0
  167. data/lib/active_merchant/billing/gateways/pay_secure.rb +110 -0
  168. data/lib/active_merchant/billing/gateways/pay_trace.rb +450 -0
  169. data/lib/active_merchant/billing/gateways/paybox_direct.rb +224 -0
  170. data/lib/active_merchant/billing/gateways/payeezy.rb +513 -0
  171. data/lib/active_merchant/billing/gateways/payex.rb +409 -0
  172. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +235 -0
  173. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +42 -0
  174. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  175. data/lib/active_merchant/billing/gateways/payflow.rb +473 -0
  176. data/lib/active_merchant/billing/gateways/payflow_express.rb +220 -0
  177. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +14 -0
  178. data/lib/active_merchant/billing/gateways/payflow_uk.rb +20 -0
  179. data/lib/active_merchant/billing/gateways/payment_express.rb +373 -0
  180. data/lib/active_merchant/billing/gateways/paymentez.rb +365 -0
  181. data/lib/active_merchant/billing/gateways/paymill.rb +369 -0
  182. data/lib/active_merchant/billing/gateways/paynetworx.rb +227 -0
  183. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +718 -0
  184. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +69 -0
  185. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  186. data/lib/active_merchant/billing/gateways/paypal.rb +136 -0
  187. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  188. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  189. data/lib/active_merchant/billing/gateways/paypal_express.rb +272 -0
  190. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  191. data/lib/active_merchant/billing/gateways/paypal_standard.rb +281 -0
  192. data/lib/active_merchant/billing/gateways/paysafe.rb +420 -0
  193. data/lib/active_merchant/billing/gateways/payscout.rb +159 -0
  194. data/lib/active_merchant/billing/gateways/paystation.rb +204 -0
  195. data/lib/active_merchant/billing/gateways/payu_in.rb +249 -0
  196. data/lib/active_merchant/billing/gateways/payu_latam.rb +482 -0
  197. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  198. data/lib/active_merchant/billing/gateways/payway_dot_com.rb +253 -0
  199. data/lib/active_merchant/billing/gateways/pin.rb +273 -0
  200. data/lib/active_merchant/billing/gateways/pixxels.rb +263 -0
  201. data/lib/active_merchant/billing/gateways/plexo.rb +308 -0
  202. data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
  203. data/lib/active_merchant/billing/gateways/priority.rb +392 -0
  204. data/lib/active_merchant/billing/gateways/pro_pay.rb +325 -0
  205. data/lib/active_merchant/billing/gateways/psigate.rb +227 -0
  206. data/lib/active_merchant/billing/gateways/psl_card.rb +295 -0
  207. data/lib/active_merchant/billing/gateways/qbms.rb +302 -0
  208. data/lib/active_merchant/billing/gateways/quantum.rb +274 -0
  209. data/lib/active_merchant/billing/gateways/quickbooks.rb +377 -0
  210. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +184 -0
  211. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +297 -0
  212. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +226 -0
  213. data/lib/active_merchant/billing/gateways/quickpay.rb +24 -0
  214. data/lib/active_merchant/billing/gateways/qvalent.rb +305 -0
  215. data/lib/active_merchant/billing/gateways/rapyd.rb +319 -0
  216. data/lib/active_merchant/billing/gateways/reach.rb +277 -0
  217. data/lib/active_merchant/billing/gateways/realex.rb +400 -0
  218. data/lib/active_merchant/billing/gateways/redsys.rb +723 -0
  219. data/lib/active_merchant/billing/gateways/s5.rb +247 -0
  220. data/lib/active_merchant/billing/gateways/safe_charge.rb +298 -0
  221. data/lib/active_merchant/billing/gateways/sage.rb +446 -0
  222. data/lib/active_merchant/billing/gateways/sage_pay.rb +434 -0
  223. data/lib/active_merchant/billing/gateways/sallie_mae.rb +141 -0
  224. data/lib/active_merchant/billing/gateways/secure_net.rb +260 -0
  225. data/lib/active_merchant/billing/gateways/secure_pay.rb +191 -0
  226. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +290 -0
  227. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +103 -0
  228. data/lib/active_merchant/billing/gateways/securion_pay.rb +305 -0
  229. data/lib/active_merchant/billing/gateways/shift4.rb +345 -0
  230. data/lib/active_merchant/billing/gateways/simetrik.rb +368 -0
  231. data/lib/active_merchant/billing/gateways/skip_jack.rb +450 -0
  232. data/lib/active_merchant/billing/gateways/smart_ps.rb +274 -0
  233. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  234. data/lib/active_merchant/billing/gateways/spreedly_core.rb +312 -0
  235. data/lib/active_merchant/billing/gateways/stripe.rb +866 -0
  236. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +602 -0
  237. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +151 -0
  238. data/lib/active_merchant/billing/gateways/telr.rb +273 -0
  239. data/lib/active_merchant/billing/gateways/tns.rb +23 -0
  240. data/lib/active_merchant/billing/gateways/trans_first.rb +240 -0
  241. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +612 -0
  242. data/lib/active_merchant/billing/gateways/transact_pro.rb +222 -0
  243. data/lib/active_merchant/billing/gateways/transax.rb +21 -0
  244. data/lib/active_merchant/billing/gateways/transnational.rb +9 -0
  245. data/lib/active_merchant/billing/gateways/trexle.rb +221 -0
  246. data/lib/active_merchant/billing/gateways/trust_commerce.rb +500 -0
  247. data/lib/active_merchant/billing/gateways/usa_epay.rb +24 -0
  248. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1612 -0
  249. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +367 -0
  250. data/lib/active_merchant/billing/gateways/vanco.rb +303 -0
  251. data/lib/active_merchant/billing/gateways/verifi.rb +224 -0
  252. data/lib/active_merchant/billing/gateways/viaklix.rb +171 -0
  253. data/lib/active_merchant/billing/gateways/visanet_peru.rb +250 -0
  254. data/lib/active_merchant/billing/gateways/vpos.rb +223 -0
  255. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  256. data/lib/active_merchant/billing/gateways/wepay.rb +235 -0
  257. data/lib/active_merchant/billing/gateways/wirecard.rb +430 -0
  258. data/lib/active_merchant/billing/gateways/wompi.rb +197 -0
  259. data/lib/active_merchant/billing/gateways/world_net.rb +345 -0
  260. data/lib/active_merchant/billing/gateways/worldpay.rb +1050 -0
  261. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +208 -0
  262. data/lib/active_merchant/billing/gateways/worldpay_us.rb +221 -0
  263. data/lib/active_merchant/billing/gateways.rb +14 -0
  264. data/lib/active_merchant/billing/model.rb +30 -0
  265. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
  266. data/lib/active_merchant/billing/payment_token.rb +21 -0
  267. data/lib/active_merchant/billing/rails.rb +3 -0
  268. data/lib/active_merchant/billing/response.rb +120 -0
  269. data/lib/active_merchant/billing/three_d_secure_eci_mapper.rb +27 -0
  270. data/lib/active_merchant/billing.rb +16 -0
  271. data/lib/active_merchant/connection.rb +194 -0
  272. data/lib/active_merchant/country.rb +338 -0
  273. data/lib/active_merchant/empty.rb +20 -0
  274. data/lib/active_merchant/errors.rb +38 -0
  275. data/lib/active_merchant/net_http_ssl_connection.rb +11 -0
  276. data/lib/active_merchant/network_connection_retries.rb +78 -0
  277. data/lib/active_merchant/post_data.rb +26 -0
  278. data/lib/active_merchant/posts_data.rb +92 -0
  279. data/lib/active_merchant/version.rb +3 -0
  280. data/lib/active_merchant.rb +63 -0
  281. data/lib/activemerchant.rb +1 -0
  282. data/lib/certs/cacert.pem +3214 -0
  283. data/lib/support/gateway_support.rb +69 -0
  284. data/lib/support/outbound_hosts.rb +28 -0
  285. data/lib/support/ssl_verify.rb +88 -0
  286. data/lib/support/ssl_version.rb +86 -0
  287. metadata +506 -0
@@ -0,0 +1,283 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ class PlugnpayGateway < Gateway
4
+ class PlugnpayPostData < PostData
5
+ # Fields that will be sent even if they are blank
6
+ self.required_fields = %i[publisher_name publisher_password
7
+ card_amount card_name card_number card_exp orderID]
8
+ end
9
+ self.live_url = self.test_url = 'https://pay1.plugnpay.com/payment/pnpremote.cgi'
10
+
11
+ CARD_CODE_MESSAGES = {
12
+ 'M' => 'Card verification number matched',
13
+ 'N' => "Card verification number didn't match",
14
+ 'P' => 'Card verification number was not processed',
15
+ 'S' => 'Card verification number should be on card but was not indicated',
16
+ 'U' => 'Issuer was not certified for card verification'
17
+ }
18
+
19
+ CARD_CODE_ERRORS = %w(N S)
20
+
21
+ AVS_MESSAGES = {
22
+ 'A' => 'Street address matches billing information, zip/postal code does not',
23
+ 'B' => 'Address information not provided for address verification check',
24
+ 'E' => 'Address verification service error',
25
+ 'G' => 'Non-U.S. card-issuing bank',
26
+ 'N' => 'Neither street address nor zip/postal match billing information',
27
+ 'P' => 'Address verification not applicable for this transaction',
28
+ 'R' => 'Payment gateway was unavailable or timed out',
29
+ 'S' => 'Address verification service not supported by issuer',
30
+ 'U' => 'Address information is unavailable',
31
+ 'W' => '9-digit zip/postal code matches billing information, street address does not',
32
+ 'X' => 'Street address and 9-digit zip/postal code matches billing information',
33
+ 'Y' => 'Street address and 5-digit zip/postal code matches billing information',
34
+ 'Z' => '5-digit zip/postal code matches billing information, street address does not'
35
+ }
36
+
37
+ AVS_ERRORS = %w(A E N R W Z)
38
+
39
+ PAYMENT_GATEWAY_RESPONSES = {
40
+ 'P01' => 'AVS Mismatch Failure',
41
+ 'P02' => 'CVV2 Mismatch Failure',
42
+ 'P21' => 'Transaction may not be marked',
43
+ 'P30' => 'Test Tran. Bad Card',
44
+ 'P35' => 'Test Tran. Problem',
45
+ 'P40' => 'Username already exists',
46
+ 'P41' => 'Username is blank',
47
+ 'P50' => 'Fraud Screen Failure',
48
+ 'P51' => 'Missing PIN Code',
49
+ 'P52' => 'Invalid Bank Acct. No.',
50
+ 'P53' => 'Invalid Bank Routing No.',
51
+ 'P54' => 'Invalid/Missing Check No.',
52
+ 'P55' => 'Invalid Credit Card No.',
53
+ 'P56' => 'Invalid CVV2/CVC2 No.',
54
+ 'P57' => 'Expired. CC Exp. Date',
55
+ 'P58' => 'Missing Data',
56
+ 'P59' => 'Missing Email Address',
57
+ 'P60' => 'Zip Code does not match Billing State.',
58
+ 'P61' => 'Invalid Billing Zip Code',
59
+ 'P62' => 'Zip Code does not match Shipping State.',
60
+ 'P63' => 'Invalid Shipping Zip Code',
61
+ 'P64' => 'Invalid Credit Card CVV2/CVC2 Format.',
62
+ 'P65' => 'Maximum number of attempts has been exceeded.',
63
+ 'P66' => 'Credit Card number has been flagged and can not be used to access this service.',
64
+ 'P67' => 'IP Address is on Blocked List.',
65
+ 'P68' => 'Billing country does not match ipaddress country.',
66
+ 'P69' => 'US based ipaddresses are currently blocked.',
67
+ 'P70' => 'Credit Cards issued from this bank are currently not being accepted.',
68
+ 'P71' => 'Credit Cards issued from this bank are currently not being accepted.',
69
+ 'P72' => 'Daily volume exceeded.',
70
+ 'P73' => 'Too many transactions within allotted time.',
71
+ 'P91' => 'Missing/incorrect password',
72
+ 'P92' => 'Account not configured for mobil administration',
73
+ 'P93' => 'IP Not registered to username.',
74
+ 'P94' => 'Mode not permitted for this account.',
75
+ 'P95' => 'Currently Blank',
76
+ 'P96' => 'Currently Blank',
77
+ 'P97' => 'Processor not responding',
78
+ 'P98' => 'Missing merchant/publisher name',
79
+ 'P99' => 'Currently Blank'
80
+ }
81
+
82
+ TRANSACTIONS = {
83
+ authorization: 'auth',
84
+ purchase: 'auth',
85
+ capture: 'mark',
86
+ void: 'void',
87
+ refund: 'return',
88
+ credit: 'newreturn'
89
+ }
90
+
91
+ SUCCESS_CODES = %w[pending success]
92
+ FAILURE_CODES = %w[badcard fraud]
93
+
94
+ self.default_currency = 'USD'
95
+ self.supported_countries = ['US']
96
+ self.supported_cardtypes = %i[visa master american_express discover]
97
+ self.homepage_url = 'http://www.plugnpay.com/'
98
+ self.display_name = "Plug'n Pay"
99
+
100
+ def initialize(options = {})
101
+ requires!(options, :login, :password)
102
+ super
103
+ end
104
+
105
+ def purchase(money, creditcard, options = {})
106
+ post = PlugnpayPostData.new
107
+
108
+ add_amount(post, money, options)
109
+ add_creditcard(post, creditcard)
110
+ add_addresses(post, options)
111
+ add_invoice_data(post, options)
112
+ add_customer_data(post, options)
113
+
114
+ post[:authtype] = 'authpostauth'
115
+ commit(:authorization, post)
116
+ end
117
+
118
+ def authorize(money, creditcard, options = {})
119
+ post = PlugnpayPostData.new
120
+
121
+ add_amount(post, money, options)
122
+ add_creditcard(post, creditcard)
123
+ add_addresses(post, options)
124
+ add_invoice_data(post, options)
125
+ add_customer_data(post, options)
126
+
127
+ post[:authtype] = 'authonly'
128
+ commit(:authorization, post)
129
+ end
130
+
131
+ def capture(money, authorization, options = {})
132
+ post = PlugnpayPostData.new
133
+
134
+ post[:orderID] = authorization
135
+
136
+ add_amount(post, money, options)
137
+ add_customer_data(post, options)
138
+
139
+ commit(:capture, post)
140
+ end
141
+
142
+ def void(authorization, options = {})
143
+ post = PlugnpayPostData.new
144
+
145
+ post[:orderID] = authorization
146
+ post[:txn_type] = 'auth'
147
+
148
+ commit(:void, post)
149
+ end
150
+
151
+ def credit(money, identification_or_creditcard, options = {})
152
+ post = PlugnpayPostData.new
153
+ add_amount(post, money, options)
154
+
155
+ if identification_or_creditcard.is_a?(String)
156
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
157
+ refund(money, identification_or_creditcard, options)
158
+ else
159
+ add_creditcard(post, identification_or_creditcard)
160
+ add_addresses(post, options)
161
+ add_customer_data(post, options)
162
+
163
+ commit(:credit, post)
164
+ end
165
+ end
166
+
167
+ def refund(money, reference, options = {})
168
+ post = PlugnpayPostData.new
169
+ add_amount(post, money, options)
170
+ post[:orderID] = reference
171
+ commit(:refund, post)
172
+ end
173
+
174
+ private
175
+
176
+ def commit(action, post)
177
+ response = parse(ssl_post(self.live_url, post_data(action, post)))
178
+ success = SUCCESS_CODES.include?(response[:finalstatus])
179
+ message = success ? 'Success' : message_from(response)
180
+
181
+ Response.new(success, message, response,
182
+ test: test?,
183
+ authorization: response[:orderid],
184
+ avs_result: { code: response[:avs_code] },
185
+ cvv_result: response[:cvvresp])
186
+ end
187
+
188
+ def parse(body)
189
+ body = CGI.unescape(body)
190
+ results = {}
191
+ body.split('&').collect { |e| e.split('=') }.each do |key, value|
192
+ results[key.downcase.to_sym] = normalize(value.to_s.strip)
193
+ end
194
+
195
+ results.delete(:publisher_password)
196
+ results[:avs_message] = AVS_MESSAGES[results[:avs_code]] if results[:avs_code]
197
+ results[:card_code_message] = CARD_CODE_MESSAGES[results[:cvvresp]] if results[:cvvresp]
198
+
199
+ results
200
+ end
201
+
202
+ def post_data(action, post)
203
+ post[:mode] = TRANSACTIONS[action]
204
+ post[:convert] = 'underscores'
205
+ post[:app_level] = 0
206
+ post[:publisher_name] = @options[:login]
207
+ post[:publisher_password] = @options[:password]
208
+
209
+ post.to_s
210
+ end
211
+
212
+ def add_creditcard(post, creditcard)
213
+ post[:card_number] = creditcard.number
214
+ post[:card_cvv] = creditcard.verification_value
215
+ post[:card_exp] = expdate(creditcard)
216
+ post[:card_name] = creditcard.name.slice(0..38)
217
+ end
218
+
219
+ def add_customer_data(post, options)
220
+ post[:email] = options[:email]
221
+ post[:dontsndmail] = 'yes' unless options[:send_email_confirmation]
222
+ post[:ipaddress] = options[:ip]
223
+ end
224
+
225
+ def add_invoice_data(post, options)
226
+ post[:shipping] = amount(options[:shipping]) unless options[:shipping].blank?
227
+ post[:tax] = amount(options[:tax]) unless options[:tax].blank?
228
+ end
229
+
230
+ def add_addresses(post, options)
231
+ if address = options[:billing_address] || options[:address]
232
+ post[:card_address1] = address[:address1]
233
+ post[:card_zip] = address[:zip]
234
+ post[:card_city] = address[:city]
235
+ post[:card_country] = address[:country]
236
+ post[:phone] = address[:phone]
237
+
238
+ case address[:country]
239
+ when 'US', 'CA'
240
+ post[:card_state] = address[:state]
241
+ else
242
+ post[:card_state] = 'ZZ'
243
+ post[:card_prov] = address[:state]
244
+ end
245
+ end
246
+
247
+ if shipping_address = options[:shipping_address] || address
248
+ post[:shipname] = shipping_address[:name]
249
+ post[:address1] = shipping_address[:address1]
250
+ post[:address2] = shipping_address[:address2]
251
+ post[:city] = shipping_address[:city]
252
+
253
+ case shipping_address[:country]
254
+ when 'US', 'CA'
255
+ post[:state] = shipping_address[:state]
256
+ else
257
+ post[:state] = 'ZZ'
258
+ post[:province] = shipping_address[:state]
259
+ end
260
+
261
+ post[:country] = shipping_address[:country]
262
+ post[:zip] = shipping_address[:zip]
263
+ end
264
+ end
265
+
266
+ def add_amount(post, money, options)
267
+ post[:card_amount] = amount(money)
268
+ post[:currency] = options[:currency] || currency(money)
269
+ end
270
+
271
+ def message_from(results)
272
+ PAYMENT_GATEWAY_RESPONSES[results[:resp_code]]
273
+ end
274
+
275
+ def expdate(creditcard)
276
+ year = sprintf('%.4i', creditcard.year)
277
+ month = sprintf('%.2i', creditcard.month)
278
+
279
+ "#{month}/#{year[-2..-1]}"
280
+ end
281
+ end
282
+ end
283
+ end
@@ -0,0 +1,392 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class PriorityGateway < Gateway
4
+ # Sandbox and Production
5
+ self.test_url = 'https://sandbox.api.mxmerchant.com/checkout/v3/payment'
6
+ self.live_url = 'https://api.mxmerchant.com/checkout/v3/payment'
7
+
8
+ class_attribute :test_url_verify, :live_url_verify, :test_auth, :live_auth, :test_env_verify, :live_env_verify, :test_url_batch, :live_url_batch, :test_url_jwt, :live_url_jwt, :merchant
9
+
10
+ # Sandbox and Production - verify card
11
+ self.test_url_verify = 'https://sandbox-api2.mxmerchant.com/merchant/v1/bin'
12
+ self.live_url_verify = 'https://api2.mxmerchant.com/merchant/v1/bin'
13
+
14
+ # Sandbox and Production - check batch status
15
+ self.test_url_batch = 'https://sandbox.api.mxmerchant.com/checkout/v3/batch'
16
+ self.live_url_batch = 'https://api.mxmerchant.com/checkout/v3/batch'
17
+
18
+ # Sandbox and Production - generate jwt for verify card url
19
+ self.test_url_jwt = 'https://sandbox-api2.mxmerchant.com/security/v1/application/merchantId'
20
+ self.live_url_jwt = 'https://api2.mxmerchant.com/security/v1/application/merchantId'
21
+
22
+ self.supported_countries = ['US']
23
+ self.default_currency = 'USD'
24
+ self.supported_cardtypes = %i[visa master american_express discover]
25
+
26
+ self.homepage_url = 'https://mxmerchant.com/'
27
+ self.display_name = 'Priority'
28
+
29
+ def initialize(options = {})
30
+ requires!(options, :merchant_id, :api_key, :secret)
31
+ super
32
+ end
33
+
34
+ def basic_auth
35
+ Base64.strict_encode64("#{@options[:api_key]}:#{@options[:secret]}")
36
+ end
37
+
38
+ def request_headers
39
+ {
40
+ 'Content-Type' => 'application/json',
41
+ 'Authorization' => "Basic #{basic_auth}"
42
+ }
43
+ end
44
+
45
+ def request_verify_headers(jwt)
46
+ {
47
+ 'Authorization' => "Bearer #{jwt}"
48
+ }
49
+ end
50
+
51
+ def purchase(amount, credit_card, options = {})
52
+ params = {}
53
+ params['authOnly'] = false
54
+ params['isSettleFunds'] = true
55
+
56
+ add_merchant_id(params)
57
+ add_amount(params, amount, options)
58
+ add_auth_purchase_params(params, credit_card, options)
59
+
60
+ commit('purchase', params: params)
61
+ end
62
+
63
+ def authorize(amount, credit_card, options = {})
64
+ params = {}
65
+ params['authOnly'] = true
66
+ params['isSettleFunds'] = false
67
+
68
+ add_merchant_id(params)
69
+ add_amount(params, amount, options)
70
+ add_auth_purchase_params(params, credit_card, options)
71
+
72
+ commit('purchase', params: params)
73
+ end
74
+
75
+ def credit(amount, credit_card, options = {})
76
+ params = {}
77
+ params['authOnly'] = false
78
+ params['isSettleFunds'] = true
79
+ amount = -amount
80
+
81
+ add_merchant_id(params)
82
+ add_amount(params, amount, options)
83
+ add_credit_params(params, credit_card, options)
84
+ commit('credit', params: params)
85
+ end
86
+
87
+ def refund(amount, authorization, options = {})
88
+ params = {}
89
+ add_merchant_id(params)
90
+ params['paymentToken'] = payment_token(authorization) || options[:payment_token]
91
+
92
+ # refund amounts must be negative
93
+ params['amount'] = ('-' + localized_amount(amount.to_f, options[:currency])).to_f
94
+
95
+ commit('refund', params: params)
96
+ end
97
+
98
+ def capture(amount, authorization, options = {})
99
+ params = {}
100
+ add_merchant_id(params)
101
+ add_amount(params, amount, options)
102
+ params['paymentToken'] = payment_token(authorization) || options[:payment_token]
103
+ params['tenderType'] = options[:tender_type].present? ? options[:tender_type] : 'Card'
104
+
105
+ commit('capture', params: params)
106
+ end
107
+
108
+ def void(authorization, options = {})
109
+ params = {}
110
+
111
+ commit('void', params: params, iid: payment_id(authorization))
112
+ end
113
+
114
+ def verify(credit_card, _options = {})
115
+ jwt = create_jwt.params['jwtToken']
116
+
117
+ commit('verify', card_number: credit_card.number, jwt: jwt)
118
+ end
119
+
120
+ def get_payment_status(batch_id)
121
+ commit('get_payment_status', params: batch_id)
122
+ end
123
+
124
+ def close_batch(batch_id)
125
+ commit('close_batch', params: batch_id)
126
+ end
127
+
128
+ def create_jwt
129
+ commit('create_jwt', params: @options[:merchant_id])
130
+ end
131
+
132
+ def supports_scrubbing?
133
+ true
134
+ end
135
+
136
+ def scrub(transcript)
137
+ transcript.
138
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
139
+ gsub(%r((number\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
140
+ gsub(%r((cvv\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]')
141
+ end
142
+
143
+ private
144
+
145
+ def add_amount(params, amount, options)
146
+ params['amount'] = localized_amount(amount.to_f, options[:currency])
147
+ end
148
+
149
+ def add_merchant_id(params)
150
+ params['merchantId'] = @options[:merchant_id]
151
+ end
152
+
153
+ def add_auth_purchase_params(params, credit_card, options)
154
+ add_replay_id(params, options)
155
+ add_credit_card(params, credit_card, 'purchase', options)
156
+ add_purchases_data(params, options)
157
+ add_shipping_data(params, options)
158
+ add_pos_data(params, options)
159
+ add_additional_data(params, options)
160
+ end
161
+
162
+ def add_credit_params(params, credit_card, options)
163
+ add_replay_id(params, options)
164
+ add_credit_card(params, credit_card, 'purchase', options)
165
+ add_additional_data(params, options)
166
+ end
167
+
168
+ def add_replay_id(params, options)
169
+ params['replayId'] = options[:replay_id] if options[:replay_id]
170
+ end
171
+
172
+ def add_credit_card(params, credit_card, action, options)
173
+ return unless credit_card&.is_a?(CreditCard)
174
+
175
+ card_details = {}
176
+ card_details['expiryMonth'] = format(credit_card.month, :two_digits).to_s
177
+ card_details['expiryYear'] = format(credit_card.year, :two_digits).to_s
178
+ card_details['cardType'] = credit_card.brand
179
+ card_details['last4'] = credit_card.last_digits
180
+ card_details['cvv'] = credit_card.verification_value unless credit_card.verification_value.nil?
181
+ card_details['number'] = credit_card.number
182
+ card_details['avsStreet'] = options[:billing_address][:address1] if options[:billing_address]
183
+ card_details['avsZip'] = options[:billing_address][:zip] if !options[:billing_address].nil? && !options[:billing_address][:zip].nil?
184
+
185
+ params['cardAccount'] = card_details
186
+ end
187
+
188
+ def exp_date(credit_card)
189
+ "#{format(credit_card.month, :two_digits)}/#{format(credit_card.year, :two_digits)}"
190
+ end
191
+
192
+ def add_additional_data(params, options)
193
+ params['isAuth'] = options[:is_auth].present? ? options[:is_auth] : 'true'
194
+ params['paymentType'] = options[:payment_type].present? ? options[:payment_type] : 'Sale'
195
+ params['tenderType'] = options[:tender_type].present? ? options[:tender_type] : 'Card'
196
+ params['taxExempt'] = options[:tax_exempt].present? ? options[:tax_exempt] : 'false'
197
+ params['taxAmount'] = options[:tax_amount] if options[:tax_amount]
198
+ params['shouldGetCreditCardLevel'] = options[:should_get_credit_card_level] if options[:should_get_credit_card_level]
199
+ params['source'] = options[:source] if options[:source]
200
+ params['invoice'] = options[:invoice] if options[:invoice]
201
+ params['isTicket'] = options[:is_ticket] if options[:is_ticket]
202
+ params['shouldVaultCard'] = options[:should_vault_card] if options[:should_vault_card]
203
+ params['sourceZip'] = options[:source_zip] if options[:source_zip]
204
+ params['authCode'] = options[:auth_code] if options[:auth_code]
205
+ params['achIndicator'] = options[:ach_indicator] if options[:ach_indicator]
206
+ params['bankAccount'] = options[:bank_account] if options[:bank_account]
207
+ params['meta'] = options[:meta] if options[:meta]
208
+ end
209
+
210
+ def add_pos_data(params, options)
211
+ pos_data = {}
212
+ pos_data['cardholderPresence'] = options.dig(:pos_data, :cardholder_presence) || 'Ecom'
213
+ pos_data['deviceAttendance'] = options.dig(:pos_data, :device_attendance) || 'HomePc'
214
+ pos_data['deviceInputCapability'] = options.dig(:pos_data, :device_input_capability) || 'Unknown'
215
+ pos_data['deviceLocation'] = options.dig(:pos_data, :device_location) || 'HomePc'
216
+ pos_data['panCaptureMethod'] = options.dig(:pos_data, :pan_capture_method) || 'Manual'
217
+ pos_data['partialApprovalSupport'] = options.dig(:pos_data, :partial_approval_support) || 'NotSupported'
218
+ pos_data['pinCaptureCapability'] = options.dig(:pos_data, :pin_capture_capability) || 'Incapable'
219
+
220
+ params['posData'] = pos_data
221
+ end
222
+
223
+ def add_purchases_data(params, options)
224
+ return unless options[:purchases]
225
+
226
+ params['purchases'] = []
227
+
228
+ options[:purchases].each do |purchase|
229
+ purchase_object = {}
230
+
231
+ purchase_object['name'] = purchase[:name] if purchase[:name]
232
+ purchase_object['description'] = purchase[:description] if purchase[:description]
233
+ purchase_object['code'] = purchase[:code] if purchase[:code]
234
+ purchase_object['unitOfMeasure'] = purchase[:unit_of_measure] if purchase[:unit_of_measure]
235
+ purchase_object['unitPrice'] = purchase[:unit_price] if purchase[:unit_price]
236
+ purchase_object['quantity'] = purchase[:quantity] if purchase[:quantity]
237
+ purchase_object['taxRate'] = purchase[:tax_rate] if purchase[:tax_rate]
238
+ purchase_object['taxAmount'] = purchase[:tax_amount] if purchase[:tax_amount]
239
+ purchase_object['discountRate'] = purchase[:discount_rate] if purchase[:discount_rate]
240
+ purchase_object['discountAmount'] = purchase[:discount_amount] if purchase[:discount_amount]
241
+ purchase_object['extendedAmount'] = purchase[:extended_amount] if purchase[:extended_amount]
242
+ purchase_object['lineItemId'] = purchase[:line_item_id] if purchase[:line_item_id]
243
+
244
+ params['purchases'].append(purchase_object)
245
+ end
246
+ end
247
+
248
+ def add_shipping_data(params, options)
249
+ params['shipAmount'] = options[:ship_amount] if options[:ship_amount]
250
+
251
+ shipping_country = shipping_country_from(options)
252
+ params['shipToCountry'] = shipping_country if shipping_country
253
+
254
+ shipping_zip = shipping_zip_from(options)
255
+ params['shipToZip'] = shipping_zip if shipping_zip
256
+ end
257
+
258
+ def shipping_country_from(options)
259
+ options[:ship_to_country] || options.dig(:shipping_address, :country) || options.dig(:billing_address, :country)
260
+ end
261
+
262
+ def shipping_zip_from(options)
263
+ options[:ship_to_zip] || options.dig(:shipping_addres, :zip) || options.dig(:billing_address, :zip)
264
+ end
265
+
266
+ def payment_token(authorization)
267
+ return unless authorization
268
+ return authorization unless authorization.include?('|')
269
+
270
+ authorization.split('|').last
271
+ end
272
+
273
+ def payment_id(authorization)
274
+ return unless authorization
275
+ return authorization unless authorization.include?('|')
276
+
277
+ authorization.split('|').first
278
+ end
279
+
280
+ def commit(action, params: '', iid: '', card_number: nil, jwt: '')
281
+ response =
282
+ begin
283
+ case action
284
+ when 'void'
285
+ parse(ssl_request(:delete, url(action, params, ref_number: iid), nil, request_headers))
286
+ when 'verify'
287
+ parse(ssl_get(url(action, params, credit_card_number: card_number), request_verify_headers(jwt)))
288
+ when 'get_payment_status', 'create_jwt'
289
+ parse(ssl_get(url(action, params, ref_number: iid), request_headers))
290
+ when 'close_batch'
291
+ parse(ssl_request(:put, url(action, params, ref_number: iid), nil, request_headers))
292
+ else
293
+ parse(ssl_post(url(action, params), post_data(params), request_headers))
294
+ end
295
+ rescue ResponseError => e
296
+ # currently Priority returns a 404 with no body on certain calls. In those cases we will substitute the response status from response.message
297
+ gateway_response = e.response.body.presence || e.response.message
298
+ parse(gateway_response)
299
+ end
300
+
301
+ success = success_from(response, action)
302
+ Response.new(
303
+ success,
304
+ message_from(response),
305
+ response,
306
+ authorization: success ? authorization_from(response) : nil,
307
+ error_code: success || response == '' ? nil : error_from(response),
308
+ test: test?
309
+ )
310
+ end
311
+
312
+ def url(action, params, ref_number: '', credit_card_number: nil)
313
+ case action
314
+ when 'void'
315
+ base_url + "/#{ref_number}?force=true"
316
+ when 'verify'
317
+ (verify_url + '?search=') + credit_card_number.to_s[0..6]
318
+ when 'get_payment_status', 'close_batch'
319
+ batch_url + "/#{params}"
320
+ when 'create_jwt'
321
+ jwt_url + "/#{params}/token"
322
+ else
323
+ base_url + '?includeCustomerMatches=false&echo=true'
324
+ end
325
+ end
326
+
327
+ def base_url
328
+ test? ? test_url : live_url
329
+ end
330
+
331
+ def verify_url
332
+ test? ? self.test_url_verify : self.live_url_verify
333
+ end
334
+
335
+ def jwt_url
336
+ test? ? self.test_url_jwt : self.live_url_jwt
337
+ end
338
+
339
+ def batch_url
340
+ test? ? self.test_url_batch : self.live_url_batch
341
+ end
342
+
343
+ def handle_response(response)
344
+ case response.code.to_i
345
+ when 204
346
+ { status: 'Success' }.to_json
347
+ when 200...300
348
+ response.body
349
+ else
350
+ raise ResponseError.new(response)
351
+ end
352
+ end
353
+
354
+ def parse(body)
355
+ return {} if body.blank?
356
+
357
+ parsed_response = JSON.parse(body)
358
+ parsed_response.is_a?(String) ? { 'message' => parsed_response } : parsed_response
359
+ rescue JSON::ParserError
360
+ message = 'Invalid JSON response received from Priority Gateway. Please contact Priority Gateway if you continue to receive this message.'
361
+ message += " (The raw response returned by the API was #{body.inspect})"
362
+ {
363
+ 'message' => message
364
+ }
365
+ end
366
+
367
+ def success_from(response, action)
368
+ return !response['bank'].empty? if action == 'verify' && response['bank']
369
+
370
+ %w[Approved Open Success Settled Voided].include?(response['status'])
371
+ end
372
+
373
+ def message_from(response)
374
+ return response['details'][0] if response['details'] && response['details'][0]
375
+
376
+ response['authMessage'] || response['message'] || response['status']
377
+ end
378
+
379
+ def authorization_from(response)
380
+ [response['id'], response['paymentToken']].join('|')
381
+ end
382
+
383
+ def error_from(response)
384
+ response['errorCode'] || response['status']
385
+ end
386
+
387
+ def post_data(params)
388
+ params.to_json
389
+ end
390
+ end
391
+ end
392
+ end