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,308 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class BarclaysEpdqGateway < Gateway
4
+ self.test_url = 'https://secure2.mde.epdq.co.uk:11500'
5
+ self.live_url = 'https://secure2.epdq.co.uk:11500'
6
+
7
+ self.supported_countries = ['GB']
8
+ self.default_currency = 'GBP'
9
+ self.supported_cardtypes = [:visa, :master, :american_express, :maestro, :switch ]
10
+ self.money_format = :cents
11
+ self.homepage_url = 'http://www.barclaycard.co.uk/business/accepting-payments/epdq-mpi/'
12
+ self.display_name = 'Barclays ePDQ'
13
+
14
+ def initialize(options = {})
15
+ requires!(options, :login, :password, :client_id)
16
+ @options = options
17
+ super
18
+ end
19
+
20
+ def authorize(money, creditcard, options = {})
21
+ document = Document.new(self, @options) do
22
+ add_order_form(options[:order_id]) do
23
+ add_consumer(options) do
24
+ add_creditcard(creditcard)
25
+ end
26
+ add_transaction(:PreAuth, money)
27
+ end
28
+ end
29
+
30
+ commit(document)
31
+ end
32
+
33
+ def purchase(money, creditcard, options = {})
34
+ # disable fraud checks if this is a repeat order:
35
+ if options[:payment_number] && (options[:payment_number] > 1)
36
+ no_fraud = true
37
+ else
38
+ no_fraud = options[:no_fraud]
39
+ end
40
+ document = Document.new(self, @options, :no_fraud => no_fraud) do
41
+ add_order_form(options[:order_id], options[:group_id]) do
42
+ add_consumer(options) do
43
+ add_creditcard(creditcard)
44
+ end
45
+ add_transaction(:Auth, money, options)
46
+ end
47
+ end
48
+ commit(document)
49
+ end
50
+
51
+ # authorization is your unique order ID, not the authorization
52
+ # code returned by ePDQ
53
+ def capture(money, authorization, options = {})
54
+ document = Document.new(self, @options) do
55
+ add_order_form(authorization) do
56
+ add_transaction(:PostAuth, money)
57
+ end
58
+ end
59
+
60
+ commit(document)
61
+ end
62
+
63
+ # authorization is your unique order ID, not the authorization
64
+ # code returned by ePDQ
65
+ def credit(money, creditcard_or_authorization, options = {})
66
+ if creditcard_or_authorization.is_a?(String)
67
+ deprecated CREDIT_DEPRECATION_MESSAGE
68
+ refund(money, creditcard_or_authorization, options)
69
+ else
70
+ credit_new_order(money, creditcard_or_authorization, options)
71
+ end
72
+ end
73
+
74
+ def refund(money, authorization, options = {})
75
+ credit_existing_order(money, authorization, options)
76
+ end
77
+
78
+ def void(authorization, options = {})
79
+ document = Document.new(self, @options) do
80
+ add_order_form(authorization) do
81
+ add_transaction(:Void)
82
+ end
83
+ end
84
+
85
+ commit(document)
86
+ end
87
+
88
+ private
89
+ def credit_new_order(money, creditcard, options)
90
+ document = Document.new(self, @options) do
91
+ add_order_form do
92
+ add_consumer(options) do
93
+ add_creditcard(creditcard)
94
+ end
95
+ add_transaction(:Credit, money)
96
+ end
97
+ end
98
+
99
+ commit(document)
100
+ end
101
+
102
+ def credit_existing_order(money, authorization, options)
103
+ order_id, _ = authorization.split(":")
104
+ document = Document.new(self, @options) do
105
+ add_order_form(order_id) do
106
+ add_transaction(:Credit, money)
107
+ end
108
+ end
109
+
110
+ commit(document)
111
+ end
112
+
113
+ def parse(body)
114
+ parser = Parser.new(body)
115
+ response = parser.parse
116
+ Response.new(response[:success], response[:message], response,
117
+ :test => test?,
118
+ :authorization => response[:authorization],
119
+ :avs_result => response[:avsresponse],
120
+ :cvv_result => response[:cvv_result],
121
+ :order_id => response[:order_id],
122
+ :raw_response => response[:raw_response]
123
+ )
124
+ end
125
+
126
+ def commit(document)
127
+ url = (test? ? self.test_url : self.live_url)
128
+ data = ssl_post(url, document.to_xml)
129
+ parse(data)
130
+ end
131
+
132
+ class Parser
133
+ def initialize(response)
134
+ @response = response
135
+ end
136
+
137
+ def parse
138
+ doc = REXML::Document.new(@response)
139
+ auth_type = find(doc, "//Transaction/Type").to_s
140
+
141
+ message = find(doc, "//Message/Text")
142
+ if message.blank?
143
+ message = find(doc, "//Transaction/CardProcResp/CcReturnMsg")
144
+ end
145
+
146
+ case auth_type
147
+ when 'Credit', 'Void'
148
+ success = find(doc, "//CcReturnMsg") == "Approved."
149
+ else
150
+ success = find(doc, "//Transaction/AuthCode").present?
151
+ end
152
+
153
+ {
154
+ :success => success,
155
+ :message => message,
156
+ :transaction_id => find(doc, "//Transaction/Id"),
157
+ :avs_result => find(doc, "//Transaction/AvsRespCode"),
158
+ :cvv_result => find(doc, "//Transaction/Cvv2Resp"),
159
+ :authorization => find(doc, "//OrderFormDoc/Id"),
160
+ :raw_response => @response
161
+ }
162
+ end
163
+
164
+ def find(doc, xpath)
165
+ REXML::XPath.first(doc, xpath).try(:text)
166
+ end
167
+ end
168
+
169
+ class Document
170
+ attr_reader :type, :xml
171
+
172
+ PAYMENT_INTERVALS = {
173
+ :days => 'D',
174
+ :months => 'M'
175
+ }
176
+
177
+ EPDQ_CARD_TYPES = {
178
+ :visa => 1,
179
+ :master => 2,
180
+ :switch => 9,
181
+ :maestro => 10,
182
+ }
183
+
184
+ def initialize(gateway, options = {}, document_options = {}, &block)
185
+ @gateway = gateway
186
+ @options = options
187
+ @document_options = document_options
188
+ @xml = Builder::XmlMarkup.new(:indent => 2)
189
+ build(&block)
190
+ end
191
+
192
+ def to_xml
193
+ @xml.target!
194
+ end
195
+
196
+ def build(&block)
197
+ xml.instruct!(:xml, :version => '1.0')
198
+ xml.EngineDocList do
199
+ xml.DocVersion "1.0"
200
+ xml.EngineDoc do
201
+ xml.ContentType "OrderFormDoc"
202
+ xml.User do
203
+ xml.Name(@options[:login])
204
+ xml.Password(@options[:password])
205
+ xml.ClientId({ :DataType => "S32" }, @options[:client_id])
206
+ end
207
+ xml.Instructions do
208
+ if @document_options[:no_fraud]
209
+ xml.Pipeline "PaymentNoFraud"
210
+ else
211
+ xml.Pipeline "Payment"
212
+ end
213
+ end
214
+ instance_eval(&block)
215
+ end
216
+ end
217
+ end
218
+
219
+ def add_order_form(order_id=nil, group_id=nil, &block)
220
+ xml.OrderFormDoc do
221
+ xml.Mode 'P'
222
+ xml.Id(order_id) if order_id
223
+ xml.GroupId(group_id) if group_id
224
+ instance_eval(&block)
225
+ end
226
+ end
227
+
228
+ def add_consumer(options=nil, &block)
229
+ xml.Consumer do
230
+ if options
231
+ xml.Email(options[:email]) if options[:email]
232
+ billing_address = options[:billing_address] || options[:address]
233
+ if billing_address
234
+ xml.BillTo do
235
+ xml.Location do
236
+ xml.Address do
237
+ xml.Street1 billing_address[:address1]
238
+ xml.Street2 billing_address[:address2]
239
+ xml.City billing_address[:city]
240
+ xml.StateProv billing_address[:state]
241
+ xml.PostalCode billing_address[:zip]
242
+ xml.Country billing_address[:country_code]
243
+ end
244
+ end
245
+ end
246
+ end
247
+ end
248
+ instance_eval(&block)
249
+ end
250
+ end
251
+
252
+ def add_creditcard(creditcard)
253
+ xml.PaymentMech do
254
+ xml.CreditCard do
255
+ xml.Type({ :DataType => 'S32' }, EPDQ_CARD_TYPES[creditcard.brand.to_sym])
256
+ xml.Number creditcard.number
257
+ xml.Expires({ :DataType => 'ExpirationDate', :Locale => 826 }, format_expiry_date(creditcard))
258
+ if creditcard.verification_value.present?
259
+ xml.Cvv2Indicator 1
260
+ xml.Cvv2Val creditcard.verification_value
261
+ else
262
+ xml.Cvv2Indicator 5
263
+ end
264
+ xml.IssueNum(creditcard.issue_number) if creditcard.issue_number.present?
265
+ end
266
+ end
267
+ end
268
+
269
+ def add_transaction(auth_type, amount = nil, options = {})
270
+ @auth_type = auth_type
271
+ xml.Transaction do
272
+ xml.Type @auth_type.to_s
273
+ if options[:payment_number] && options[:payment_number] > 1
274
+ xml.CardholderPresentCode({ :DataType => 'S32' }, 8)
275
+ else
276
+ xml.CardholderPresentCode({ :DataType => 'S32' }, 7)
277
+ end
278
+ if options[:payment_number]
279
+ xml.PaymentNumber({ :DataType => 'S32' }, options[:payment_number])
280
+ end
281
+ if options[:total_payments]
282
+ xml.TotalNumberPayments({ :DataType => 'S32' }, options[:total_payments])
283
+ end
284
+ if amount
285
+ xml.CurrentTotals do
286
+ xml.Totals do
287
+ xml.Total({ :DataType => 'Money', :Currency => 826 }, amount)
288
+ end
289
+ end
290
+ end
291
+ end
292
+ end
293
+
294
+ # date must be formatted MM/YY
295
+ def format_expiry_date(creditcard)
296
+ month_str = "%02d" % creditcard.month
297
+ if match = creditcard.year.to_s.match(/^\d{2}(\d{2})$/)
298
+ year_str = "%02d" % match[1].to_i
299
+ else
300
+ year_str = "%02d" % creditcard.year
301
+ end
302
+ "#{month_str}/#{year_str}"
303
+ end
304
+ end
305
+ end
306
+ end
307
+ end
308
+
@@ -0,0 +1,167 @@
1
+ require File.dirname(__FILE__) + '/beanstream/beanstream_core'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # This class implements the Canadian {Beanstream}[http://www.beanstream.com] payment gateway.
6
+ # It is also named TD Canada Trust Online Mart payment gateway.
7
+ # To learn more about the specification of Beanstream gateway, please read the OM_Direct_Interface_API.pdf,
8
+ # which you can get from your Beanstream account or get from me by email.
9
+ #
10
+ # == Supported transaction types by Beanstream:
11
+ # * +P+ - Purchase
12
+ # * +PA+ - Pre Authorization
13
+ # * +PAC+ - Pre Authorization Completion
14
+ #
15
+ # == Secure Payment Profiles:
16
+ # BeanStream supports payment profiles (vaults). This allows you to store cc information with BeanStream and process subsequent transactions with a customer id.
17
+ # Secure Payment Profiles must be enabled on your account (must be done over the phone).
18
+ # Your API Access Passcode must be set in Administration => account settings => order settings.
19
+ # To learn more about storing credit cards with the Beanstream gateway, please read the BEAN_Payment_Profiles.pdf (I had to phone BeanStream to request it.)
20
+ #
21
+ # == Notes
22
+ # * Adding of order products information is not implemented.
23
+ # * Ensure that country and province data is provided as a code such as "CA", "US", "QC".
24
+ # * login is the Beanstream merchant ID, username and password should be enabled in your Beanstream account and passed in using the <tt>:user</tt> and <tt>:password</tt> options.
25
+ # * Test your app with your true merchant id and test credit card information provided in the api pdf document.
26
+ # * Beanstream does not allow Payment Profiles to be deleted with their API. The accounts are 'closed', but have to be deleted manually.
27
+ #
28
+ # Example authorization (Beanstream PA transaction type):
29
+ #
30
+ # twenty = 2000
31
+ # gateway = BeanstreamGateway.new(
32
+ # :login => '100200000',
33
+ # :user => 'xiaobozz',
34
+ # :password => 'password'
35
+ # )
36
+ #
37
+ # credit_card = CreditCard.new(
38
+ # :number => '4030000010001234',
39
+ # :month => 8,
40
+ # :year => 2011,
41
+ # :first_name => 'xiaobo',
42
+ # :last_name => 'zzz',
43
+ # :verification_value => 137
44
+ # )
45
+ # response = gateway.authorize(twenty, credit_card,
46
+ # :order_id => '1234',
47
+ # :billing_address => {
48
+ # :name => 'xiaobo zzz',
49
+ # :phone => '555-555-5555',
50
+ # :address1 => '1234 Levesque St.',
51
+ # :address2 => 'Apt B',
52
+ # :city => 'Montreal',
53
+ # :state => 'QC',
54
+ # :country => 'CA',
55
+ # :zip => 'H2C1X8'
56
+ # },
57
+ # :email => 'xiaobozzz@example.com',
58
+ # :subtotal => 800,
59
+ # :shipping => 100,
60
+ # :tax1 => 100,
61
+ # :tax2 => 100,
62
+ # :custom => 'reference one'
63
+ # )
64
+ class BeanstreamGateway < Gateway
65
+ include BeanstreamCore
66
+
67
+ def authorize(money, source, options = {})
68
+ post = {}
69
+ add_amount(post, money)
70
+ add_invoice(post, options)
71
+ add_source(post, source)
72
+ add_address(post, options)
73
+ add_transaction_type(post, :authorization)
74
+ commit(post)
75
+ end
76
+
77
+ def purchase(money, source, options = {})
78
+ post = {}
79
+ add_amount(post, money)
80
+ add_invoice(post, options)
81
+ add_source(post, source)
82
+ add_address(post, options)
83
+ add_transaction_type(post, purchase_action(source))
84
+ commit(post)
85
+ end
86
+
87
+ def void(authorization, options = {})
88
+ reference, amount, type = split_auth(authorization)
89
+
90
+ post = {}
91
+ add_reference(post, reference)
92
+ add_original_amount(post, amount)
93
+ add_transaction_type(post, void_action(type))
94
+ commit(post)
95
+ end
96
+
97
+ def recurring(money, source, options = {})
98
+ post = {}
99
+ add_amount(post, money)
100
+ add_invoice(post, options)
101
+ add_credit_card(post, source)
102
+ add_address(post, options)
103
+ add_transaction_type(post, purchase_action(source))
104
+ add_recurring_type(post, options)
105
+ commit(post)
106
+ end
107
+
108
+ def update_recurring(amount, source, options = {})
109
+ post = {}
110
+ add_recurring_amount(post, amount)
111
+ add_recurring_invoice(post, options)
112
+ add_credit_card(post, source)
113
+ add_address(post, options)
114
+ add_recurring_operation_type(post, :update)
115
+ add_recurring_service(post, options)
116
+ recurring_commit(post)
117
+ end
118
+
119
+ def cancel_recurring(options = {})
120
+ post = {}
121
+ add_recurring_operation_type(post, :cancel)
122
+ add_recurring_service(post, options)
123
+ recurring_commit(post)
124
+ end
125
+
126
+ def interac
127
+ @interac ||= BeanstreamInteracGateway.new(@options)
128
+ end
129
+
130
+ # To match the other stored-value gateways, like TrustCommerce,
131
+ # store and unstore need to be defined
132
+ def store(credit_card, options = {})
133
+ post = {}
134
+ add_address(post, options)
135
+ add_credit_card(post, credit_card)
136
+ add_secure_profile_variables(post,options)
137
+ commit(post, true)
138
+ end
139
+
140
+ #can't actually delete a secure profile with the supplicaed API. This function sets the status of the profile to closed (C).
141
+ #Closed profiles will have to removed manually.
142
+ def delete(vault_id)
143
+ update(vault_id, false, {:status => "C"})
144
+ end
145
+
146
+ alias_method :unstore, :delete
147
+
148
+ # Update the values (such as CC expiration) stored at
149
+ # the gateway. The CC number must be supplied in the
150
+ # CreditCard object.
151
+ def update(vault_id, credit_card, options = {})
152
+ post = {}
153
+ add_address(post, options)
154
+ add_credit_card(post, credit_card)
155
+ options.merge!({:vault_id => vault_id, :operation => secure_profile_action(:modify)})
156
+ add_secure_profile_variables(post,options)
157
+ commit(post, true)
158
+ end
159
+
160
+ private
161
+ def build_response(*args)
162
+ Response.new(*args)
163
+ end
164
+ end
165
+ end
166
+ end
167
+