fishman-activemerchant 1.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/CHANGELOG +733 -0
  2. data/CONTRIBUTORS +257 -0
  3. data/MIT-LICENSE +20 -0
  4. data/gem-public_cert.pem +20 -0
  5. data/lib/active_merchant.rb +47 -0
  6. data/lib/active_merchant/billing.rb +9 -0
  7. data/lib/active_merchant/billing/avs_result.rb +98 -0
  8. data/lib/active_merchant/billing/base.rb +57 -0
  9. data/lib/active_merchant/billing/check.rb +68 -0
  10. data/lib/active_merchant/billing/credit_card.rb +260 -0
  11. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  12. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  13. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  14. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  15. data/lib/active_merchant/billing/gateway.rb +170 -0
  16. data/lib/active_merchant/billing/gateways.rb +18 -0
  17. data/lib/active_merchant/billing/gateways/authorize_net.rb +693 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +858 -0
  19. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  20. data/lib/active_merchant/billing/gateways/beanstream.rb +139 -0
  21. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +282 -0
  22. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  23. data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
  24. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  25. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  26. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  27. data/lib/active_merchant/billing/gateways/braintree_blue.rb +303 -0
  28. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  29. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  30. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  31. data/lib/active_merchant/billing/gateways/cyber_source.rb +430 -0
  32. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  33. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  34. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  35. data/lib/active_merchant/billing/gateways/epay.rb +274 -0
  36. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  37. data/lib/active_merchant/billing/gateways/eway_managed.rb +264 -0
  38. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  39. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  40. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  41. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  42. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  43. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  44. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  45. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  46. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  47. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  48. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  49. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  50. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  51. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +156 -0
  52. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  53. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  54. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  55. data/lib/active_merchant/billing/gateways/moneris.rb +209 -0
  56. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  57. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  58. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  59. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  60. data/lib/active_merchant/billing/gateways/ogone.rb +292 -0
  61. data/lib/active_merchant/billing/gateways/optimal_payment.rb +274 -0
  62. data/lib/active_merchant/billing/gateways/orbital.rb +321 -0
  63. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  64. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  65. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  66. data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
  67. data/lib/active_merchant/billing/gateways/payflow.rb +253 -0
  68. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  69. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  70. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  71. data/lib/active_merchant/billing/gateways/payflow_express.rb +222 -0
  72. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  73. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  74. data/lib/active_merchant/billing/gateways/payment_express.rb +235 -0
  75. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  76. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +354 -0
  77. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  78. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  79. data/lib/active_merchant/billing/gateways/paypal_express.rb +184 -0
  80. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -0
  81. data/lib/active_merchant/billing/gateways/paypal_express_de.rb +14 -0
  82. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  83. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  84. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  85. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  86. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  87. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  88. data/lib/active_merchant/billing/gateways/quickpay.rb +297 -0
  89. data/lib/active_merchant/billing/gateways/realex.rb +311 -0
  90. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  91. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  92. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  93. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  94. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  95. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  96. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  97. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  98. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +193 -0
  99. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  100. data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
  101. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  102. data/lib/active_merchant/billing/gateways/stripe.rb +212 -0
  103. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  104. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  105. data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
  106. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  107. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  108. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  109. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  110. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  111. data/lib/active_merchant/billing/integrations.rb +17 -0
  112. data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
  113. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  114. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  115. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  116. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  117. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  118. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  119. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  120. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  121. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  122. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  123. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  124. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  125. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  126. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  127. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  128. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  129. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  130. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  131. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +28 -0
  132. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +50 -0
  133. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  134. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  135. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  136. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  137. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  138. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  139. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  140. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  141. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  142. data/lib/active_merchant/billing/integrations/helper.rb +96 -0
  143. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  144. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  145. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  146. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  147. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  148. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  149. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  150. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  151. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  152. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  153. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  154. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  155. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  156. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +58 -0
  157. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  158. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  159. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  160. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  161. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  162. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  163. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  164. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  165. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  166. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  167. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  168. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +111 -0
  169. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  170. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  171. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  172. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  173. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  174. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  175. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  176. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  177. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  178. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  179. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  180. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  181. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  182. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  183. data/lib/active_merchant/billing/response.rb +32 -0
  184. data/lib/active_merchant/version.rb +3 -0
  185. data/lib/activemerchant.rb +1 -0
  186. data/lib/support/gateway_support.rb +58 -0
  187. data/lib/support/outbound_hosts.rb +25 -0
  188. metadata +335 -0
@@ -0,0 +1,308 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class BarclaysEpdqGateway < Gateway
4
+ TEST_URL = 'https://secure2.mde.epdq.co.uk:11500'
5
+ LIVE_URL = 'https://secure2.epdq.co.uk:11500'
6
+
7
+ self.supported_countries = ['UK']
8
+ self.default_currency = 'GBP'
9
+ self.supported_cardtypes = [:visa, :master, :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? ? TEST_URL : 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
+ :authorization => find(doc, "//Transaction/Id"),
157
+ :avs_result => find(doc, "//Transaction/AvsRespCode"),
158
+ :cvv_result => find(doc, "//Transaction/Cvv2Resp"),
159
+ :order_id => find(doc, "//OrderFormDoc/Transaction/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,139 @@
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
+ # * Recurring billing is not yet implemented.
23
+ # * Adding of order products information is not implemented.
24
+ # * Ensure that country and province data is provided as a code such as "CA", "US", "QC".
25
+ # * 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.
26
+ # * Test your app with your true merchant id and test credit card information provided in the api pdf document.
27
+ # * Beanstream does not allow Payment Profiles to be deleted with their API. The accounts are 'closed', but have to be deleted manually.
28
+ #
29
+ # Example authorization (Beanstream PA transaction type):
30
+ #
31
+ # twenty = 2000
32
+ # gateway = BeanstreamGateway.new(
33
+ # :login => '100200000',
34
+ # :user => 'xiaobozz',
35
+ # :password => 'password'
36
+ # )
37
+ #
38
+ # credit_card = CreditCard.new(
39
+ # :number => '4030000010001234',
40
+ # :month => 8,
41
+ # :year => 2011,
42
+ # :first_name => 'xiaobo',
43
+ # :last_name => 'zzz',
44
+ # :verification_value => 137
45
+ # )
46
+ # response = gateway.authorize(twenty, credit_card,
47
+ # :order_id => '1234',
48
+ # :billing_address => {
49
+ # :name => 'xiaobo zzz',
50
+ # :phone => '555-555-5555',
51
+ # :address1 => '1234 Levesque St.',
52
+ # :address2 => 'Apt B',
53
+ # :city => 'Montreal',
54
+ # :state => 'QC',
55
+ # :country => 'CA',
56
+ # :zip => 'H2C1X8'
57
+ # },
58
+ # :email => 'xiaobozzz@example.com',
59
+ # :subtotal => 800,
60
+ # :shipping => 100,
61
+ # :tax1 => 100,
62
+ # :tax2 => 100,
63
+ # :custom => 'reference one'
64
+ # )
65
+ class BeanstreamGateway < Gateway
66
+ include BeanstreamCore
67
+
68
+ def authorize(money, source, options = {})
69
+ post = {}
70
+ add_amount(post, money)
71
+ add_invoice(post, options)
72
+ add_source(post, source)
73
+ add_address(post, options)
74
+ add_transaction_type(post, :authorization)
75
+ commit(post)
76
+ end
77
+
78
+ def purchase(money, source, options = {})
79
+ post = {}
80
+ add_amount(post, money)
81
+ add_invoice(post, options)
82
+ add_source(post, source)
83
+ add_address(post, options)
84
+ add_transaction_type(post, purchase_action(source))
85
+ commit(post)
86
+ end
87
+
88
+ def void(authorization, options = {})
89
+ reference, amount, type = split_auth(authorization)
90
+
91
+ post = {}
92
+ add_reference(post, reference)
93
+ add_original_amount(post, amount)
94
+ add_transaction_type(post, void_action(type))
95
+ commit(post)
96
+ end
97
+
98
+ def interac
99
+ @interac ||= BeanstreamInteracGateway.new(@options)
100
+ end
101
+
102
+ # To match the other stored-value gateways, like TrustCommerce,
103
+ # store and unstore need to be defined
104
+ def store(credit_card, options = {})
105
+ post = {}
106
+ add_address(post, options)
107
+ add_credit_card(post, credit_card)
108
+ add_secure_profile_variables(post,options)
109
+ commit(post, true)
110
+ end
111
+
112
+ #can't actually delete a secure profile with the supplicaed API. This function sets the status of the profile to closed (C).
113
+ #Closed profiles will have to removed manually.
114
+ def delete(vault_id)
115
+ update(vault_id, false, {:status => "C"})
116
+ end
117
+
118
+ alias_method :unstore, :delete
119
+
120
+ # Update the values (such as CC expiration) stored at
121
+ # the gateway. The CC number must be supplied in the
122
+ # CreditCard object.
123
+ def update(vault_id, credit_card, options = {})
124
+ post = {}
125
+ add_address(post, options)
126
+ add_credit_card(post, credit_card)
127
+ options.merge!({:vault_id => vault_id, :operation => secure_profile_action(:modify)})
128
+ add_secure_profile_variables(post,options)
129
+ commit(post, true)
130
+ end
131
+
132
+ private
133
+ def build_response(*args)
134
+ Response.new(*args)
135
+ end
136
+ end
137
+ end
138
+ end
139
+
@@ -0,0 +1,282 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module BeanstreamCore
4
+ URL = 'https://www.beanstream.com/scripts/process_transaction.asp'
5
+ SECURE_PROFILE_URL = 'https://www.beanstream.com/scripts/payment_profile.asp'
6
+ SP_SERVICE_VERSION = '1.1'
7
+
8
+ TRANSACTIONS = {
9
+ :authorization => 'PA',
10
+ :purchase => 'P',
11
+ :capture => 'PAC',
12
+ :refund => 'R',
13
+ :void => 'VP',
14
+ :check_purchase => 'D',
15
+ :check_refund => 'C',
16
+ :void_purchase => 'VP',
17
+ :void_refund => 'VR'
18
+ }
19
+
20
+ PROFILE_OPERATIONS = {
21
+ :new => 'N',
22
+ :modify => 'M'
23
+ }
24
+
25
+ CVD_CODES = {
26
+ '1' => 'M',
27
+ '2' => 'N',
28
+ '3' => 'I',
29
+ '4' => 'S',
30
+ '5' => 'U',
31
+ '6' => 'P'
32
+ }
33
+
34
+ AVS_CODES = {
35
+ '0' => 'R',
36
+ '5' => 'I',
37
+ '9' => 'I'
38
+ }
39
+
40
+ def self.included(base)
41
+ base.default_currency = 'CAD'
42
+
43
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
44
+ base.supported_countries = ['CA']
45
+
46
+ # The card types supported by the payment gateway
47
+ base.supported_cardtypes = [:visa, :master, :american_express]
48
+
49
+ # The homepage URL of the gateway
50
+ base.homepage_url = 'http://www.beanstream.com/'
51
+
52
+ # The name of the gateway
53
+ base.display_name = 'Beanstream.com'
54
+ end
55
+
56
+ # Only <tt>:login</tt> is required by default,
57
+ # which is the merchant's merchant ID. If you'd like to perform void,
58
+ # capture or refund transactions then you'll also need to add a username
59
+ # and password to your account under administration -> account settings ->
60
+ # order settings -> Use username/password validation
61
+ def initialize(options = {})
62
+ requires!(options, :login)
63
+ @options = options
64
+ super
65
+ end
66
+
67
+ def capture(money, authorization, options = {})
68
+ reference, amount, type = split_auth(authorization)
69
+
70
+ post = {}
71
+ add_amount(post, money)
72
+ add_reference(post, reference)
73
+ add_transaction_type(post, :capture)
74
+ commit(post)
75
+ end
76
+
77
+ def refund(money, source, options = {})
78
+ post = {}
79
+ reference, amount, type = split_auth(source)
80
+ add_reference(post, reference)
81
+ add_transaction_type(post, refund_action(type))
82
+ add_amount(post, money)
83
+ commit(post)
84
+ end
85
+
86
+ def credit(money, source, options = {})
87
+ deprecated Gateway::CREDIT_DEPRECATION_MESSAGE
88
+ refund(money, source, options)
89
+ end
90
+
91
+ private
92
+ def purchase_action(source)
93
+ (card_brand(source) == "check") ? :check_purchase : :purchase
94
+ end
95
+
96
+ def void_action(original_transaction_type)
97
+ (original_transaction_type == TRANSACTIONS[:refund]) ? :void_refund : :void_purchase
98
+ end
99
+
100
+ def refund_action(type)
101
+ (type == TRANSACTIONS[:check_purchase]) ? :check_refund : :refund
102
+ end
103
+
104
+ def secure_profile_action(type)
105
+ PROFILE_OPERATIONS[type] || PROFILE_OPERATIONS[:new]
106
+ end
107
+
108
+ def split_auth(string)
109
+ string.split(";")
110
+ end
111
+
112
+ def add_amount(post, money)
113
+ post[:trnAmount] = amount(money)
114
+ end
115
+
116
+ def add_original_amount(post, amount)
117
+ post[:trnAmount] = amount
118
+ end
119
+
120
+ def add_reference(post, reference)
121
+ post[:adjId] = reference
122
+ end
123
+
124
+ def add_address(post, options)
125
+ prepare_address_for_non_american_countries(options)
126
+
127
+ if billing_address = options[:billing_address] || options[:address]
128
+ post[:ordName] = billing_address[:name]
129
+ post[:ordEmailAddress] = options[:email]
130
+ post[:ordPhoneNumber] = billing_address[:phone]
131
+ post[:ordAddress1] = billing_address[:address1]
132
+ post[:ordAddress2] = billing_address[:address2]
133
+ post[:ordCity] = billing_address[:city]
134
+ post[:ordProvince] = billing_address[:state]
135
+ post[:ordPostalCode] = billing_address[:zip]
136
+ post[:ordCountry] = billing_address[:country]
137
+ end
138
+ if shipping_address = options[:shipping_address]
139
+ post[:shipName] = shipping_address[:name]
140
+ post[:shipEmailAddress] = options[:email]
141
+ post[:shipPhoneNumber] = shipping_address[:phone]
142
+ post[:shipAddress1] = shipping_address[:address1]
143
+ post[:shipAddress2] = shipping_address[:address2]
144
+ post[:shipCity] = shipping_address[:city]
145
+ post[:shipProvince] = shipping_address[:state]
146
+ post[:shipPostalCode] = shipping_address[:zip]
147
+ post[:shipCountry] = shipping_address[:country]
148
+ post[:shippingMethod] = shipping_address[:shipping_method]
149
+ post[:deliveryEstimate] = shipping_address[:delivery_estimate]
150
+ end
151
+ end
152
+
153
+ def prepare_address_for_non_american_countries(options)
154
+ [ options[:billing_address], options[:shipping_address] ].compact.each do |address|
155
+ unless ['US', 'CA'].include?(address[:country])
156
+ address[:state] = '--'
157
+ address[:zip] = '000000' unless address[:zip]
158
+ end
159
+ end
160
+ end
161
+
162
+ def add_invoice(post, options)
163
+ post[:trnOrderNumber] = options[:order_id]
164
+ post[:trnComments] = options[:description]
165
+ post[:ordItemPrice] = amount(options[:subtotal])
166
+ post[:ordShippingPrice] = amount(options[:shipping])
167
+ post[:ordTax1Price] = amount(options[:tax1] || options[:tax])
168
+ post[:ordTax2Price] = amount(options[:tax2])
169
+ post[:ref1] = options[:custom]
170
+ end
171
+
172
+ def add_credit_card(post, credit_card)
173
+ if credit_card
174
+ post[:trnCardOwner] = credit_card.name
175
+ post[:trnCardNumber] = credit_card.number
176
+ post[:trnExpMonth] = format(credit_card.month, :two_digits)
177
+ post[:trnExpYear] = format(credit_card.year, :two_digits)
178
+ post[:trnCardCvd] = credit_card.verification_value
179
+ end
180
+ end
181
+
182
+ def add_check(post, check)
183
+ # The institution number of the consumer’s financial institution. Required for Canadian dollar EFT transactions.
184
+ post[:institutionNumber] = check.institution_number
185
+
186
+ # The bank transit number of the consumer’s bank account. Required for Canadian dollar EFT transactions.
187
+ post[:transitNumber] = check.transit_number
188
+
189
+ # The routing number of the consumer’s bank account. Required for US dollar EFT transactions.
190
+ post[:routingNumber] = check.routing_number
191
+
192
+ # The account number of the consumer’s bank account. Required for both Canadian and US dollar EFT transactions.
193
+ post[:accountNumber] = check.account_number
194
+ end
195
+
196
+ def add_secure_profile_variables(post, options = {})
197
+ post[:serviceVersion] = SP_SERVICE_VERSION
198
+ post[:responseFormat] = 'QS'
199
+ post[:cardValidation] = (options[:cardValidation].to_i == 1) || '0'
200
+
201
+ post[:operationType] = options[:operationType] || options[:operation] || secure_profile_action(:new)
202
+ post[:customerCode] = options[:billing_id] || options[:vault_id] || false
203
+ post[:status] = options[:status]
204
+ end
205
+
206
+ def parse(body)
207
+ results = {}
208
+ if !body.nil?
209
+ body.split(/&/).each do |pair|
210
+ key,val = pair.split(/=/)
211
+ results[key.to_sym] = val.nil? ? nil : CGI.unescape(val)
212
+ end
213
+ end
214
+
215
+ # Clean up the message text if there is any
216
+ if results[:messageText]
217
+ results[:messageText].gsub!(/<LI>/, "")
218
+ results[:messageText].gsub!(/(\.)?<br>/, ". ")
219
+ results[:messageText].strip!
220
+ end
221
+
222
+ results
223
+ end
224
+
225
+ def commit(params, use_profile_api = false)
226
+ post(post_data(params,use_profile_api),use_profile_api)
227
+ end
228
+
229
+ def post(data, use_profile_api=nil)
230
+ response = parse(ssl_post((use_profile_api ? SECURE_PROFILE_URL : URL), data))
231
+ response[:customer_vault_id] = response[:customerCode] if response[:customerCode]
232
+ build_response(success?(response), message_from(response), response,
233
+ :test => test? || response[:authCode] == "TEST",
234
+ :authorization => authorization_from(response),
235
+ :cvv_result => CVD_CODES[response[:cvdId]],
236
+ :avs_result => { :code => (AVS_CODES.include? response[:avsId]) ? AVS_CODES[response[:avsId]] : response[:avsId] }
237
+ )
238
+ end
239
+
240
+ def authorization_from(response)
241
+ "#{response[:trnId]};#{response[:trnAmount]};#{response[:trnType]}"
242
+ end
243
+
244
+ def message_from(response)
245
+ response[:messageText] || response[:responseMessage]
246
+ end
247
+
248
+ def success?(response)
249
+ response[:responseType] == 'R' || response[:trnApproved] == '1' || response[:responseCode] == '1'
250
+ end
251
+
252
+ def add_source(post, source)
253
+ if source.is_a?(String) or source.is_a?(Integer)
254
+ post[:customerCode] = source
255
+ else
256
+ card_brand(source) == "check" ? add_check(post, source) : add_credit_card(post, source)
257
+ end
258
+ end
259
+
260
+ def add_transaction_type(post, action)
261
+ post[:trnType] = TRANSACTIONS[action]
262
+ end
263
+
264
+ def post_data(params, use_profile_api)
265
+ params[:requestType] = 'BACKEND'
266
+ if use_profile_api
267
+ params[:merchantId] = @options[:login]
268
+ params[:passCode] = @options[:secure_profile_api_key]
269
+ else
270
+ params[:username] = @options[:user] if @options[:user]
271
+ params[:password] = @options[:password] if @options[:password]
272
+ params[:merchant_id] = @options[:login]
273
+ end
274
+ params[:vbvEnabled] = '0'
275
+ params[:scEnabled] = '0'
276
+
277
+ params.reject{|k, v| v.blank?}.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
278
+ end
279
+ end
280
+ end
281
+ end
282
+