activemerchant-nsp 1.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. data/CHANGELOG +952 -0
  2. data/CONTRIBUTORS +347 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +204 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant.rb +63 -0
  7. data/lib/active_merchant/billing.rb +9 -0
  8. data/lib/active_merchant/billing/avs_result.rb +98 -0
  9. data/lib/active_merchant/billing/base.rb +56 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +274 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +143 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  15. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  16. data/lib/active_merchant/billing/gateway.rb +176 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +695 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +943 -0
  20. data/lib/active_merchant/billing/gateways/balanced.rb +462 -0
  21. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  22. data/lib/active_merchant/billing/gateways/beanstream.rb +167 -0
  23. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +389 -0
  24. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  25. data/lib/active_merchant/billing/gateways/blue_pay.rb +492 -0
  26. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  27. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  28. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  29. data/lib/active_merchant/billing/gateways/braintree_blue.rb +389 -0
  30. data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
  31. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  32. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  33. data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
  34. data/lib/active_merchant/billing/gateways/cyber_source.rb +576 -0
  35. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  36. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  37. data/lib/active_merchant/billing/gateways/elavon.rb +137 -0
  38. data/lib/active_merchant/billing/gateways/epay.rb +276 -0
  39. data/lib/active_merchant/billing/gateways/eway.rb +287 -0
  40. data/lib/active_merchant/billing/gateways/eway_managed.rb +265 -0
  41. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  42. data/lib/active_merchant/billing/gateways/fat_zebra.rb +152 -0
  43. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  44. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  45. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  46. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +252 -0
  47. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  48. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  49. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  50. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  51. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  52. data/lib/active_merchant/billing/gateways/iridium.rb +257 -0
  53. data/lib/active_merchant/billing/gateways/itransact.rb +450 -0
  54. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  55. data/lib/active_merchant/billing/gateways/linkpoint.rb +451 -0
  56. data/lib/active_merchant/billing/gateways/litle.rb +290 -0
  57. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +157 -0
  58. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  59. data/lib/active_merchant/billing/gateways/metrics_global.rb +323 -0
  60. data/lib/active_merchant/billing/gateways/migs.rb +263 -0
  61. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  62. data/lib/active_merchant/billing/gateways/modern_payments.rb +38 -0
  63. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  64. data/lib/active_merchant/billing/gateways/moneris.rb +250 -0
  65. data/lib/active_merchant/billing/gateways/moneris_us.rb +211 -0
  66. data/lib/active_merchant/billing/gateways/nab_transact.rb +257 -0
  67. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  68. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  69. data/lib/active_merchant/billing/gateways/netbilling.rb +196 -0
  70. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  71. data/lib/active_merchant/billing/gateways/ogone.rb +427 -0
  72. data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
  73. data/lib/active_merchant/billing/gateways/orbital.rb +351 -0
  74. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  75. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +266 -0
  76. data/lib/active_merchant/billing/gateways/pay_junction.rb +397 -0
  77. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  78. data/lib/active_merchant/billing/gateways/paybox_direct.rb +201 -0
  79. data/lib/active_merchant/billing/gateways/payflow.rb +268 -0
  80. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +212 -0
  81. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  82. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  83. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  84. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  85. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  86. data/lib/active_merchant/billing/gateways/payment_express.rb +282 -0
  87. data/lib/active_merchant/billing/gateways/paypal.rb +106 -0
  88. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +653 -0
  89. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  90. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +245 -0
  91. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  92. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +43 -0
  93. data/lib/active_merchant/billing/gateways/paypal_express.rb +178 -0
  94. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  95. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  96. data/lib/active_merchant/billing/gateways/payway.rb +214 -0
  97. data/lib/active_merchant/billing/gateways/plugnpay.rb +295 -0
  98. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  99. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  100. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  101. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  102. data/lib/active_merchant/billing/gateways/quickpay.rb +298 -0
  103. data/lib/active_merchant/billing/gateways/realex.rb +313 -0
  104. data/lib/active_merchant/billing/gateways/sage.rb +148 -0
  105. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  106. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +115 -0
  107. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  108. data/lib/active_merchant/billing/gateways/sage_pay.rb +322 -0
  109. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  110. data/lib/active_merchant/billing/gateways/samurai.rb +121 -0
  111. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  112. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  113. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +284 -0
  114. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  115. data/lib/active_merchant/billing/gateways/skip_jack.rb +458 -0
  116. data/lib/active_merchant/billing/gateways/smart_ps.rb +273 -0
  117. data/lib/active_merchant/billing/gateways/stripe.rb +236 -0
  118. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  119. data/lib/active_merchant/billing/gateways/transax.rb +23 -0
  120. data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
  121. data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
  122. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1497 -0
  123. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +206 -0
  124. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  125. data/lib/active_merchant/billing/gateways/viaklix.rb +194 -0
  126. data/lib/active_merchant/billing/gateways/vindicia.rb +359 -0
  127. data/lib/active_merchant/billing/gateways/wirecard.rb +313 -0
  128. data/lib/active_merchant/billing/gateways/worldpay.rb +271 -0
  129. data/lib/active_merchant/billing/integrations.rb +17 -0
  130. data/lib/active_merchant/billing/integrations/action_view_helper.rb +73 -0
  131. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
  132. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
  133. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
  134. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  135. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  136. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  137. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  138. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  139. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  140. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  141. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  142. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  143. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  144. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  145. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  146. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  147. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  148. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  149. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  150. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  151. data/lib/active_merchant/billing/integrations/dotpay.rb +22 -0
  152. data/lib/active_merchant/billing/integrations/dotpay/helper.rb +77 -0
  153. data/lib/active_merchant/billing/integrations/dotpay/notification.rb +86 -0
  154. data/lib/active_merchant/billing/integrations/dotpay/return.rb +11 -0
  155. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  156. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
  157. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
  158. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  159. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  160. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  161. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  162. data/lib/active_merchant/billing/integrations/easy_pay.rb +30 -0
  163. data/lib/active_merchant/billing/integrations/easy_pay/common.rb +40 -0
  164. data/lib/active_merchant/billing/integrations/easy_pay/helper.rb +40 -0
  165. data/lib/active_merchant/billing/integrations/easy_pay/notification.rb +51 -0
  166. data/lib/active_merchant/billing/integrations/epay.rb +21 -0
  167. data/lib/active_merchant/billing/integrations/epay/helper.rb +55 -0
  168. data/lib/active_merchant/billing/integrations/epay/notification.rb +110 -0
  169. data/lib/active_merchant/billing/integrations/first_data.rb +38 -0
  170. data/lib/active_merchant/billing/integrations/first_data/helper.rb +63 -0
  171. data/lib/active_merchant/billing/integrations/first_data/notification.rb +56 -0
  172. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  173. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  174. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  175. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  176. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  177. data/lib/active_merchant/billing/integrations/helper.rb +117 -0
  178. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  179. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  180. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  181. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  182. data/lib/active_merchant/billing/integrations/maksuturva.rb +86 -0
  183. data/lib/active_merchant/billing/integrations/maksuturva/helper.rb +119 -0
  184. data/lib/active_merchant/billing/integrations/maksuturva/notification.rb +48 -0
  185. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  186. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  187. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  188. data/lib/active_merchant/billing/integrations/nelnet.rb +40 -0
  189. data/lib/active_merchant/billing/integrations/nelnet/helper.rb +34 -0
  190. data/lib/active_merchant/billing/integrations/nelnet/notification.rb +100 -0
  191. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  192. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  193. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  194. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  195. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  196. data/lib/active_merchant/billing/integrations/paxum.rb +44 -0
  197. data/lib/active_merchant/billing/integrations/paxum/common.rb +24 -0
  198. data/lib/active_merchant/billing/integrations/paxum/helper.rb +42 -0
  199. data/lib/active_merchant/billing/integrations/paxum/notification.rb +33 -0
  200. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  201. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
  202. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  203. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  204. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  205. data/lib/active_merchant/billing/integrations/paypal/notification.rb +155 -0
  206. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  207. data/lib/active_merchant/billing/integrations/paypal_payments_advanced.rb +20 -0
  208. data/lib/active_merchant/billing/integrations/paypal_payments_advanced/helper.rb +15 -0
  209. data/lib/active_merchant/billing/integrations/pxpay.rb +31 -0
  210. data/lib/active_merchant/billing/integrations/pxpay/helper.rb +110 -0
  211. data/lib/active_merchant/billing/integrations/pxpay/notification.rb +157 -0
  212. data/lib/active_merchant/billing/integrations/pxpay/return.rb +25 -0
  213. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  214. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +71 -0
  215. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  216. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  217. data/lib/active_merchant/billing/integrations/robokassa.rb +49 -0
  218. data/lib/active_merchant/billing/integrations/robokassa/common.rb +19 -0
  219. data/lib/active_merchant/billing/integrations/robokassa/helper.rb +50 -0
  220. data/lib/active_merchant/billing/integrations/robokassa/notification.rb +55 -0
  221. data/lib/active_merchant/billing/integrations/robokassa/return.rb +17 -0
  222. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  223. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  224. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +129 -0
  225. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  226. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  227. data/lib/active_merchant/billing/integrations/two_checkout.rb +44 -0
  228. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +91 -0
  229. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +139 -0
  230. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  231. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  232. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  233. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  234. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  235. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  236. data/lib/active_merchant/billing/integrations/verkkomaksut.rb +20 -0
  237. data/lib/active_merchant/billing/integrations/verkkomaksut/helper.rb +87 -0
  238. data/lib/active_merchant/billing/integrations/verkkomaksut/notification.rb +59 -0
  239. data/lib/active_merchant/billing/integrations/web_pay.rb +45 -0
  240. data/lib/active_merchant/billing/integrations/web_pay/common.rb +50 -0
  241. data/lib/active_merchant/billing/integrations/web_pay/helper.rb +68 -0
  242. data/lib/active_merchant/billing/integrations/web_pay/notification.rb +51 -0
  243. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  244. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  245. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  246. data/lib/active_merchant/billing/response.rb +64 -0
  247. data/lib/active_merchant/version.rb +3 -0
  248. data/lib/activemerchant.rb +1 -0
  249. data/lib/support/gateway_support.rb +65 -0
  250. data/lib/support/outbound_hosts.rb +25 -0
  251. data/lib/support/ssl_verify.rb +93 -0
  252. metadata +482 -0
@@ -0,0 +1,273 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'check.rb')
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class SmartPs < Gateway #:nodoc:
6
+
7
+ ##
8
+ # This is the base gateway for processors who use the smartPS processing system
9
+
10
+ self.abstract_class = true
11
+
12
+ def initialize(options = {})
13
+ requires!(options, :login, :password)
14
+ @options = options
15
+ super
16
+ end
17
+
18
+ # Pass :store => true in the options to store the
19
+ # payment info at the gateway and get a generated
20
+ # customer_vault_id in the response.
21
+ # Pass :store => some_number_or_string to specify the
22
+ # customer_vault_id the gateway should use (make sure it's
23
+ # unique).
24
+ def authorize(money, creditcard, options = {})
25
+ post = {}
26
+ add_invoice(post, options)
27
+ add_payment_source(post, creditcard,options)
28
+ add_address(post, options[:billing_address] || options[:address])
29
+ add_address(post, options[:shipping_address], "shipping")
30
+ add_customer_data(post, options)
31
+ add_currency(post, money, options)
32
+ add_taxes(post, options)
33
+ add_processor(post, options)
34
+ commit('auth', money, post)
35
+ end
36
+
37
+ def purchase(money, payment_source, options = {})
38
+ post = {}
39
+ add_invoice(post, options)
40
+ add_payment_source(post, payment_source, options)
41
+ add_address(post, options[:billing_address] || options[:address])
42
+ add_address(post, options[:shipping_address], "shipping")
43
+ add_customer_data(post, options)
44
+ add_currency(post, money, options)
45
+ add_taxes(post, options)
46
+ add_processor(post, options)
47
+ commit('sale', money, post)
48
+ end
49
+
50
+ def capture(money, authorization, options = {})
51
+ post ={}
52
+ post[:transactionid] = authorization
53
+ commit('capture', money, post)
54
+ end
55
+
56
+ def void(authorization, options = {})
57
+ post ={}
58
+ post[:transactionid] = authorization
59
+ commit('void', nil, post)
60
+ end
61
+
62
+ def credit(money, payment_source, options = {})
63
+ post = {}
64
+ add_invoice(post, options)
65
+ add_payment_source(post, payment_source, options)
66
+ add_address(post, options[:billing_address] || options[:address])
67
+ add_customer_data(post, options)
68
+ add_sku(post,options)
69
+ add_currency(post, money, options)
70
+ add_processor(post, options)
71
+ commit('credit', money, post)
72
+ end
73
+
74
+ def refund(money, auth, options = {})
75
+ post = {}
76
+ add_transaction(post, auth)
77
+ commit('refund', money, post)
78
+ end
79
+
80
+
81
+ # Update the values (such as CC expiration) stored at
82
+ # the gateway. The CC number must be supplied in the
83
+ # CreditCard object.
84
+ def update(vault_id, creditcard, options = {})
85
+ post = {}
86
+ post[:customer_vault] = "update_customer"
87
+ add_customer_vault_id(post, vault_id)
88
+ add_creditcard(post, creditcard, options)
89
+ add_address(post, options[:billing_address] || options[:address])
90
+ add_customer_data(post, options)
91
+
92
+ commit(nil, nil, post)
93
+ end
94
+
95
+ # Amend an existing transaction
96
+ def amend(auth, options = {})
97
+ post = {}
98
+ add_invoice(post, options)
99
+ add_transaction(post, auth)
100
+ commit('update', nil, post)
101
+ end
102
+
103
+
104
+ def delete(vault_id)
105
+ post = {}
106
+ post[:customer_vault] = "delete_customer"
107
+ add_customer_vault_id(post, vault_id)
108
+ commit(nil, nil, post)
109
+ end
110
+
111
+ # To match the other stored-value gateways, like TrustCommerce,
112
+ # store and unstore need to be defined
113
+ def store(payment_source, options = {})
114
+ post = {}
115
+ billing_id = options.delete(:billing_id).to_s || true
116
+ add_payment_source(post, payment_source, :store => billing_id)
117
+ add_address(post, options[:billing_address] || options[:address])
118
+ add_customer_data(post, options)
119
+ commit(nil, nil, post)
120
+ end
121
+
122
+ alias_method :unstore, :delete
123
+
124
+ private
125
+ def add_customer_data(post, options)
126
+ if options.has_key? :email
127
+ post[:email] = options[:email]
128
+ end
129
+
130
+ if options.has_key? :ip
131
+ post[:ipaddress] = options[:ip]
132
+ end
133
+ end
134
+
135
+ def add_address(post, address,prefix="")
136
+ prefix +="_" unless prefix.blank?
137
+ unless address.blank? or address.values.blank?
138
+ post[prefix+"address1"] = address[:address1].to_s
139
+ post[prefix+"address2"] = address[:address2].to_s unless address[:address2].blank?
140
+ post[prefix+"company"] = address[:company].to_s
141
+ post[prefix+"phone"] = address[:phone].to_s
142
+ post[prefix+"zip"] = address[:zip].to_s
143
+ post[prefix+"city"] = address[:city].to_s
144
+ post[prefix+"country"] = address[:country].to_s
145
+ post[prefix+"state"] = address[:state].blank? ? 'n/a' : address[:state]
146
+ end
147
+ end
148
+
149
+ def add_currency(post, money, options)
150
+ post[:currency] = options[:currency] || currency(money)
151
+ end
152
+
153
+ def add_taxes(post, options)
154
+ post[:tax] = amount(options[:tax])
155
+ end
156
+
157
+ def add_processor(post, options)
158
+ post[:processor] = options[:processor] unless options[:processor].nil?
159
+ end
160
+
161
+ def add_invoice(post, options)
162
+ post[:orderid] = options[:order_id].to_s.gsub(/[^\w.]/, '')
163
+ end
164
+
165
+ def add_payment_source(params, source, options={})
166
+ case determine_funding_source(source)
167
+ when :vault then add_customer_vault_id(params, source)
168
+ when :credit_card then add_creditcard(params, source, options)
169
+ when :check then add_check(params, source, options)
170
+ end
171
+ end
172
+
173
+ def add_customer_vault_id(params, vault_id)
174
+ params[:customer_vault_id] = vault_id
175
+ end
176
+
177
+ def add_creditcard(post, creditcard, options)
178
+ if options[:store]
179
+ post[:customer_vault] = "add_customer"
180
+ post[:customer_vault_id] = options[:store] unless options[:store] == true
181
+ end
182
+ post[:ccnumber] = creditcard.number
183
+ post[:cvv] = creditcard.verification_value if creditcard.verification_value?
184
+ post[:ccexp] = expdate(creditcard)
185
+ post[:firstname] = creditcard.first_name
186
+ post[:lastname] = creditcard.last_name
187
+ end
188
+
189
+ def add_check(post, check, options)
190
+ if options[:store]
191
+ post[:customer_vault] = "add_customer"
192
+ post[:customer_vault_id] = options[:store] unless options[:store] == true
193
+ end
194
+
195
+ post[:payment] = 'check' # Set transaction to ACH
196
+ post[:checkname] = check.name # The name on the customer's Checking Account
197
+ post[:checkaba] = check.routing_number # The customer's bank routing number
198
+ post[:checkaccount] = check.account_number # The customer's account number
199
+ post[:account_holder_type] = check.account_holder_type # The customer's type of ACH account
200
+ post[:account_type] = check.account_type # The customer's type of ACH account
201
+ end
202
+
203
+ def add_sku(post,options)
204
+ post["product_sku_#"] = options[:sku] || options["product_sku_#"]
205
+ end
206
+
207
+ def add_transaction(post, auth)
208
+ post[:transactionid] = auth
209
+ end
210
+
211
+ def parse(body)
212
+ results = {}
213
+ body.split(/&/).each do |pair|
214
+ key,val = pair.split(/=/)
215
+ results[key] = val
216
+ end
217
+
218
+ results
219
+ end
220
+
221
+ def commit(action, money, parameters)
222
+ parameters[:amount] = amount(money) if money
223
+ response = parse( ssl_post(self.live_url, post_data(action,parameters)) )
224
+ Response.new(response["response"] == "1", message_from(response), response,
225
+ :authorization => response["transactionid"],
226
+ :test => test?,
227
+ :cvv_result => response["cvvresponse"],
228
+ :avs_result => { :code => response["avsresponse"] }
229
+ )
230
+
231
+ end
232
+
233
+ def expdate(creditcard)
234
+ year = sprintf("%.04i", creditcard.year.to_i)
235
+ month = sprintf("%.02i", creditcard.month.to_i)
236
+
237
+ "#{month}#{year[-2..-1]}"
238
+ end
239
+
240
+
241
+ def message_from(response)
242
+ case response["responsetext"]
243
+ when "SUCCESS", "Approved", nil # This is dubious, but responses from UPDATE are nil.
244
+ "This transaction has been approved"
245
+ when "DECLINE"
246
+ "This transaction has been declined"
247
+ else
248
+ response["responsetext"]
249
+ end
250
+ end
251
+
252
+ def post_data(action, parameters = {})
253
+ post = {}
254
+ post[:username] = @options[:login]
255
+ post[:password] = @options[:password]
256
+ post[:type] = action if action
257
+
258
+ request = post.merge(parameters).map {|key,value| "#{key}=#{CGI.escape(value.to_s)}"}.join("&")
259
+ request
260
+ end
261
+
262
+ def determine_funding_source(source)
263
+ case
264
+ when source.is_a?(String) then :vault
265
+ when CreditCard.card_companies.keys.include?(card_brand(source)) then :credit_card
266
+ when card_brand(source) == 'check' then :check
267
+ else raise ArgumentError, "Unsupported funding source provided"
268
+ end
269
+ end
270
+ end
271
+ end
272
+ end
273
+
@@ -0,0 +1,236 @@
1
+ require 'json'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class StripeGateway < Gateway
6
+ self.live_url = 'https://api.stripe.com/v1/'
7
+
8
+ AVS_CODE_TRANSLATOR = {
9
+ 'line1: pass, zip: pass' => 'Y',
10
+ 'line1: pass, zip: fail' => 'A',
11
+ 'line1: pass, zip: unchecked' => 'B',
12
+ 'line1: fail, zip: pass' => 'Z',
13
+ 'line1: fail, zip: fail' => 'N',
14
+ 'line1: unchecked, zip: pass' => 'P',
15
+ 'line1: unchecked, zip: unchecked' => 'I'
16
+ }
17
+
18
+ CVC_CODE_TRANSLATOR = {
19
+ 'pass' => 'M',
20
+ 'fail' => 'N',
21
+ 'unchecked' => 'P'
22
+ }
23
+
24
+ self.supported_countries = ['US']
25
+ self.default_currency = 'USD'
26
+ self.money_format = :cents
27
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club]
28
+
29
+ self.homepage_url = 'https://stripe.com/'
30
+ self.display_name = 'Stripe'
31
+
32
+ def initialize(options = {})
33
+ requires!(options, :login)
34
+ @api_key = options[:login]
35
+ super
36
+ end
37
+
38
+ # To create a charge on a card or a token, call
39
+ #
40
+ # purchase(money, card_hash_or_token, { ... })
41
+ #
42
+ # To create a charge on a customer, call
43
+ #
44
+ # purchase(money, nil, { :customer => id, ... })
45
+ def purchase(money, creditcard, options = {})
46
+ post = {}
47
+
48
+ add_amount(post, money, options)
49
+ add_creditcard(post, creditcard, options)
50
+ add_customer(post, options)
51
+ post[:description] = options[:description] || options[:email]
52
+ add_flags(post, options)
53
+
54
+ meta = generate_meta(options)
55
+
56
+ raise ArgumentError.new("Customer or Credit Card required.") if !post[:card] && !post[:customer]
57
+
58
+ commit(:post, 'charges', post, meta)
59
+ end
60
+
61
+ def void(identification, options = {})
62
+ commit(:post, "charges/#{CGI.escape(identification)}/refund", {})
63
+ end
64
+
65
+ def refund(money, identification, options = {})
66
+ meta = generate_meta(options)
67
+ post = {}
68
+
69
+ post[:amount] = amount(money) if money
70
+
71
+ commit(:post, "charges/#{CGI.escape(identification)}/refund", post, meta)
72
+ end
73
+
74
+ def store(creditcard, options = {})
75
+ post = {}
76
+ add_creditcard(post, creditcard, options)
77
+ post[:description] = options[:description]
78
+ post[:email] = options[:email]
79
+
80
+ meta = generate_meta(options)
81
+ path = if options[:customer]
82
+ "customers/#{CGI.escape(options[:customer])}"
83
+ else
84
+ 'customers'
85
+ end
86
+
87
+ commit(:post, path, post, meta)
88
+ end
89
+
90
+ def update(customer_id, creditcard, options = {})
91
+ options = options.merge(:customer => customer_id)
92
+ store(creditcard, options)
93
+ end
94
+
95
+ def unstore(customer_id, options = {})
96
+ meta = generate_meta(options)
97
+ commit(:delete, "customers/#{CGI.escape(customer_id)}", nil, meta)
98
+ end
99
+
100
+ private
101
+
102
+ def add_amount(post, money, options)
103
+ post[:amount] = amount(money)
104
+ post[:currency] = (options[:currency] || currency(money)).downcase
105
+ end
106
+
107
+ def add_customer_data(post, options)
108
+ post[:description] = options[:description]
109
+ post[:email] = options[:email]
110
+ end
111
+
112
+ def add_address(post, options)
113
+ return unless post[:card] && post[:card].kind_of?(Hash)
114
+ if address = options[:billing_address] || options[:address]
115
+ post[:card][:address_line1] = address[:address1] if address[:address1]
116
+ post[:card][:address_line2] = address[:address2] if address[:address2]
117
+ post[:card][:address_country] = address[:country] if address[:country]
118
+ post[:card][:address_zip] = address[:zip] if address[:zip]
119
+ post[:card][:address_state] = address[:state] if address[:state]
120
+ end
121
+ end
122
+
123
+ def add_creditcard(post, creditcard, options)
124
+ if creditcard.respond_to?(:number)
125
+ card = {}
126
+ card[:number] = creditcard.number
127
+ card[:exp_month] = creditcard.month
128
+ card[:exp_year] = creditcard.year
129
+ card[:cvc] = creditcard.verification_value if creditcard.verification_value?
130
+ card[:name] = creditcard.name if creditcard.name
131
+ post[:card] = card
132
+
133
+ add_address(post, options)
134
+ elsif creditcard.kind_of?(String)
135
+ post[:card] = creditcard
136
+ end
137
+ end
138
+
139
+ def add_customer(post, options)
140
+ post[:customer] = options[:customer] if options[:customer] && !post[:card]
141
+ end
142
+
143
+ def add_flags(post, options)
144
+ post[:uncaptured] = true if options[:uncaptured]
145
+ end
146
+
147
+ def parse(body)
148
+ JSON.parse(body)
149
+ end
150
+
151
+ def post_data(params)
152
+ return nil unless params
153
+
154
+ params.map do |key, value|
155
+ next if value.blank?
156
+ if value.is_a?(Hash)
157
+ h = {}
158
+ value.each do |k, v|
159
+ h["#{key}[#{k}]"] = v unless v.blank?
160
+ end
161
+ post_data(h)
162
+ else
163
+ "#{key}=#{CGI.escape(value.to_s)}"
164
+ end
165
+ end.compact.join("&")
166
+ end
167
+
168
+ def generate_meta(options)
169
+ {:ip => options[:ip]}
170
+ end
171
+
172
+ def headers(meta={})
173
+ @@ua ||= JSON.dump({
174
+ :bindings_version => ActiveMerchant::VERSION,
175
+ :lang => 'ruby',
176
+ :lang_version => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
177
+ :platform => RUBY_PLATFORM,
178
+ :publisher => 'active_merchant',
179
+ :uname => (RUBY_PLATFORM =~ /linux|darwin/i ? `uname -a 2>/dev/null`.strip : nil)
180
+ })
181
+
182
+ {
183
+ "Authorization" => "Basic " + Base64.encode64(@api_key.to_s + ":").strip,
184
+ "User-Agent" => "Stripe/v1 ActiveMerchantBindings/#{ActiveMerchant::VERSION}",
185
+ "X-Stripe-Client-User-Agent" => @@ua,
186
+ "X-Stripe-Client-User-Metadata" => meta.to_json
187
+ }
188
+ end
189
+
190
+ def commit(method, url, parameters=nil, meta={})
191
+ raw_response = response = nil
192
+ success = false
193
+ begin
194
+ raw_response = ssl_request(method, self.live_url + url, post_data(parameters), headers(meta))
195
+ response = parse(raw_response)
196
+ success = !response.key?("error")
197
+ rescue ResponseError => e
198
+ raw_response = e.response.body
199
+ response = response_error(raw_response)
200
+ rescue JSON::ParserError
201
+ response = json_error(raw_response)
202
+ end
203
+
204
+ card = response["card"] || response["active_card"] || {}
205
+ avs_code = AVS_CODE_TRANSLATOR["line1: #{card["address_line1_check"]}, zip: #{card["address_zip_check"]}"]
206
+ cvc_code = CVC_CODE_TRANSLATOR[card["cvc_check"]]
207
+ Response.new(success,
208
+ success ? "Transaction approved" : response["error"]["message"],
209
+ response,
210
+ :test => response.has_key?("livemode") ? !response["livemode"] : false,
211
+ :authorization => response["id"],
212
+ :avs_result => { :code => avs_code },
213
+ :cvv_result => cvc_code
214
+ )
215
+ end
216
+
217
+ def response_error(raw_response)
218
+ begin
219
+ parse(raw_response)
220
+ rescue JSON::ParserError
221
+ json_error(raw_response)
222
+ end
223
+ end
224
+
225
+ def json_error(raw_response)
226
+ msg = 'Invalid response received from the Stripe API. Please contact support@stripe.com if you continue to receive this message.'
227
+ msg += " (The raw response returned by the API was #{raw_response.inspect})"
228
+ {
229
+ "error" => {
230
+ "message" => msg
231
+ }
232
+ }
233
+ end
234
+ end
235
+ end
236
+ end