activemerchant-kiddy 1.15.0.kiddy

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/CHANGELOG +688 -0
  2. data/CONTRIBUTORS +233 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +164 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant/billing/avs_result.rb +98 -0
  7. data/lib/active_merchant/billing/base.rb +57 -0
  8. data/lib/active_merchant/billing/check.rb +68 -0
  9. data/lib/active_merchant/billing/credit_card.rb +172 -0
  10. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  11. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  12. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  13. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  14. data/lib/active_merchant/billing/gateway.rb +170 -0
  15. data/lib/active_merchant/billing/gateways/authorize_net.rb +671 -0
  16. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +858 -0
  17. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +309 -0
  18. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +282 -0
  19. data/lib/active_merchant/billing/gateways/beanstream.rb +139 -0
  20. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  21. data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
  22. data/lib/active_merchant/billing/gateways/bogus.rb +132 -0
  23. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  24. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  25. data/lib/active_merchant/billing/gateways/braintree_blue.rb +293 -0
  26. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  27. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  28. data/lib/active_merchant/billing/gateways/cyber_source.rb +410 -0
  29. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  30. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  31. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  32. data/lib/active_merchant/billing/gateways/epay.rb +268 -0
  33. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  34. data/lib/active_merchant/billing/gateways/eway_managed.rb +231 -0
  35. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  36. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  37. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  38. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  39. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  40. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  41. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  42. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  43. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  44. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  45. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  46. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  47. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  48. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +156 -0
  49. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  50. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  51. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  52. data/lib/active_merchant/billing/gateways/moneris.rb +209 -0
  53. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  54. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  55. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  56. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  57. data/lib/active_merchant/billing/gateways/ogone.rb +292 -0
  58. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  59. data/lib/active_merchant/billing/gateways/orbital.rb +317 -0
  60. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  61. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  62. data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
  63. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  64. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  65. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  66. data/lib/active_merchant/billing/gateways/payflow.rb +253 -0
  67. data/lib/active_merchant/billing/gateways/payflow_express.rb +222 -0
  68. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  69. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  70. data/lib/active_merchant/billing/gateways/payment_express.rb +235 -0
  71. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +351 -0
  72. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  73. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  74. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  75. data/lib/active_merchant/billing/gateways/paypal_express.rb +177 -0
  76. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -0
  77. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  78. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  79. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  80. data/lib/active_merchant/billing/gateways/qbms.rb +295 -0
  81. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  82. data/lib/active_merchant/billing/gateways/quickpay.rb +218 -0
  83. data/lib/active_merchant/billing/gateways/realex.rb +311 -0
  84. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  85. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  86. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  87. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  88. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  89. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  90. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  91. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  92. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +193 -0
  93. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  94. data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
  95. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  96. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  97. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  98. data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
  99. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  100. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  101. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  102. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  103. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  104. data/lib/active_merchant/billing/gateways.rb +18 -0
  105. data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
  106. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  107. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  108. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  109. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  110. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  111. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  112. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  113. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  114. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  115. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  116. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  117. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  118. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  119. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  120. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  121. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  122. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  123. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  124. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  125. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  126. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  127. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  128. data/lib/active_merchant/billing/integrations/helper.rb +96 -0
  129. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  130. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  131. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  132. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  133. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +48 -0
  134. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  135. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  136. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  137. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  138. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  139. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  140. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  141. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  142. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  143. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  144. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  145. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  146. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  147. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  148. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  149. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  150. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +111 -0
  151. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  152. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  153. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  154. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  155. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  156. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  157. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  158. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  159. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  160. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +88 -0
  161. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  162. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  163. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  164. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  165. data/lib/active_merchant/billing/integrations/world_pay.rb +38 -0
  166. data/lib/active_merchant/billing/integrations.rb +17 -0
  167. data/lib/active_merchant/billing/response.rb +32 -0
  168. data/lib/active_merchant/billing.rb +9 -0
  169. data/lib/active_merchant/common/connection.rb +177 -0
  170. data/lib/active_merchant/common/country.rb +328 -0
  171. data/lib/active_merchant/common/error.rb +26 -0
  172. data/lib/active_merchant/common/post_data.rb +24 -0
  173. data/lib/active_merchant/common/posts_data.rb +63 -0
  174. data/lib/active_merchant/common/requires_parameters.rb +16 -0
  175. data/lib/active_merchant/common/utils.rb +22 -0
  176. data/lib/active_merchant/common/validateable.rb +81 -0
  177. data/lib/active_merchant/common.rb +14 -0
  178. data/lib/active_merchant/version.rb +3 -0
  179. data/lib/active_merchant.rb +50 -0
  180. data/lib/activemerchant.rb +1 -0
  181. data/lib/certs/cacert.pem +7815 -0
  182. data/lib/support/gateway_support.rb +58 -0
  183. data/lib/support/outbound_hosts.rb +25 -0
  184. metadata +273 -0
@@ -0,0 +1,309 @@
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 =>
157
+ [find(doc, "//OrderFormDoc/Id"), find(doc, "//Transaction/Id")].join(":"),
158
+ :avs_result => find(doc, "//Transaction/AvsRespCode"),
159
+ :cvv_result => find(doc, "//Transaction/Cvv2Resp"),
160
+ :order_id => find(doc, "//OrderFormDoc/Transaction/Id"),
161
+ :raw_response => @response
162
+ }
163
+ end
164
+
165
+ def find(doc, xpath)
166
+ REXML::XPath.first(doc, xpath).try(:text)
167
+ end
168
+ end
169
+
170
+ class Document
171
+ attr_reader :type, :xml
172
+
173
+ PAYMENT_INTERVALS = {
174
+ :days => 'D',
175
+ :months => 'M'
176
+ }
177
+
178
+ EPDQ_CARD_TYPES = {
179
+ :visa => 1,
180
+ :master => 2,
181
+ :switch => 9,
182
+ :maestro => 10,
183
+ }
184
+
185
+ def initialize(gateway, options = {}, document_options = {}, &block)
186
+ @gateway = gateway
187
+ @options = options
188
+ @document_options = document_options
189
+ @xml = Builder::XmlMarkup.new(:indent => 2)
190
+ build(&block)
191
+ end
192
+
193
+ def to_xml
194
+ @xml.target!
195
+ end
196
+
197
+ def build(&block)
198
+ xml.instruct!(:xml, :version => '1.0')
199
+ xml.EngineDocList do
200
+ xml.DocVersion "1.0"
201
+ xml.EngineDoc do
202
+ xml.ContentType "OrderFormDoc"
203
+ xml.User do
204
+ xml.Name(@options[:login])
205
+ xml.Password(@options[:password])
206
+ xml.ClientId({ :DataType => "S32" }, @options[:client_id])
207
+ end
208
+ xml.Instructions do
209
+ if @document_options[:no_fraud]
210
+ xml.Pipeline "PaymentNoFraud"
211
+ else
212
+ xml.Pipeline "Payment"
213
+ end
214
+ end
215
+ instance_eval(&block)
216
+ end
217
+ end
218
+ end
219
+
220
+ def add_order_form(order_id=nil, group_id=nil, &block)
221
+ xml.OrderFormDoc do
222
+ xml.Mode 'P'
223
+ xml.Id(order_id) if order_id
224
+ xml.GroupId(group_id) if group_id
225
+ instance_eval(&block)
226
+ end
227
+ end
228
+
229
+ def add_consumer(options=nil, &block)
230
+ xml.Consumer do
231
+ if options
232
+ xml.Email(options[:email]) if options[:email]
233
+ billing_address = options[:billing_address] || options[:address]
234
+ if billing_address
235
+ xml.BillTo do
236
+ xml.Location do
237
+ xml.Address do
238
+ xml.Street1 billing_address[:address1]
239
+ xml.Street2 billing_address[:address2]
240
+ xml.City billing_address[:city]
241
+ xml.StateProv billing_address[:state]
242
+ xml.PostalCode billing_address[:zip]
243
+ xml.Country billing_address[:country_code]
244
+ end
245
+ end
246
+ end
247
+ end
248
+ end
249
+ instance_eval(&block)
250
+ end
251
+ end
252
+
253
+ def add_creditcard(creditcard)
254
+ xml.PaymentMech do
255
+ xml.CreditCard do
256
+ xml.Type({ :DataType => 'S32' }, EPDQ_CARD_TYPES[creditcard.brand.to_sym])
257
+ xml.Number creditcard.number
258
+ xml.Expires({ :DataType => 'ExpirationDate', :Locale => 826 }, format_expiry_date(creditcard))
259
+ if creditcard.verification_value.present?
260
+ xml.Cvv2Indicator 1
261
+ xml.Cvv2Val creditcard.verification_value
262
+ else
263
+ xml.Cvv2Indicator 5
264
+ end
265
+ xml.IssueNum(creditcard.issue_number) if creditcard.issue_number.present?
266
+ end
267
+ end
268
+ end
269
+
270
+ def add_transaction(auth_type, amount = nil, options = {})
271
+ @auth_type = auth_type
272
+ xml.Transaction do
273
+ xml.Type @auth_type.to_s
274
+ if options[:payment_number] && options[:payment_number] > 1
275
+ xml.CardholderPresentCode({ :DataType => 'S32' }, 8)
276
+ else
277
+ xml.CardholderPresentCode({ :DataType => 'S32' }, 7)
278
+ end
279
+ if options[:payment_number]
280
+ xml.PaymentNumber({ :DataType => 'S32' }, options[:payment_number])
281
+ end
282
+ if options[:total_payments]
283
+ xml.TotalNumberPayments({ :DataType => 'S32' }, options[:total_payments])
284
+ end
285
+ if amount
286
+ xml.CurrentTotals do
287
+ xml.Totals do
288
+ xml.Total({ :DataType => 'Money', :Currency => 826 }, amount)
289
+ end
290
+ end
291
+ end
292
+ end
293
+ end
294
+
295
+ # date must be formatted MM/YY
296
+ def format_expiry_date(creditcard)
297
+ month_str = "%02d" % creditcard.month
298
+ if match = creditcard.year.to_s.match(/^\d{2}(\d{2})$/)
299
+ year_str = "%02d" % match[1].to_i
300
+ else
301
+ year_str = "%02d" % creditcard.year
302
+ end
303
+ "#{month_str}/#{year_str}"
304
+ end
305
+ end
306
+ end
307
+ end
308
+ end
309
+
@@ -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
+