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,434 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class SagePayGateway < Gateway
4
+ cattr_accessor :simulate
5
+ self.simulate = false
6
+
7
+ class_attribute :simulator_url
8
+
9
+ self.test_url = 'https://test.sagepay.com/gateway/service'
10
+ self.live_url = 'https://live.sagepay.com/gateway/service'
11
+ self.simulator_url = 'https://test.sagepay.com/Simulator'
12
+
13
+ APPROVED = 'OK'
14
+
15
+ TRANSACTIONS = {
16
+ purchase: 'PAYMENT',
17
+ credit: 'REFUND',
18
+ authorization: 'DEFERRED',
19
+ capture: 'RELEASE',
20
+ void: 'VOID',
21
+ abort: 'ABORT',
22
+ store: 'TOKEN',
23
+ unstore: 'REMOVETOKEN',
24
+ repeat: 'REPEAT'
25
+ }
26
+
27
+ CREDIT_CARDS = {
28
+ visa: 'VISA',
29
+ master: 'MC',
30
+ delta: 'DELTA',
31
+ maestro: 'MAESTRO',
32
+ american_express: 'AMEX',
33
+ electron: 'UKE',
34
+ diners_club: 'DC',
35
+ jcb: 'JCB'
36
+ }
37
+
38
+ AVS_CODE = {
39
+ 'NOTPROVIDED' => nil,
40
+ 'NOTCHECKED' => 'X',
41
+ 'MATCHED' => 'Y',
42
+ 'NOTMATCHED' => 'N'
43
+ }
44
+
45
+ CVV_CODE = {
46
+ 'NOTPROVIDED' => 'S',
47
+ 'NOTCHECKED' => 'X',
48
+ 'MATCHED' => 'M',
49
+ 'NOTMATCHED' => 'N'
50
+ }
51
+
52
+ OPTIONAL_REQUEST_FIELDS = {
53
+ paypal_callback_url: :PayPalCallbackURL,
54
+ basket: :Basket,
55
+ gift_aid_payment: :GiftAidPayment,
56
+ apply_avscv2: :ApplyAVSCV2,
57
+ apply_3d_secure: :Apply3DSecure,
58
+ account_type: :AccountType,
59
+ billing_agreement: :BillingAgreement,
60
+ basket_xml: :BasketXML,
61
+ customer_xml: :CustomerXML,
62
+ surcharge_xml: :SurchargeXML,
63
+ vendor_data: :VendorData,
64
+ language: :Language,
65
+ website: :Website,
66
+ recipient_account_number: :FIRecipientAcctNumber,
67
+ recipient_surname: :FIRecipientSurname,
68
+ recipient_postcode: :FIRecipientPostcode,
69
+ recipient_dob: :FIRecipientDoB
70
+ }
71
+
72
+ self.supported_countries = %w[GB IE]
73
+ self.supported_cardtypes = %i[visa master american_express discover jcb maestro diners_club]
74
+ self.default_currency = 'GBP'
75
+
76
+ self.homepage_url = 'http://www.sagepay.com'
77
+ self.display_name = 'SagePay'
78
+
79
+ def initialize(options = {})
80
+ requires!(options, :login)
81
+ super
82
+ end
83
+
84
+ def purchase(money, payment_method, options = {})
85
+ requires!(options, :order_id)
86
+
87
+ post = {}
88
+
89
+ add_amount(post, money, options)
90
+ add_invoice(post, options)
91
+ add_payment_method(post, payment_method, options)
92
+ add_address(post, options)
93
+ add_customer_data(post, options)
94
+ add_optional_data(post, options)
95
+
96
+ commit((past_purchase_reference?(payment_method) ? :repeat : :purchase), post)
97
+ end
98
+
99
+ def authorize(money, payment_method, options = {})
100
+ requires!(options, :order_id)
101
+
102
+ post = {}
103
+
104
+ add_amount(post, money, options)
105
+ add_invoice(post, options)
106
+ add_payment_method(post, payment_method, options)
107
+ add_address(post, options)
108
+ add_customer_data(post, options)
109
+ add_optional_data(post, options)
110
+
111
+ commit(:authorization, post)
112
+ end
113
+
114
+ # You can only capture a transaction once, even if you didn't capture the full amount the first time.
115
+ def capture(money, identification, options = {})
116
+ post = {}
117
+
118
+ add_reference(post, identification)
119
+ add_release_amount(post, money, options)
120
+
121
+ commit(:capture, post)
122
+ end
123
+
124
+ def void(identification, options = {})
125
+ post = {}
126
+
127
+ add_reference(post, identification)
128
+ action = abort_or_void_from(identification)
129
+
130
+ commit(action, post)
131
+ end
132
+
133
+ # Refunding requires a new order_id to passed in, as well as a description
134
+ def refund(money, identification, options = {})
135
+ requires!(options, :order_id, :description)
136
+
137
+ post = {}
138
+
139
+ add_related_reference(post, identification)
140
+ add_amount(post, money, options)
141
+ add_invoice(post, options)
142
+
143
+ commit(:credit, post)
144
+ end
145
+
146
+ def credit(money, identification, options = {})
147
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
148
+ refund(money, identification, options)
149
+ end
150
+
151
+ def store(credit_card, options = {})
152
+ post = {}
153
+ add_credit_card(post, credit_card)
154
+ add_currency(post, 0, options)
155
+
156
+ commit(:store, post)
157
+ end
158
+
159
+ def unstore(token, options = {})
160
+ post = {}
161
+ add_token(post, token)
162
+ commit(:unstore, post)
163
+ end
164
+
165
+ def verify(credit_card, options = {})
166
+ MultiResponse.run(:use_first_response) do |r|
167
+ r.process { authorize(100, credit_card, options) }
168
+ r.process(:ignore_result) { void(r.authorization, options) }
169
+ end
170
+ end
171
+
172
+ def supports_scrubbing
173
+ true
174
+ end
175
+
176
+ def scrub(transcript)
177
+ transcript.
178
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
179
+ gsub(%r((&?CardNumber=)\d+(&?)), '\1[FILTERED]\2').
180
+ gsub(%r((&?CV2=)\d+(&?)), '\1[FILTERED]\2')
181
+ end
182
+
183
+ private
184
+
185
+ def truncate(value, max_size)
186
+ return nil unless value
187
+ return value.to_s if CGI.escape(value.to_s).length <= max_size
188
+
189
+ if value.size > max_size
190
+ truncate(super(value, max_size), max_size)
191
+ else
192
+ truncate(value.to_s.chop, max_size)
193
+ end
194
+ end
195
+
196
+ def add_reference(post, identification)
197
+ order_id, transaction_id, authorization, security_key = identification.split(';')
198
+
199
+ add_pair(post, :VendorTxCode, order_id)
200
+ add_pair(post, :VPSTxId, transaction_id)
201
+ add_pair(post, :TxAuthNo, authorization)
202
+ add_pair(post, :SecurityKey, security_key)
203
+ end
204
+
205
+ def add_related_reference(post, identification)
206
+ order_id, transaction_id, authorization, security_key = identification.split(';')
207
+
208
+ add_pair(post, :RelatedVendorTxCode, order_id)
209
+ add_pair(post, :RelatedVPSTxId, transaction_id)
210
+ add_pair(post, :RelatedTxAuthNo, authorization)
211
+ add_pair(post, :RelatedSecurityKey, security_key)
212
+ end
213
+
214
+ def add_amount(post, money, options)
215
+ currency = options[:currency] || currency(money)
216
+ add_pair(post, :Amount, localized_amount(money, currency), required: true)
217
+ add_pair(post, :Currency, currency, required: true)
218
+ end
219
+
220
+ def add_currency(post, money, options)
221
+ currency = options[:currency] || currency(money)
222
+ add_pair(post, :Currency, currency, required: true)
223
+ end
224
+
225
+ # doesn't actually use the currency -- dodgy!
226
+ def add_release_amount(post, money, options)
227
+ add_pair(post, :ReleaseAmount, amount(money), required: true)
228
+ end
229
+
230
+ def add_customer_data(post, options)
231
+ add_pair(post, :CustomerEMail, truncate(options[:email], 255)) unless options[:email].blank?
232
+ add_pair(post, :ClientIPAddress, options[:ip])
233
+ end
234
+
235
+ def add_optional_data(post, options)
236
+ add_pair(post, :CreateToken, 1) unless options[:store].blank?
237
+
238
+ OPTIONAL_REQUEST_FIELDS.each do |gateway_option, sagepay_field|
239
+ add_pair(post, sagepay_field, options[gateway_option])
240
+ end
241
+ end
242
+
243
+ def add_address(post, options)
244
+ if billing_address = options[:billing_address] || options[:address]
245
+ first_name, last_name = split_names(billing_address[:name])
246
+ add_pair(post, :BillingSurname, truncate(last_name, 20))
247
+ add_pair(post, :BillingFirstnames, truncate(first_name, 20))
248
+ add_pair(post, :BillingAddress1, truncate(billing_address[:address1], 100))
249
+ add_pair(post, :BillingAddress2, truncate(billing_address[:address2], 100))
250
+ add_pair(post, :BillingCity, truncate(billing_address[:city], 40))
251
+ add_pair(post, :BillingState, truncate(billing_address[:state], 2)) if usa?(billing_address[:country])
252
+ add_pair(post, :BillingCountry, truncate(billing_address[:country], 2))
253
+ add_pair(post, :BillingPhone, sanitize_phone(billing_address[:phone]))
254
+ add_pair(post, :BillingPostCode, truncate(billing_address[:zip], 10))
255
+ end
256
+
257
+ if shipping_address = options[:shipping_address] || billing_address
258
+ first_name, last_name = split_names(shipping_address[:name])
259
+ add_pair(post, :DeliverySurname, truncate(last_name, 20))
260
+ add_pair(post, :DeliveryFirstnames, truncate(first_name, 20))
261
+ add_pair(post, :DeliveryAddress1, truncate(shipping_address[:address1], 100))
262
+ add_pair(post, :DeliveryAddress2, truncate(shipping_address[:address2], 100))
263
+ add_pair(post, :DeliveryCity, truncate(shipping_address[:city], 40))
264
+ add_pair(post, :DeliveryState, truncate(shipping_address[:state], 2)) if usa?(shipping_address[:country])
265
+ add_pair(post, :DeliveryCountry, truncate(shipping_address[:country], 2))
266
+ add_pair(post, :DeliveryPhone, sanitize_phone(shipping_address[:phone]))
267
+ add_pair(post, :DeliveryPostCode, truncate(shipping_address[:zip], 10))
268
+ end
269
+ end
270
+
271
+ def add_invoice(post, options)
272
+ add_pair(post, :VendorTxCode, sanitize_order_id(options[:order_id]), required: true)
273
+ add_pair(post, :Description, truncate(options[:description] || options[:order_id], 100))
274
+ end
275
+
276
+ def add_payment_method(post, payment_method, options)
277
+ if payment_method.is_a?(String)
278
+ if past_purchase_reference?(payment_method)
279
+ add_related_reference(post, payment_method)
280
+ else
281
+ add_token_details(post, payment_method, options)
282
+ end
283
+ else
284
+ add_credit_card(post, payment_method)
285
+ end
286
+ end
287
+
288
+ def add_credit_card(post, credit_card)
289
+ add_pair(post, :CardHolder, truncate(credit_card.name, 50), required: true)
290
+ add_pair(post, :CardNumber, credit_card.number, required: true)
291
+
292
+ add_pair(post, :ExpiryDate, format_date(credit_card.month, credit_card.year), required: true)
293
+ add_pair(post, :CardType, map_card_type(credit_card))
294
+
295
+ add_pair(post, :CV2, credit_card.verification_value)
296
+ end
297
+
298
+ def add_token_details(post, token, options)
299
+ add_token(post, token)
300
+ add_pair(post, :StoreToken, options[:customer])
301
+ add_pair(post, :CV2, options[:verification_value])
302
+ end
303
+
304
+ def add_token(post, token)
305
+ add_pair(post, :Token, token)
306
+ end
307
+
308
+ def sanitize_order_id(order_id)
309
+ cleansed = order_id.to_s.gsub(/[^-a-zA-Z0-9._]/, '')
310
+ truncate(cleansed, 40)
311
+ end
312
+
313
+ def sanitize_phone(phone)
314
+ return nil unless phone
315
+
316
+ cleansed = phone.to_s.gsub(/[^0-9+]/, '')
317
+ truncate(cleansed, 20)
318
+ end
319
+
320
+ def usa?(country)
321
+ truncate(country, 2) == 'US'
322
+ end
323
+
324
+ def map_card_type(credit_card)
325
+ raise ArgumentError, 'The credit card type must be provided' if card_brand(credit_card).blank?
326
+
327
+ card_type = card_brand(credit_card).to_sym
328
+
329
+ if card_type == :visa && credit_card.electron?
330
+ CREDIT_CARDS[:electron]
331
+ else
332
+ CREDIT_CARDS[card_type]
333
+ end
334
+ end
335
+
336
+ # MMYY format
337
+ def format_date(month, year)
338
+ return nil if year.blank? || month.blank?
339
+
340
+ year = sprintf('%.4i', year)
341
+ month = sprintf('%.2i', month)
342
+
343
+ "#{month}#{year[-2..-1]}"
344
+ end
345
+
346
+ def commit(action, parameters)
347
+ response = parse(ssl_post(url_for(action), post_data(action, parameters)))
348
+
349
+ Response.new(response['Status'] == APPROVED, message_from(response), response,
350
+ test: test?,
351
+ authorization: authorization_from(response, parameters, action),
352
+ avs_result: {
353
+ street_match: AVS_CODE[response['AddressResult']],
354
+ postal_match: AVS_CODE[response['PostCodeResult']]
355
+ },
356
+ cvv_result: CVV_CODE[response['CV2Result']])
357
+ end
358
+
359
+ def authorization_from(response, params, action)
360
+ case action
361
+ when :store
362
+ response['Token']
363
+ else
364
+ [params[:VendorTxCode],
365
+ response['VPSTxId'] || params[:VPSTxId],
366
+ response['TxAuthNo'],
367
+ response['SecurityKey'] || params[:SecurityKey],
368
+ action].join(';')
369
+ end
370
+ end
371
+
372
+ def abort_or_void_from(identification)
373
+ original_transaction = identification.split(';').last
374
+ original_transaction == 'authorization' ? :abort : :void
375
+ end
376
+
377
+ def url_for(action)
378
+ simulate ? build_simulator_url(action) : build_url(action)
379
+ end
380
+
381
+ def build_url(action)
382
+ endpoint =
383
+ case action
384
+ when :purchase, :authorization then 'vspdirect-register'
385
+ when :store then 'directtoken'
386
+ else TRANSACTIONS[action].downcase
387
+ end
388
+ "#{test? ? self.test_url : self.live_url}/#{endpoint}.vsp"
389
+ end
390
+
391
+ def build_simulator_url(action)
392
+ endpoint = %i[purchase authorization].include?(action) ? 'VSPDirectGateway.asp' : "VSPServerGateway.asp?Service=Vendor#{TRANSACTIONS[action].capitalize}Tx"
393
+ "#{self.simulator_url}/#{endpoint}"
394
+ end
395
+
396
+ def message_from(response)
397
+ response['Status'] == APPROVED ? 'Success' : (response['StatusDetail'] || 'Unspecified error') # simonr 20080207 can't actually get non-nil blanks, so this is shorter
398
+ end
399
+
400
+ def post_data(action, parameters = {})
401
+ parameters.update(
402
+ Vendor: @options[:login],
403
+ TxType: TRANSACTIONS[action],
404
+ VPSProtocol: @options.fetch(:protocol_version, '3.00')
405
+ )
406
+
407
+ parameters.update(ReferrerID: application_id) if application_id && (application_id != Gateway.application_id)
408
+
409
+ parameters.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&')
410
+ end
411
+
412
+ # SagePay returns data in the following format
413
+ # Key1=value1
414
+ # Key2=value2
415
+ def parse(body)
416
+ result = {}
417
+ body.to_s.each_line do |pair|
418
+ result[$1] = $2 if pair.strip =~ /\A([^=]+)=(.+)\Z/im
419
+ end
420
+ result
421
+ end
422
+
423
+ def add_pair(post, key, value, options = {})
424
+ post[key] = value if !value.blank? || options[:required]
425
+ end
426
+
427
+ def past_purchase_reference?(payment_method)
428
+ return false unless payment_method.is_a?(String)
429
+
430
+ payment_method.split(';').last == 'purchase'
431
+ end
432
+ end
433
+ end
434
+ end
@@ -0,0 +1,141 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class SallieMaeGateway < Gateway
4
+ self.live_url = self.test_url = 'https://trans.salliemae.com/cgi-bin/process.cgi'
5
+
6
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
7
+ self.supported_countries = ['US']
8
+
9
+ # The card types supported by the payment gateway
10
+ self.supported_cardtypes = %i[visa master american_express discover]
11
+
12
+ # The homepage URL of the gateway
13
+ self.homepage_url = 'http://www.salliemae.com/'
14
+
15
+ # The name of the gateway
16
+ self.display_name = 'Sallie Mae'
17
+
18
+ def initialize(options = {})
19
+ requires!(options, :login)
20
+ super
21
+ end
22
+
23
+ def test?
24
+ @options[:login] == 'TEST0'
25
+ end
26
+
27
+ def authorize(money, creditcard, options = {})
28
+ post = PostData.new
29
+ add_invoice(post, options)
30
+ add_creditcard(post, creditcard)
31
+ add_address(post, creditcard, options)
32
+ add_customer_data(post, options)
33
+
34
+ commit(:authonly, money, post)
35
+ end
36
+
37
+ def purchase(money, creditcard, options = {})
38
+ post = PostData.new
39
+ add_invoice(post, options)
40
+ add_creditcard(post, creditcard)
41
+ add_address(post, creditcard, options)
42
+ add_customer_data(post, options)
43
+
44
+ commit(:sale, money, post)
45
+ end
46
+
47
+ def capture(money, authorization, options = {})
48
+ post = PostData.new
49
+ post[:postonly] = authorization
50
+ commit(:capture, money, post)
51
+ end
52
+
53
+ private
54
+
55
+ def add_customer_data(post, options)
56
+ if address = options[:billing_address] || options[:shipping_address] || options[:address]
57
+ post[:ci_phone] = address[:phone].to_s
58
+ end
59
+
60
+ post[:ci_email] = options[:email].to_s unless options[:email].blank?
61
+ post[:ci_IP] = options[:ip].to_s unless options[:ip].blank?
62
+ end
63
+
64
+ def add_address(post, creditcard, options)
65
+ if address = options[:billing_address] || options[:address]
66
+ post[:ci_billaddr1] = address[:address1].to_s
67
+ post[:ci_billaddr2] = address[:address2].to_s unless address[:address2].blank?
68
+ post[:ci_billcity] = address[:city].to_s
69
+ post[:ci_billstate] = address[:state].to_s
70
+ post[:ci_billzip] = address[:zip].to_s
71
+ end
72
+
73
+ if shipping_address = options[:shipping_address] || options[:address]
74
+ post[:ci_shipaddr1] = shipping_address[:address1].to_s
75
+ post[:ci_shipaddr2] = shipping_address[:address2].to_s unless shipping_address[:address2].blank?
76
+ post[:ci_shipcity] = shipping_address[:city].to_s
77
+ post[:ci_shipstate] = shipping_address[:state].to_s
78
+ post[:ci_shipzip] = shipping_address[:zip].to_s
79
+ end
80
+ end
81
+
82
+ def add_invoice(post, options)
83
+ memo = "OrderID: #{options[:order_id]}\nDescription: #{options[:description]}"
84
+ post[:ci_memo] = memo
85
+ end
86
+
87
+ def add_creditcard(post, creditcard)
88
+ post[:ccnum] = creditcard.number.to_s
89
+ post[:ccname] = creditcard.name.to_s
90
+ post[:cvv2] = creditcard.verification_value.to_s if creditcard.verification_value?
91
+ post[:expmon] = creditcard.month.to_s
92
+ post[:expyear] = creditcard.year.to_s
93
+ end
94
+
95
+ def parse(body)
96
+ h = {}
97
+ body.gsub!('<html><body><plaintext>', '')
98
+ body.
99
+ split("\r\n").
100
+ map do |i|
101
+ a = i.split('=')
102
+ h[a.first] = a.last unless a.first.nil?
103
+ end
104
+ h
105
+ end
106
+
107
+ def commit(action, money, parameters)
108
+ parameters[:acctid] = @options[:login].to_s
109
+ parameters[:subid] = @options[:sub_id].to_s unless @options[:sub_id].blank?
110
+ parameters[:amount] = amount(money)
111
+
112
+ case action
113
+ when :sale
114
+ parameters[:action] = 'ns_quicksale_cc'
115
+ when :authonly
116
+ parameters[:action] = 'ns_quicksale_cc'
117
+ parameters[:authonly] = 1
118
+ when :capture
119
+ parameters[:action] = 'ns_quicksale_cc'
120
+ end
121
+
122
+ response = parse(ssl_post(self.live_url, parameters.to_post_data) || '')
123
+ Response.new(successful?(response), message_from(response), response,
124
+ test: test?,
125
+ authorization: response['refcode'])
126
+ end
127
+
128
+ def successful?(response)
129
+ response['Status'] == 'Accepted'
130
+ end
131
+
132
+ def message_from(response)
133
+ if successful?(response)
134
+ 'Accepted'
135
+ else
136
+ response['Reason'].split(':')[2].capitalize unless response['Reason'].nil?
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end