archetype2142_activemerchant 1.124.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (271) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +3640 -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 +80 -0
  10. data/lib/active_merchant/billing/compatibility.rb +118 -0
  11. data/lib/active_merchant/billing/credit_card.rb +414 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +444 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +37 -0
  15. data/lib/active_merchant/billing/gateway.rb +331 -0
  16. data/lib/active_merchant/billing/gateways/adyen.rb +712 -0
  17. data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +1107 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +424 -0
  20. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +977 -0
  21. data/lib/active_merchant/billing/gateways/axcessms.rb +179 -0
  22. data/lib/active_merchant/billing/gateways/balanced.rb +263 -0
  23. data/lib/active_merchant/billing/gateways/bambora_apac.rb +222 -0
  24. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  25. data/lib/active_merchant/billing/gateways/banwire.rb +116 -0
  26. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +396 -0
  27. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
  28. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  29. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +474 -0
  30. data/lib/active_merchant/billing/gateways/beanstream.rb +220 -0
  31. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +57 -0
  32. data/lib/active_merchant/billing/gateways/blue_pay.rb +549 -0
  33. data/lib/active_merchant/billing/gateways/blue_snap.rb +613 -0
  34. data/lib/active_merchant/billing/gateways/bogus.rb +186 -0
  35. data/lib/active_merchant/billing/gateways/borgun.rb +231 -0
  36. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  37. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +23 -0
  38. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  39. data/lib/active_merchant/billing/gateways/braintree_blue.rb +832 -0
  40. data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
  41. data/lib/active_merchant/billing/gateways/bridge_pay.rb +244 -0
  42. data/lib/active_merchant/billing/gateways/cams.rb +230 -0
  43. data/lib/active_merchant/billing/gateways/card_connect.rb +320 -0
  44. data/lib/active_merchant/billing/gateways/card_save.rb +21 -0
  45. data/lib/active_merchant/billing/gateways/card_stream.rb +371 -0
  46. data/lib/active_merchant/billing/gateways/cardknox.rb +327 -0
  47. data/lib/active_merchant/billing/gateways/cardprocess.rb +256 -0
  48. data/lib/active_merchant/billing/gateways/cashnet.rb +225 -0
  49. data/lib/active_merchant/billing/gateways/cc5.rb +198 -0
  50. data/lib/active_merchant/billing/gateways/cecabank.rb +249 -0
  51. data/lib/active_merchant/billing/gateways/cenpos.rb +328 -0
  52. data/lib/active_merchant/billing/gateways/checkout.rb +212 -0
  53. data/lib/active_merchant/billing/gateways/checkout_v2.rb +311 -0
  54. data/lib/active_merchant/billing/gateways/citrus_pay.rb +21 -0
  55. data/lib/active_merchant/billing/gateways/clearhaus.rb +219 -0
  56. data/lib/active_merchant/billing/gateways/commercegate.rb +142 -0
  57. data/lib/active_merchant/billing/gateways/conekta.rb +230 -0
  58. data/lib/active_merchant/billing/gateways/creditcall.rb +272 -0
  59. data/lib/active_merchant/billing/gateways/credorax.rb +496 -0
  60. data/lib/active_merchant/billing/gateways/ct_payment.rb +269 -0
  61. data/lib/active_merchant/billing/gateways/culqi.rb +279 -0
  62. data/lib/active_merchant/billing/gateways/cyber_source.rb +1074 -0
  63. data/lib/active_merchant/billing/gateways/d_local.rb +253 -0
  64. data/lib/active_merchant/billing/gateways/data_cash.rb +302 -0
  65. data/lib/active_merchant/billing/gateways/decidir.rb +331 -0
  66. data/lib/active_merchant/billing/gateways/dibs.rb +199 -0
  67. data/lib/active_merchant/billing/gateways/digitzs.rb +295 -0
  68. data/lib/active_merchant/billing/gateways/ebanx.rb +333 -0
  69. data/lib/active_merchant/billing/gateways/efsnet.rb +215 -0
  70. data/lib/active_merchant/billing/gateways/elavon.rb +472 -0
  71. data/lib/active_merchant/billing/gateways/element.rb +386 -0
  72. data/lib/active_merchant/billing/gateways/epay.rb +296 -0
  73. data/lib/active_merchant/billing/gateways/evo_ca.rb +307 -0
  74. data/lib/active_merchant/billing/gateways/eway.rb +226 -0
  75. data/lib/active_merchant/billing/gateways/eway_managed.rb +289 -0
  76. data/lib/active_merchant/billing/gateways/eway_rapid.rb +578 -0
  77. data/lib/active_merchant/billing/gateways/exact.rb +219 -0
  78. data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
  79. data/lib/active_merchant/billing/gateways/fat_zebra.rb +223 -0
  80. data/lib/active_merchant/billing/gateways/federated_canada.rb +158 -0
  81. data/lib/active_merchant/billing/gateways/finansbank.rb +22 -0
  82. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  83. data/lib/active_merchant/billing/gateways/first_pay.rb +182 -0
  84. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +452 -0
  85. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +505 -0
  86. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  87. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  88. data/lib/active_merchant/billing/gateways/forte.rb +286 -0
  89. data/lib/active_merchant/billing/gateways/garanti.rb +256 -0
  90. data/lib/active_merchant/billing/gateways/global_collect.rb +463 -0
  91. data/lib/active_merchant/billing/gateways/global_transport.rb +193 -0
  92. data/lib/active_merchant/billing/gateways/hdfc.rb +205 -0
  93. data/lib/active_merchant/billing/gateways/hps.rb +472 -0
  94. data/lib/active_merchant/billing/gateways/iats_payments.rb +312 -0
  95. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  96. data/lib/active_merchant/billing/gateways/inspire.rb +213 -0
  97. data/lib/active_merchant/billing/gateways/instapay.rb +159 -0
  98. data/lib/active_merchant/billing/gateways/ipg.rb +390 -0
  99. data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
  100. data/lib/active_merchant/billing/gateways/iridium.rb +467 -0
  101. data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
  102. data/lib/active_merchant/billing/gateways/iveri.rb +254 -0
  103. data/lib/active_merchant/billing/gateways/ixopay.rb +320 -0
  104. data/lib/active_merchant/billing/gateways/jetpay.rb +395 -0
  105. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +432 -0
  106. data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
  107. data/lib/active_merchant/billing/gateways/kushki.rb +270 -0
  108. data/lib/active_merchant/billing/gateways/latitude19.rb +412 -0
  109. data/lib/active_merchant/billing/gateways/linkpoint.rb +448 -0
  110. data/lib/active_merchant/billing/gateways/litle.rb +531 -0
  111. data/lib/active_merchant/billing/gateways/mastercard.rb +293 -0
  112. data/lib/active_merchant/billing/gateways/maxipago.rb +220 -0
  113. data/lib/active_merchant/billing/gateways/mercado_pago.rb +329 -0
  114. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +194 -0
  115. data/lib/active_merchant/billing/gateways/merchant_one.rb +110 -0
  116. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  117. data/lib/active_merchant/billing/gateways/merchant_ware.rb +313 -0
  118. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +284 -0
  119. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +248 -0
  120. data/lib/active_merchant/billing/gateways/mercury.rb +352 -0
  121. data/lib/active_merchant/billing/gateways/metrics_global.rb +293 -0
  122. data/lib/active_merchant/billing/gateways/micropayment.rb +182 -0
  123. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  124. data/lib/active_merchant/billing/gateways/migs.rb +329 -0
  125. data/lib/active_merchant/billing/gateways/mit.rb +260 -0
  126. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  127. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +215 -0
  128. data/lib/active_merchant/billing/gateways/moka.rb +290 -0
  129. data/lib/active_merchant/billing/gateways/monei.rb +422 -0
  130. data/lib/active_merchant/billing/gateways/moneris.rb +446 -0
  131. data/lib/active_merchant/billing/gateways/money_movers.rb +150 -0
  132. data/lib/active_merchant/billing/gateways/mundipagg.rb +363 -0
  133. data/lib/active_merchant/billing/gateways/nab_transact.rb +299 -0
  134. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +163 -0
  135. data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
  136. data/lib/active_merchant/billing/gateways/netaxept.rb +180 -0
  137. data/lib/active_merchant/billing/gateways/netbanx.rb +376 -0
  138. data/lib/active_merchant/billing/gateways/netbilling.rb +229 -0
  139. data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
  140. data/lib/active_merchant/billing/gateways/network_merchants.rb +238 -0
  141. data/lib/active_merchant/billing/gateways/nmi.rb +356 -0
  142. data/lib/active_merchant/billing/gateways/ogone.rb +481 -0
  143. data/lib/active_merchant/billing/gateways/omise.rb +323 -0
  144. data/lib/active_merchant/billing/gateways/openpay.rb +229 -0
  145. data/lib/active_merchant/billing/gateways/opp.rb +394 -0
  146. data/lib/active_merchant/billing/gateways/optimal_payment.rb +331 -0
  147. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +45 -0
  148. data/lib/active_merchant/billing/gateways/orbital.rb +1209 -0
  149. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +206 -0
  150. data/lib/active_merchant/billing/gateways/pagarme.rb +239 -0
  151. data/lib/active_merchant/billing/gateways/pago_facil.rb +120 -0
  152. data/lib/active_merchant/billing/gateways/pay_arc.rb +392 -0
  153. data/lib/active_merchant/billing/gateways/pay_conex.rb +245 -0
  154. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +277 -0
  155. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  156. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  157. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +206 -0
  158. data/lib/active_merchant/billing/gateways/pay_secure.rb +110 -0
  159. data/lib/active_merchant/billing/gateways/pay_trace.rb +404 -0
  160. data/lib/active_merchant/billing/gateways/paybox_direct.rb +224 -0
  161. data/lib/active_merchant/billing/gateways/payeezy.rb +458 -0
  162. data/lib/active_merchant/billing/gateways/payex.rb +409 -0
  163. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +235 -0
  164. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +42 -0
  165. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  166. data/lib/active_merchant/billing/gateways/payflow.rb +411 -0
  167. data/lib/active_merchant/billing/gateways/payflow_express.rb +220 -0
  168. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +14 -0
  169. data/lib/active_merchant/billing/gateways/payflow_uk.rb +20 -0
  170. data/lib/active_merchant/billing/gateways/payment_express.rb +373 -0
  171. data/lib/active_merchant/billing/gateways/paymentez.rb +327 -0
  172. data/lib/active_merchant/billing/gateways/paymill.rb +369 -0
  173. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +718 -0
  174. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
  175. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  176. data/lib/active_merchant/billing/gateways/paypal.rb +136 -0
  177. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  178. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  179. data/lib/active_merchant/billing/gateways/paypal_express.rb +270 -0
  180. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  181. data/lib/active_merchant/billing/gateways/paysafe.rb +412 -0
  182. data/lib/active_merchant/billing/gateways/payscout.rb +159 -0
  183. data/lib/active_merchant/billing/gateways/paystation.rb +204 -0
  184. data/lib/active_merchant/billing/gateways/payu_in.rb +249 -0
  185. data/lib/active_merchant/billing/gateways/payu_latam.rb +469 -0
  186. data/lib/active_merchant/billing/gateways/payu_polska.rb +178 -0
  187. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  188. data/lib/active_merchant/billing/gateways/payway_dot_com.rb +253 -0
  189. data/lib/active_merchant/billing/gateways/pin.rb +246 -0
  190. data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
  191. data/lib/active_merchant/billing/gateways/priority.rb +390 -0
  192. data/lib/active_merchant/billing/gateways/pro_pay.rb +325 -0
  193. data/lib/active_merchant/billing/gateways/psigate.rb +227 -0
  194. data/lib/active_merchant/billing/gateways/psl_card.rb +295 -0
  195. data/lib/active_merchant/billing/gateways/qbms.rb +302 -0
  196. data/lib/active_merchant/billing/gateways/quantum.rb +274 -0
  197. data/lib/active_merchant/billing/gateways/quickbooks.rb +377 -0
  198. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +184 -0
  199. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +297 -0
  200. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +226 -0
  201. data/lib/active_merchant/billing/gateways/quickpay.rb +24 -0
  202. data/lib/active_merchant/billing/gateways/qvalent.rb +305 -0
  203. data/lib/active_merchant/billing/gateways/realex.rb +400 -0
  204. data/lib/active_merchant/billing/gateways/redsys.rb +718 -0
  205. data/lib/active_merchant/billing/gateways/s5.rb +247 -0
  206. data/lib/active_merchant/billing/gateways/safe_charge.rb +301 -0
  207. data/lib/active_merchant/billing/gateways/sage.rb +446 -0
  208. data/lib/active_merchant/billing/gateways/sage_pay.rb +434 -0
  209. data/lib/active_merchant/billing/gateways/sallie_mae.rb +141 -0
  210. data/lib/active_merchant/billing/gateways/secure_net.rb +260 -0
  211. data/lib/active_merchant/billing/gateways/secure_pay.rb +191 -0
  212. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +290 -0
  213. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +103 -0
  214. data/lib/active_merchant/billing/gateways/securion_pay.rb +265 -0
  215. data/lib/active_merchant/billing/gateways/skip_jack.rb +450 -0
  216. data/lib/active_merchant/billing/gateways/smart_ps.rb +274 -0
  217. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  218. data/lib/active_merchant/billing/gateways/spreedly_core.rb +312 -0
  219. data/lib/active_merchant/billing/gateways/stripe.rb +813 -0
  220. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +463 -0
  221. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +151 -0
  222. data/lib/active_merchant/billing/gateways/telr.rb +273 -0
  223. data/lib/active_merchant/billing/gateways/tns.rb +26 -0
  224. data/lib/active_merchant/billing/gateways/trans_first.rb +240 -0
  225. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +612 -0
  226. data/lib/active_merchant/billing/gateways/transact_pro.rb +222 -0
  227. data/lib/active_merchant/billing/gateways/transax.rb +21 -0
  228. data/lib/active_merchant/billing/gateways/transnational.rb +9 -0
  229. data/lib/active_merchant/billing/gateways/trexle.rb +221 -0
  230. data/lib/active_merchant/billing/gateways/trust_commerce.rb +489 -0
  231. data/lib/active_merchant/billing/gateways/usa_epay.rb +24 -0
  232. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1612 -0
  233. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +353 -0
  234. data/lib/active_merchant/billing/gateways/vanco.rb +294 -0
  235. data/lib/active_merchant/billing/gateways/verifi.rb +224 -0
  236. data/lib/active_merchant/billing/gateways/viaklix.rb +171 -0
  237. data/lib/active_merchant/billing/gateways/visanet_peru.rb +246 -0
  238. data/lib/active_merchant/billing/gateways/vpos.rb +220 -0
  239. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  240. data/lib/active_merchant/billing/gateways/wepay.rb +235 -0
  241. data/lib/active_merchant/billing/gateways/wirecard.rb +430 -0
  242. data/lib/active_merchant/billing/gateways/wompi.rb +153 -0
  243. data/lib/active_merchant/billing/gateways/world_net.rb +345 -0
  244. data/lib/active_merchant/billing/gateways/worldpay.rb +923 -0
  245. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +208 -0
  246. data/lib/active_merchant/billing/gateways/worldpay_us.rb +221 -0
  247. data/lib/active_merchant/billing/gateways.rb +14 -0
  248. data/lib/active_merchant/billing/model.rb +30 -0
  249. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
  250. data/lib/active_merchant/billing/payment_token.rb +21 -0
  251. data/lib/active_merchant/billing/rails.rb +3 -0
  252. data/lib/active_merchant/billing/response.rb +97 -0
  253. data/lib/active_merchant/billing/three_d_secure_eci_mapper.rb +27 -0
  254. data/lib/active_merchant/billing.rb +16 -0
  255. data/lib/active_merchant/connection.rb +196 -0
  256. data/lib/active_merchant/country.rb +337 -0
  257. data/lib/active_merchant/empty.rb +20 -0
  258. data/lib/active_merchant/errors.rb +35 -0
  259. data/lib/active_merchant/net_http_ssl_connection.rb +11 -0
  260. data/lib/active_merchant/network_connection_retries.rb +78 -0
  261. data/lib/active_merchant/post_data.rb +26 -0
  262. data/lib/active_merchant/posts_data.rb +92 -0
  263. data/lib/active_merchant/version.rb +3 -0
  264. data/lib/active_merchant.rb +63 -0
  265. data/lib/activemerchant.rb +1 -0
  266. data/lib/certs/cacert.pem +3214 -0
  267. data/lib/support/gateway_support.rb +69 -0
  268. data/lib/support/outbound_hosts.rb +28 -0
  269. data/lib/support/ssl_verify.rb +88 -0
  270. data/lib/support/ssl_version.rb +86 -0
  271. metadata +463 -0
@@ -0,0 +1,412 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class PaysafeGateway < Gateway
4
+ self.test_url = 'https://api.test.paysafe.com'
5
+ self.live_url = 'https://api.paysafe.com'
6
+
7
+ self.supported_countries = %w(AL AT BE BA BG CA HR CY CZ DK EE FI FR DE GR HU IS IE IT LV LI LT LU MT ME NL MK NO PL PT RO RS SK SI ES SE CH TR GB US)
8
+ self.supported_cardtypes = %i[visa master american_express discover]
9
+
10
+ self.homepage_url = 'https://www.paysafe.com/'
11
+ self.display_name = 'Paysafe'
12
+
13
+ def initialize(options = {})
14
+ requires!(options, :username, :password, :account_id)
15
+ super
16
+ end
17
+
18
+ def purchase(money, payment, options = {})
19
+ post = {}
20
+ add_invoice(post, money, options)
21
+ add_payment(post, payment)
22
+ add_billing_address(post, options)
23
+ add_merchant_details(post, options)
24
+ add_airline_travel_details(post, options)
25
+ add_customer_data(post, payment, options) unless payment.is_a?(String)
26
+ add_three_d_secure(post, payment, options) if options[:three_d_secure]
27
+ add_stored_credential(post, options) if options[:stored_credential]
28
+ add_split_pay_details(post, options)
29
+ post[:settleWithAuth] = true
30
+
31
+ commit(:post, 'auths', post, options)
32
+ end
33
+
34
+ def authorize(money, payment, options = {})
35
+ post = {}
36
+ add_invoice(post, money, options)
37
+ add_payment(post, payment)
38
+ add_billing_address(post, options)
39
+ add_merchant_details(post, options)
40
+ add_customer_data(post, payment, options) unless payment.is_a?(String)
41
+ add_three_d_secure(post, payment, options) if options[:three_d_secure]
42
+ add_stored_credential(post, options) if options[:stored_credential]
43
+
44
+ commit(:post, 'auths', post, options)
45
+ end
46
+
47
+ def capture(money, authorization, options = {})
48
+ post = {}
49
+ add_invoice(post, money, options)
50
+
51
+ commit(:post, "auths/#{authorization}/settlements", post, options)
52
+ end
53
+
54
+ def refund(money, authorization, options = {})
55
+ post = {}
56
+ add_invoice(post, money, options)
57
+
58
+ commit(:post, "settlements/#{authorization}/refunds", post, options)
59
+ end
60
+
61
+ def void(authorization, options = {})
62
+ post = {}
63
+ money = options[:amount]
64
+ add_invoice(post, money, options)
65
+
66
+ commit(:post, "auths/#{authorization}/voidauths", post, options)
67
+ end
68
+
69
+ def credit(money, payment, options = {})
70
+ post = {}
71
+ add_invoice(post, money, options)
72
+ add_payment(post, payment)
73
+
74
+ commit(:post, 'standalonecredits', post, options)
75
+ end
76
+
77
+ # This is a '$0 auth' done at a specific verification endpoint at the gateway
78
+ def verify(payment, options = {})
79
+ post = {}
80
+ add_payment(post, payment)
81
+ add_billing_address(post, options)
82
+ add_customer_data(post, payment, options) unless payment.is_a?(String)
83
+
84
+ commit(:post, 'verifications', post, options)
85
+ end
86
+
87
+ def store(payment, options = {})
88
+ post = {}
89
+ add_payment(post, payment)
90
+ add_address_for_vaulting(post, options)
91
+ add_profile_data(post, payment, options)
92
+ add_store_data(post, payment, options)
93
+
94
+ commit(:post, 'profiles', post, options)
95
+ end
96
+
97
+ def redact(pm_profile_id)
98
+ commit_for_redact(:delete, "profiles/#{pm_profile_id}", nil, nil)
99
+ end
100
+
101
+ def supports_scrubbing?
102
+ true
103
+ end
104
+
105
+ def scrub(transcript)
106
+ transcript.
107
+ gsub(%r((Authorization: Basic )[a-zA-Z0-9:_]+), '\1[FILTERED]').
108
+ gsub(%r(("cardNum\\?":\\?")\d+), '\1[FILTERED]').
109
+ gsub(%r(("cvv\\?":\\?")\d+), '\1[FILTERED]')
110
+ end
111
+
112
+ private
113
+
114
+ # Customer data can be included in transactions where the payment method is a credit card
115
+ # but should not be sent when the payment method is a token
116
+ def add_customer_data(post, creditcard, options)
117
+ post[:profile] = {}
118
+ post[:profile][:firstName] = creditcard.first_name
119
+ post[:profile][:lastName] = creditcard.last_name
120
+ post[:profile][:email] = options[:email] if options[:email]
121
+ post[:customerIp] = options[:ip] if options[:ip]
122
+ end
123
+
124
+ def add_billing_address(post, options)
125
+ return unless address = options[:billing_address] || options[:address]
126
+
127
+ post[:billingDetails] = {}
128
+ post[:billingDetails][:street] = address[:address1]
129
+ post[:billingDetails][:city] = address[:city]
130
+ post[:billingDetails][:state] = address[:state]
131
+ post[:billingDetails][:country] = address[:country]
132
+ post[:billingDetails][:zip] = address[:zip]
133
+ post[:billingDetails][:phone] = address[:phone]
134
+ end
135
+
136
+ # The add_address_for_vaulting method is applicable to the store method, as the APIs address
137
+ # object is formatted differently from the standard transaction billing address
138
+ def add_address_for_vaulting(post, options)
139
+ return unless address = options[:billing_address] || options[:address]
140
+
141
+ post[:card][:billingAddress] = {}
142
+ post[:card][:billingAddress][:street] = address[:address1]
143
+ post[:card][:billingAddress][:street2] = address[:address2]
144
+ post[:card][:billingAddress][:city] = address[:city]
145
+ post[:card][:billingAddress][:zip] = address[:zip]
146
+ post[:card][:billingAddress][:country] = address[:country]
147
+ post[:card][:billingAddress][:state] = address[:state] if address[:state]
148
+ end
149
+
150
+ # This data is specific to creating a profile at the gateway's vault level
151
+ def add_profile_data(post, payment, options)
152
+ post[:firstName] = payment.first_name
153
+ post[:lastName] = payment.last_name
154
+ post[:dateOfBirth] = {}
155
+ post[:dateOfBirth][:year] = options[:date_of_birth][:year]
156
+ post[:dateOfBirth][:month] = options[:date_of_birth][:month]
157
+ post[:dateOfBirth][:day] = options[:date_of_birth][:day]
158
+ post[:email] = options[:email] if options[:email]
159
+ post[:ip] = options[:ip] if options[:ip]
160
+
161
+ if options[:phone]
162
+ post[:phone] = options[:phone]
163
+ elsif address = options[:billing_address] || options[:address]
164
+ post[:phone] = address[:phone] if address[:phone]
165
+ end
166
+ end
167
+
168
+ def add_store_data(post, payment, options)
169
+ post[:merchantCustomerId] = options[:customer_id] || SecureRandom.hex(12)
170
+ post[:locale] = options[:locale] || 'en_US'
171
+ post[:card][:holderName] = payment.name
172
+ end
173
+
174
+ # Paysafe expects minor units so we are not calling amount method on money parameter
175
+ def add_invoice(post, money, options)
176
+ post[:amount] = money
177
+ end
178
+
179
+ def add_payment(post, payment)
180
+ if payment.is_a?(String)
181
+ post[:card] = {}
182
+ post[:card][:paymentToken] = payment
183
+ else
184
+ post[:card] = { cardExpiry: {} }
185
+ post[:card][:cardNum] = payment.number
186
+ post[:card][:cardExpiry][:month] = payment.month
187
+ post[:card][:cardExpiry][:year] = payment.year
188
+ post[:card][:cvv] = payment.verification_value
189
+ end
190
+ end
191
+
192
+ def add_merchant_details(post, options)
193
+ return unless options[:merchant_descriptor]
194
+
195
+ post[:merchantDescriptor] = {}
196
+ post[:merchantDescriptor][:dynamicDescriptor] = options[:merchant_descriptor][:dynamic_descriptor] if options[:merchant_descriptor][:dynamic_descriptor]
197
+ post[:merchantDescriptor][:phone] = options[:merchant_descriptor][:phone] if options[:merchant_descriptor][:phone]
198
+ end
199
+
200
+ def add_three_d_secure(post, payment, options)
201
+ three_d_secure = options[:three_d_secure]
202
+
203
+ post[:authentication] = {}
204
+ post[:authentication][:eci] = three_d_secure[:eci]
205
+ post[:authentication][:cavv] = three_d_secure[:cavv]
206
+ post[:authentication][:xid] = three_d_secure[:xid] if three_d_secure[:xid]
207
+ post[:authentication][:threeDSecureVersion] = three_d_secure[:version]
208
+ post[:authentication][:directoryServerTransactionId] = three_d_secure[:ds_transaction_id] unless payment.is_a?(String) || !mastercard?(payment)
209
+ end
210
+
211
+ def add_airline_travel_details(post, options)
212
+ return unless options[:airline_travel_details]
213
+
214
+ post[:airlineTravelDetails] = {}
215
+ post[:airlineTravelDetails][:passengerName] = options[:airline_travel_details][:passenger_name] if options[:airline_travel_details][:passenger_name]
216
+ post[:airlineTravelDetails][:departureDate] = options[:airline_travel_details][:departure_date] if options[:airline_travel_details][:departure_date]
217
+ post[:airlineTravelDetails][:origin] = options[:airline_travel_details][:origin] if options[:airline_travel_details][:origin]
218
+ post[:airlineTravelDetails][:computerizedReservationSystem] = options[:airline_travel_details][:computerized_reservation_system] if options[:airline_travel_details][:computerized_reservation_system]
219
+ post[:airlineTravelDetails][:customerReferenceNumber] = options[:airline_travel_details][:customer_reference_number] if options[:airline_travel_details][:customer_reference_number]
220
+
221
+ add_ticket_details(post, options)
222
+ add_travel_agency_details(post, options)
223
+ add_trip_legs(post, options)
224
+ end
225
+
226
+ def add_ticket_details(post, options)
227
+ return unless ticket = options[:airline_travel_details][:ticket]
228
+
229
+ post[:airlineTravelDetails][:ticket] = {}
230
+ post[:airlineTravelDetails][:ticket][:ticketNumber] = ticket[:ticket_number] if ticket[:ticket_number]
231
+ post[:airlineTravelDetails][:ticket][:isRestrictedTicket] = ticket[:is_restricted_ticket] if ticket[:is_restricted_ticket]
232
+ end
233
+
234
+ def add_travel_agency_details(post, options)
235
+ return unless agency = options[:airline_travel_details][:travel_agency]
236
+
237
+ post[:airlineTravelDetails][:travelAgency] = {}
238
+ post[:airlineTravelDetails][:travelAgency][:name] = agency[:name] if agency[:name]
239
+ post[:airlineTravelDetails][:travelAgency][:code] = agency[:code] if agency[:code]
240
+ end
241
+
242
+ def add_trip_legs(post, options)
243
+ return unless trip_legs = options[:airline_travel_details][:trip_legs]
244
+
245
+ trip_legs_hash = {}
246
+ trip_legs.each.with_index(1) do |leg, i|
247
+ my_leg = "leg#{i}".to_sym
248
+ details = add_leg_details(my_leg, leg[1])
249
+
250
+ trip_legs_hash[my_leg] = details
251
+ end
252
+ post[:airlineTravelDetails][:tripLegs] = trip_legs_hash
253
+ end
254
+
255
+ def add_leg_details(obj, leg)
256
+ details = {}
257
+ add_flight_details(details, obj, leg)
258
+ details[:serviceClass] = leg[:service_class] if leg[:service_class]
259
+ details[:isStopOverAllowed] = leg[:is_stop_over_allowed] if leg[:is_stop_over_allowed]
260
+ details[:destination] = leg[:destination] if leg[:destination]
261
+ details[:fareBasis] = leg[:fare_basis] if leg[:fare_basis]
262
+ details[:departureDate] = leg[:departure_date] if leg[:departure_date]
263
+
264
+ details
265
+ end
266
+
267
+ def add_flight_details(details, obj, leg)
268
+ details[:flight] = {}
269
+ details[:flight][:carrierCode] = leg[:flight][:carrier_code] if leg[:flight][:carrier_code]
270
+ details[:flight][:flightNumber] = leg[:flight][:flight_number] if leg[:flight][:flight_number]
271
+ end
272
+
273
+ def add_split_pay_details(post, options)
274
+ return unless options[:split_pay]
275
+
276
+ split_pay = []
277
+ options[:split_pay].each do |pmnt|
278
+ split = {}
279
+
280
+ split[:linkedAccount] = pmnt[:linked_account]
281
+ split[:amount] = pmnt[:amount].to_i if pmnt[:amount]
282
+ split[:percent] = pmnt[:percent].to_i if pmnt[:percent]
283
+
284
+ split_pay << split
285
+ end
286
+ post[:splitpay] = split_pay
287
+ end
288
+
289
+ def add_stored_credential(post, options)
290
+ return unless options[:stored_credential]
291
+
292
+ post[:storedCredential] = {}
293
+
294
+ case options[:stored_credential][:initial_transaction]
295
+ when true
296
+ post[:storedCredential][:occurrence] = 'INITIAL'
297
+ when false
298
+ post[:storedCredential][:occurrence] = 'SUBSEQUENT'
299
+ end
300
+
301
+ case options[:stored_credential][:reason_type]
302
+ when 'recurring' || 'installment'
303
+ post[:storedCredential][:type] = 'RECURRING'
304
+ when 'unscheduled'
305
+ if options[:stored_credential][:initiator] == 'merchant'
306
+ post[:storedCredential][:type] = 'TOPUP'
307
+ elsif options[:stored_credential][:initiator] == 'cardholder'
308
+ post[:storedCredential][:type] = 'ADHOC'
309
+ else
310
+ return
311
+ end
312
+ end
313
+
314
+ post[:storedCredential][:initialTransactionId] = options[:stored_credential][:network_transaction_id] if options[:stored_credential][:network_transaction_id]
315
+ end
316
+
317
+ def mastercard?(payment)
318
+ return false unless payment.respond_to?(:brand)
319
+
320
+ payment.brand == 'master'
321
+ end
322
+
323
+ def parse(body)
324
+ JSON.parse(body)
325
+ end
326
+
327
+ def commit(method, action, parameters, options)
328
+ url = url(action)
329
+ raw_response = ssl_request(method, url, post_data(parameters, options), headers)
330
+ response = parse(raw_response)
331
+ success = success_from(response)
332
+
333
+ Response.new(
334
+ success,
335
+ message_from(success, response),
336
+ response,
337
+ authorization: authorization_from(action, response),
338
+ avs_result: AVSResult.new(code: response['avsResponse']),
339
+ cvv_result: CVVResult.new(response['cvvVerification']),
340
+ test: test?,
341
+ error_code: success ? nil : error_code_from(response)
342
+ )
343
+ end
344
+
345
+ def commit_for_redact(method, action, parameters, options)
346
+ url = url(action)
347
+ response = raw_ssl_request(method, url, post_data(parameters, options), headers)
348
+ success = true if response.code == '200'
349
+
350
+ Response.new(
351
+ success,
352
+ message: response.message
353
+ )
354
+ end
355
+
356
+ def headers
357
+ {
358
+ 'Content-Type' => 'application/json',
359
+ 'Authorization' => 'Basic ' + Base64.strict_encode64("#{@options[:username]}:#{@options[:password]}")
360
+ }
361
+ end
362
+
363
+ def url(action, options = {})
364
+ base_url = (test? ? test_url : live_url)
365
+
366
+ if action.include? 'profiles'
367
+ "#{base_url}/customervault/v1/#{action}"
368
+ else
369
+ "#{base_url}/cardpayments/v1/accounts/#{@options[:account_id]}/#{action}"
370
+ end
371
+ end
372
+
373
+ def success_from(response)
374
+ return false if response['status'] == 'FAILED' || response['error']
375
+
376
+ true
377
+ end
378
+
379
+ def message_from(success, response)
380
+ return response['status'] unless response['error']
381
+
382
+ "Error(s)- code:#{response['error']['code']}, message:#{response['error']['message']}"
383
+ end
384
+
385
+ def authorization_from(action, response)
386
+ if action == 'profiles'
387
+ response['cards'].first['paymentToken']
388
+ else
389
+ response['id']
390
+ end
391
+ end
392
+
393
+ def post_data(parameters = {}, options = {})
394
+ return unless parameters.present?
395
+
396
+ parameters[:merchantRefNum] = options[:merchant_ref_num] || SecureRandom.hex(16).to_s
397
+
398
+ parameters.to_json
399
+ end
400
+
401
+ def error_code_from(response)
402
+ return unless response['error']
403
+
404
+ response['error']['code']
405
+ end
406
+
407
+ def handle_response(response)
408
+ response.body
409
+ end
410
+ end
411
+ end
412
+ end
@@ -0,0 +1,159 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class PayscoutGateway < Gateway
4
+ self.live_url = self.test_url = 'https://secure.payscout.com/api/transact.php'
5
+
6
+ self.supported_countries = ['US']
7
+ self.supported_cardtypes = %i[visa master american_express discover]
8
+ self.default_currency = 'USD'
9
+ self.homepage_url = 'http://www.payscout.com/'
10
+ self.display_name = 'Payscout'
11
+
12
+ def initialize(options = {})
13
+ requires!(options, :username, :password)
14
+ super
15
+ end
16
+
17
+ def authorize(money, creditcard, options = {})
18
+ post = {}
19
+ add_invoice(post, options)
20
+ add_creditcard(post, creditcard)
21
+ add_currency(post, money, options)
22
+ add_address(post, options)
23
+
24
+ commit('auth', money, post)
25
+ end
26
+
27
+ def purchase(money, creditcard, options = {})
28
+ post = {}
29
+ add_invoice(post, options)
30
+ add_creditcard(post, creditcard)
31
+ add_currency(post, money, options)
32
+ add_address(post, options)
33
+
34
+ commit('sale', money, post)
35
+ end
36
+
37
+ def capture(money, authorization, options = {})
38
+ post = {}
39
+ post[:transactionid] = authorization
40
+
41
+ commit('capture', money, post)
42
+ end
43
+
44
+ def refund(money, authorization, options = {})
45
+ post = {}
46
+ post[:transactionid] = authorization
47
+
48
+ commit('refund', money, post)
49
+ end
50
+
51
+ def void(authorization, options = {})
52
+ post = {}
53
+ post[:transactionid] = authorization
54
+
55
+ commit('void', nil, post)
56
+ end
57
+
58
+ private
59
+
60
+ def add_address(post, options)
61
+ if address = options[:billing_address] || options[:address]
62
+ post[:address1] = address[:address1].to_s
63
+ post[:address2] = address[:address2].to_s
64
+ post[:city] = address[:city].to_s
65
+ post[:state] = (address[:state].blank? ? 'n/a' : address[:state])
66
+ post[:zip] = address[:zip].to_s
67
+ post[:country] = address[:country].to_s
68
+ post[:phone] = address[:phone].to_s
69
+ post[:fax] = address[:fax].to_s
70
+ post[:email] = address[:email].to_s
71
+ end
72
+
73
+ if address = options[:shipping_address]
74
+ post[:shipping_firstname] = address[:first_name].to_s
75
+ post[:shipping_lastname] = address[:last_name].to_s
76
+ post[:shipping_company] = address[:company].to_s
77
+ post[:shipping_address1] = address[:address1].to_s
78
+ post[:shipping_address2] = address[:address2].to_s
79
+ post[:shipping_city] = address[:city].to_s
80
+ post[:shipping_country] = address[:country].to_s
81
+ post[:shipping_state] = (address[:state].blank? ? 'n/a' : address[:state])
82
+ post[:shipping_zip] = address[:zip].to_s
83
+ post[:shipping_email] = address[:email].to_s
84
+ end
85
+ end
86
+
87
+ def add_currency(post, money, options)
88
+ post[:currency] = options[:currency] || currency(money)
89
+ end
90
+
91
+ def add_invoice(post, options)
92
+ post[:orderdescription] = options[:description]
93
+ post[:orderid] = options[:order_id]
94
+ end
95
+
96
+ def add_creditcard(post, creditcard)
97
+ post[:ccnumber] = creditcard.number
98
+ post[:cvv] = creditcard.verification_value if creditcard.verification_value?
99
+ post[:ccexp] = expdate(creditcard)
100
+ post[:firstname] = creditcard.first_name
101
+ post[:lastname] = creditcard.last_name
102
+ end
103
+
104
+ def parse(body)
105
+ Hash[body.split('&').map { |x| x.split('=') }]
106
+ end
107
+
108
+ def commit(action, money, parameters)
109
+ parameters[:amount] = amount(money) unless action == 'void'
110
+ url = (test? ? self.test_url : self.live_url)
111
+ data = ssl_post(url, post_data(action, parameters))
112
+
113
+ response = parse(data)
114
+ response[:action] = action
115
+
116
+ message = message_from(response)
117
+ test_mode = (test? || message =~ /TESTMODE/)
118
+ Response.new(success?(response), message, response,
119
+ test: test_mode,
120
+ authorization: response['transactionid'],
121
+ fraud_review: fraud_review?(response),
122
+ avs_result: { code: response['avsresponse'] },
123
+ cvv_result: response['cvvresponse'])
124
+ end
125
+
126
+ def message_from(response)
127
+ case response['response']
128
+ when '1'
129
+ 'The transaction has been approved'
130
+ when '2'
131
+ 'The transaction has been declined'
132
+ when '3'
133
+ response['responsetext']
134
+ else
135
+ 'There was an error processing the transaction'
136
+ end
137
+ end
138
+
139
+ def fraud_review?(response)
140
+ false
141
+ end
142
+
143
+ def success?(response)
144
+ (response['response'] == '1')
145
+ end
146
+
147
+ def post_data(action, parameters = {})
148
+ post = {}
149
+
150
+ post[:username] = @options[:username]
151
+ post[:password] = @options[:password]
152
+ post[:type] = action
153
+
154
+ request = post.merge(parameters).collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&')
155
+ request
156
+ end
157
+ end
158
+ end
159
+ end