bitfluent-activemerchant 1.5.1.1 → 1.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/CHANGELOG +168 -0
  2. data/CONTRIBUTORS +96 -1
  3. data/README.rdoc +33 -5
  4. data/lib/active_merchant.rb +12 -0
  5. data/lib/active_merchant/billing/credit_card.rb +59 -46
  6. data/lib/active_merchant/billing/credit_card_methods.rb +3 -3
  7. data/lib/active_merchant/billing/gateway.rb +16 -9
  8. data/lib/active_merchant/billing/gateways/authorize_net.rb +19 -9
  9. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +134 -12
  10. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +309 -0
  11. data/lib/active_merchant/billing/gateways/beanstream.rb +39 -2
  12. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +64 -26
  13. data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
  14. data/lib/active_merchant/billing/gateways/bogus.rb +33 -3
  15. data/lib/active_merchant/billing/gateways/braintree.rb +11 -11
  16. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  17. data/lib/active_merchant/billing/gateways/braintree_blue.rb +293 -0
  18. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  19. data/lib/active_merchant/billing/gateways/cyber_source.rb +5 -1
  20. data/lib/active_merchant/billing/gateways/data_cash.rb +6 -2
  21. data/lib/active_merchant/billing/gateways/efsnet.rb +8 -2
  22. data/lib/active_merchant/billing/gateways/epay.rb +268 -0
  23. data/lib/active_merchant/billing/gateways/eway_managed.rb +231 -0
  24. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  25. data/lib/active_merchant/billing/gateways/first_pay.rb +8 -3
  26. data/lib/active_merchant/billing/gateways/garanti.rb +132 -92
  27. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  28. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  29. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  30. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  31. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  32. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  33. data/lib/active_merchant/billing/gateways/jetpay.rb +12 -6
  34. data/lib/active_merchant/billing/gateways/linkpoint.rb +6 -1
  35. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +10 -8
  36. data/lib/active_merchant/billing/gateways/merchant_ware.rb +7 -1
  37. data/lib/active_merchant/billing/gateways/moneris.rb +6 -2
  38. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  39. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  40. data/lib/active_merchant/billing/gateways/ogone.rb +16 -3
  41. data/lib/active_merchant/billing/gateways/orbital.rb +317 -0
  42. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  43. data/lib/active_merchant/billing/gateways/pay_junction.rb +9 -9
  44. data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
  45. data/lib/active_merchant/billing/gateways/payflow.rb +26 -9
  46. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +11 -11
  47. data/lib/active_merchant/billing/gateways/payflow_express.rb +122 -38
  48. data/lib/active_merchant/billing/gateways/payment_express.rb +7 -2
  49. data/lib/active_merchant/billing/gateways/paypal.rb +5 -5
  50. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +33 -8
  51. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +26 -15
  52. data/lib/active_merchant/billing/gateways/paypal_ca.rb +1 -1
  53. data/lib/active_merchant/billing/gateways/paypal_express.rb +55 -13
  54. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +8 -3
  55. data/lib/active_merchant/billing/gateways/plugnpay.rb +9 -3
  56. data/lib/active_merchant/billing/gateways/psigate.rb +5 -0
  57. data/lib/active_merchant/billing/gateways/qbms.rb +295 -0
  58. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  59. data/lib/active_merchant/billing/gateways/quickpay.rb +7 -2
  60. data/lib/active_merchant/billing/gateways/realex.rb +187 -76
  61. data/lib/active_merchant/billing/gateways/sage_pay.rb +16 -5
  62. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  63. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +39 -3
  64. data/lib/active_merchant/billing/gateways/smart_ps.rb +9 -3
  65. data/lib/active_merchant/billing/gateways/trust_commerce.rb +7 -2
  66. data/lib/active_merchant/billing/gateways/usa_epay.rb +1 -1
  67. data/lib/active_merchant/billing/gateways/verifi.rb +6 -1
  68. data/lib/active_merchant/billing/gateways/viaklix.rb +1 -1
  69. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  70. data/lib/active_merchant/billing/integrations.rb +0 -12
  71. data/lib/active_merchant/billing/integrations/action_view_helper.rb +13 -24
  72. data/lib/active_merchant/billing/integrations/bogus.rb +2 -2
  73. data/lib/active_merchant/billing/integrations/chronopay.rb +2 -2
  74. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  75. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  76. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  77. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  78. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  79. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  80. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  81. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  82. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  83. data/lib/active_merchant/billing/integrations/gestpay.rb +2 -2
  84. data/lib/active_merchant/billing/integrations/helper.rb +14 -11
  85. data/lib/active_merchant/billing/integrations/hi_trust.rb +2 -2
  86. data/lib/active_merchant/billing/integrations/ipay88.rb +4 -4
  87. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  88. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  89. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  90. data/lib/active_merchant/billing/integrations/nochex.rb +2 -2
  91. data/lib/active_merchant/billing/integrations/notification.rb +1 -1
  92. data/lib/active_merchant/billing/integrations/paypal.rb +2 -2
  93. data/lib/active_merchant/billing/integrations/quickpay.rb +6 -2
  94. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +1 -1
  95. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +2 -2
  96. data/lib/active_merchant/billing/integrations/return.rb +10 -3
  97. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  98. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  99. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +111 -0
  100. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  101. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  102. data/lib/active_merchant/billing/integrations/two_checkout.rb +2 -2
  103. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +5 -5
  104. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  105. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  106. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  107. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +88 -0
  108. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  109. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  110. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  111. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  112. data/lib/active_merchant/common.rb +1 -1
  113. data/lib/active_merchant/common/connection.rb +13 -8
  114. data/lib/active_merchant/common/country.rb +15 -6
  115. data/lib/active_merchant/common/post_data.rb +1 -1
  116. data/lib/active_merchant/common/posts_data.rb +21 -5
  117. data/lib/active_merchant/common/utils.rb +4 -0
  118. data/lib/active_merchant/common/validateable.rb +20 -15
  119. data/lib/active_merchant/version.rb +3 -0
  120. data/lib/support/gateway_support.rb +1 -1
  121. metadata +65 -27
@@ -31,7 +31,7 @@ module ActiveMerchant #:nodoc:
31
31
  :diners_club => "DC",
32
32
  :jcb => "JCB"
33
33
  }
34
-
34
+
35
35
  ELECTRON = /^(424519|42496[23]|450875|48440[6-8]|4844[1-5][1-5]|4917[3-5][0-9]|491880)\d{10}(\d{3})?$/
36
36
 
37
37
  AVS_CVV_CODE = {
@@ -105,8 +105,8 @@ module ActiveMerchant #:nodoc:
105
105
  commit(action, post)
106
106
  end
107
107
 
108
- # Crediting requires a new order_id to passed in, as well as a description
109
- def credit(money, identification, options = {})
108
+ # Refunding requires a new order_id to passed in, as well as a description
109
+ def refund(money, identification, options = {})
110
110
  requires!(options, :order_id, :description)
111
111
 
112
112
  post = {}
@@ -117,6 +117,11 @@ module ActiveMerchant #:nodoc:
117
117
 
118
118
  commit(:credit, post)
119
119
  end
120
+
121
+ def credit(money, identification, options = {})
122
+ deprecated CREDIT_DEPRECATION_MESSAGE
123
+ refund(money, identification, options)
124
+ end
120
125
 
121
126
  private
122
127
  def add_reference(post, identification)
@@ -138,8 +143,9 @@ module ActiveMerchant #:nodoc:
138
143
  end
139
144
 
140
145
  def add_amount(post, money, options)
141
- add_pair(post, :Amount, amount(money), :required => true)
142
- add_pair(post, :Currency, options[:currency] || currency(money), :required => true)
146
+ currency = options[:currency] || currency(money)
147
+ add_pair(post, :Amount, localized_amount(money, currency), :required => true)
148
+ add_pair(post, :Currency, currency, :required => true)
143
149
  end
144
150
 
145
151
  # doesn't actually use the currency -- dodgy!
@@ -303,6 +309,11 @@ module ActiveMerchant #:nodoc:
303
309
  first_name = name.join(' ')
304
310
  [ first_name[0,20], last_name[0,20] ]
305
311
  end
312
+
313
+ def localized_amount(money, currency)
314
+ amount = amount(money)
315
+ CURRENCIES_WITHOUT_FRACTIONS.include?(currency.to_s) ? amount.split('.').first : amount
316
+ end
306
317
  end
307
318
  end
308
319
  end
@@ -0,0 +1,330 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class SecureNetGateway < Gateway
4
+
5
+ API_VERSION = "4.0"
6
+
7
+ TRANSACTIONS = {
8
+ :auth_only => "0000", #
9
+ :partial_auth_only => "0001",
10
+ :auth_capture => "0100", #
11
+ :partial_auth_capture => "0101",
12
+ :prior_auth_capture => "0200",
13
+ :capture_only => "0300", #
14
+ :void => "0400", #
15
+ :partial_void => "0401",
16
+ :credit => "0500", #
17
+ :credit_authonly => "0501",
18
+ :credit_priorauthcapture => "0502",
19
+ :force_credit => "0600",
20
+ :force_credit_authonly => "0601",
21
+ :force_credit_priorauthcapture => "0602",
22
+ :verification => "0700",
23
+ :auth_increment => "0800",
24
+ :issue => "0900",
25
+ :activate => "0901",
26
+ :redeem => "0902",
27
+ :redeem_partial => "0903",
28
+ :deactivate => "0904",
29
+ :reactivate => "0905",
30
+ :inquiry_balance => "0906"
31
+ }
32
+
33
+ XML_ATTRIBUTES = { 'xmlns' => "http://gateway.securenet.com/API/Contracts",
34
+ 'xmlns:i' => "http://www.w3.org/2001/XMLSchema-instance"
35
+ }
36
+ NIL_ATTRIBUTE = { 'i:nil' => "true" }
37
+
38
+ # SUCCESS = "true"
39
+ # SENSITIVE_FIELDS = [ :verification_str2, :expiry_date, :card_number ]
40
+
41
+ self.supported_countries = ['US']
42
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
43
+ self.homepage_url = 'http://www.securenet.com/'
44
+ self.display_name = 'SecureNet'
45
+ # self.wiredump_device = STDOUT
46
+
47
+ # TEST_URL = 'https://certify.securenet.com/api/Gateway.svc'
48
+ TEST_URL = 'https://certify.securenet.com/API/gateway.svc/webHttp/ProcessTransaction'
49
+ LIVE_URL = 'https://gateway.securenet.com/api/Gateway.svc'
50
+
51
+ APPROVED, DECLINED, ERROR = 1, 2, 3
52
+
53
+ RESPONSE_CODE, RESPONSE_REASON_CODE, RESPONSE_REASON_TEXT = 0, 2, 3
54
+ AVS_RESULT_CODE, CARD_CODE_RESPONSE_CODE, TRANSACTION_ID = 5, 6, 8
55
+
56
+ CARD_CODE_ERRORS = %w( N S )
57
+ AVS_ERRORS = %w( A E N R W Z )
58
+
59
+ def initialize(options = {})
60
+ requires!(options, :login, :password)
61
+ @options = options
62
+ super
63
+ end
64
+
65
+ def authorize(money, creditcard, options = {})
66
+ commit(build_sale_or_authorization_request(creditcard, options, :auth_only), money)
67
+ end
68
+
69
+ def purchase(money, creditcard, options = {})
70
+ commit(build_sale_or_authorization_request(creditcard, options, :auth_capture), money)
71
+ end
72
+
73
+ def capture(money, creditcard, authorization, options = {})
74
+ commit(build_capture_request(authorization, creditcard, options, :prior_auth_capture), money)
75
+ end
76
+
77
+ def void(money, creditcard, authorization, options = {})
78
+ commit(build_void_request(authorization, creditcard, options, :void), money)
79
+ end
80
+
81
+ def credit(money, creditcard, authorization, options = {})
82
+ commit(build_credit_request(authorization, creditcard, options, :credit), money)
83
+ end
84
+
85
+ private
86
+ def commit(request, money)
87
+ xml = build_request(request, money)
88
+ data = ssl_post(TEST_URL, xml, "Content-Type" => "text/xml")
89
+ response = parse(data)
90
+
91
+ test_mode = test?
92
+ Response.new(success?(response), message_from(response), response,
93
+ :test => test_mode,
94
+ :authorization => response[:transactionid],
95
+ :avs_result => { :code => response[:avs_result_code] },
96
+ :cvv_result => response[:card_code_response_code]
97
+ )
98
+ end
99
+
100
+ def build_request(request, money)
101
+ xml = Builder::XmlMarkup.new
102
+
103
+ xml.instruct!
104
+ xml.tag!("TRANSACTION", XML_ATTRIBUTES) do
105
+ xml.tag! 'AMOUNT', amount(money)
106
+ xml << request
107
+ end
108
+
109
+ xml.target!
110
+ end
111
+
112
+ def build_sale_or_authorization_request(creditcard, options, action)
113
+ xml = Builder::XmlMarkup.new
114
+
115
+ add_credit_card(xml, creditcard)
116
+ xml.tag! 'CODE', TRANSACTIONS[action]
117
+ add_customer_data(xml, options)
118
+ add_address(xml, creditcard, options)
119
+ xml.tag! 'DCI', 0 # No duplicate checking will be done, except for ORDERID
120
+ xml.tag! 'INSTALLMENT_SEQUENCENUM', 1
121
+ add_invoice(xml, options)
122
+ add_merchant_key(xml, options)
123
+ xml.tag! 'METHOD', 'CC'
124
+ xml.tag! 'ORDERID', options[:order_id]#'30'.to_i.to_s#'22'# @options[:order_id]
125
+ xml.tag! 'OVERRIDE_FROM', 0 # Docs say not required, but doesn't work without it
126
+ xml.tag! 'RETAIL_LANENUM', '0' # Docs say string, but it's an integer!?
127
+ xml.tag! 'TEST', 'TRUE'
128
+ xml.tag! 'TOTAL_INSTALLMENTCOUNT', 0
129
+ xml.tag! 'TRANSACTION_SERVICE', 0
130
+
131
+ xml.target!
132
+ end
133
+
134
+ def build_capture_or_credit_request(identification, options)
135
+ xml = Builder::XmlMarkup.new
136
+
137
+ add_identification(xml, identification)
138
+ add_customer_data(xml, options)
139
+
140
+ xml.target!
141
+ end
142
+
143
+ def build_capture_request(authorization, creditcard, options, action)
144
+ xml = Builder::XmlMarkup.new
145
+
146
+ add_credit_card(xml, creditcard)
147
+ xml.tag! 'CODE', TRANSACTIONS[action]
148
+ add_customer_data(xml, options)
149
+ xml.tag! 'DCI', 0 # No duplicate checking will be done, except for ORDERID
150
+ xml.tag! 'INSTALLMENT_SEQUENCENUM', 1
151
+ add_merchant_key(xml, options)
152
+ xml.tag! 'METHOD', 'CC'
153
+ xml.tag! 'ORDERID', options[:order_id]#'30'.to_i.to_s#'22'# @options[:order_id]
154
+ xml.tag! 'OVERRIDE_FROM', 0 # Docs say not required, but doesn't work without it
155
+ xml.tag! 'REF_TRANSID', authorization
156
+ xml.tag! 'RETAIL_LANENUM', '0' # Docs say string, but it's an integer!?
157
+ xml.tag! 'TEST', 'TRUE'
158
+ xml.tag! 'TOTAL_INSTALLMENTCOUNT', 0
159
+ xml.tag! 'TRANSACTION_SERVICE', 0
160
+
161
+ xml.target!
162
+ end
163
+
164
+ def build_credit_request(authorization, creditcard, options, action)
165
+ # requires!(options, :card_number)
166
+ xml = Builder::XmlMarkup.new
167
+
168
+ add_credit_card(xml, creditcard)
169
+ xml.tag! 'CODE', TRANSACTIONS[action]
170
+ add_customer_data(xml, options)
171
+ xml.tag! 'DCI', 0 # No duplicate checking will be done, except for ORDERID
172
+ xml.tag! 'INSTALLMENT_SEQUENCENUM', 1
173
+ add_merchant_key(xml, options)
174
+ xml.tag! 'METHOD', 'CC'
175
+ xml.tag! 'ORDERID', options[:order_id]#'30'.to_i.to_s#'22'# @options[:order_id]
176
+ xml.tag! 'OVERRIDE_FROM', 0 # Docs say not required, but doesn't work without it
177
+ xml.tag! 'REF_TRANSID', authorization
178
+ xml.tag! 'RETAIL_LANENUM', '0' # Docs say string, but it's an integer!?
179
+ xml.tag! 'TEST', 'TRUE'
180
+ xml.tag! 'TOTAL_INSTALLMENTCOUNT', 0
181
+ xml.tag! 'TRANSACTION_SERVICE', 0
182
+
183
+ xml.target!
184
+ end
185
+
186
+ def build_void_request(authorization, creditcard, options, action)
187
+ xml = Builder::XmlMarkup.new
188
+
189
+ add_credit_card(xml, creditcard)
190
+ xml.tag! 'CODE', TRANSACTIONS[action]
191
+ add_customer_data(xml, options)
192
+ xml.tag! 'DCI', 0 # No duplicate checking will be done, except for ORDERID
193
+ xml.tag! 'INSTALLMENT_SEQUENCENUM', 1
194
+ add_merchant_key(xml, options)
195
+ xml.tag! 'METHOD', 'CC'
196
+ xml.tag! 'ORDERID', options[:order_id]#'30'.to_i.to_s#'22'# @options[:order_id]
197
+ xml.tag! 'OVERRIDE_FROM', 0 # Docs say not required, but doesn't work without it
198
+ xml.tag! 'REF_TRANSID', authorization
199
+ xml.tag! 'RETAIL_LANENUM', '0' # Docs say string, but it's an integer!?
200
+ xml.tag! 'TEST', 'TRUE'
201
+ xml.tag! 'TOTAL_INSTALLMENTCOUNT', 0
202
+ xml.tag! 'TRANSACTION_SERVICE', 0
203
+
204
+ xml.target!
205
+ end
206
+
207
+ #########################################################################
208
+ # FUNCTIONS RELATED TO BUILDING THE XML
209
+ #########################################################################
210
+ def add_credit_card(xml, creditcard)
211
+ xml.tag!("CARD") do
212
+ xml.tag! 'CARDCODE', creditcard.verification_value if creditcard.verification_value?
213
+ xml.tag! 'CARDNUMBER', creditcard.number
214
+ xml.tag! 'EXPDATE', expdate(creditcard)
215
+ end
216
+ end
217
+
218
+ def expdate(creditcard)
219
+ year = sprintf("%.4i", creditcard.year)
220
+ month = sprintf("%.2i", creditcard.month)
221
+
222
+ "#{month}#{year[-2..-1]}"
223
+ end
224
+
225
+ def add_customer_data(xml, options)
226
+ if options.has_key? :customer
227
+ xml.tag! 'CUSTOMERID', options[:customer]
228
+ end
229
+
230
+ if options.has_key? :ip
231
+ xml.tag! 'CUSTOMERIP', options[:ip]
232
+ end
233
+ end
234
+
235
+ def add_address(xml, creditcard, options)
236
+
237
+ if address = options[:billing_address] || options[:address]
238
+ xml.tag!("CUSTOMER_BILL") do
239
+ xml.tag! 'ADDRESS', address[:address1].to_s
240
+ xml.tag! 'CITY', address[:city].to_s
241
+ xml.tag! 'COMPANY', address[:company].to_s
242
+ xml.tag! 'COUNTRY', address[:country].to_s
243
+ if options.has_key? :email
244
+ xml.tag! 'EMAIL', options[:email]
245
+ # xml.tag! 'EMAIL', 'myemail@yahoo.com'
246
+ xml.tag! 'EMAILRECEIPT', 'FALSE'
247
+ end
248
+ xml.tag! 'FIRSTNAME', creditcard.first_name
249
+ xml.tag! 'LASTNAME', creditcard.last_name
250
+ xml.tag! 'PHONE', address[:phone].to_s
251
+ xml.tag! 'STATE', address[:state].blank? ? 'n/a' : address[:state]
252
+ xml.tag! 'ZIP', address[:zip].to_s
253
+ end
254
+ end
255
+
256
+ if address = options[:shipping_address]
257
+ xml.tag!("CUSTOMER_SHIP") do
258
+ xml.tag! 'ADDRESS', address[:address1].to_s
259
+ xml.tag! 'CITY', address[:city].to_s
260
+ xml.tag! 'COMPANY', address[:company].to_s
261
+ xml.tag! 'COUNTRY', address[:country].to_s
262
+ xml.tag! 'FIRSTNAME', address[:first_name].to_s
263
+ xml.tag! 'LASTNAME', address[:last_name].to_s
264
+ xml.tag! 'STATE', address[:state].blank? ? 'n/a' : address[:state]
265
+ xml.tag! 'ZIP', address[:zip].to_s
266
+ end
267
+ else
268
+ xml.tag!('CUSTOMER_SHIP', NIL_ATTRIBUTE) do
269
+ end
270
+ end
271
+
272
+ end
273
+
274
+ def add_invoice(xml, options)
275
+ xml.tag! 'INVOICEDESC', options[:description]
276
+ xml.tag! 'INVOICENUM', 'inv-8'
277
+ end
278
+
279
+ def add_merchant_key(xml, options)
280
+ xml.tag!("MERCHANT_KEY") do
281
+ xml.tag! 'GROUPID', 0
282
+ xml.tag! 'SECUREKEY', @options[:password]
283
+ xml.tag! 'SECURENETID', @options[:login]
284
+ end
285
+ end
286
+
287
+ #########################################################################
288
+ # FUNCTIONS RELATED TO THE RESPONSE
289
+ #########################################################################
290
+ def success?(response)
291
+ response[:response_code].to_i == APPROVED
292
+ end
293
+
294
+ def message_from(response)
295
+ if response[:response_code].to_i == DECLINED
296
+ return CVVResult.messages[ response[:card_code_response_code] ] if CARD_CODE_ERRORS.include?(response[:card_code_response_code])
297
+ return AVSResult.messages[ response[:avs_result_code] ] if AVS_ERRORS.include?(response[:avs_result_code])
298
+ end
299
+
300
+ return response[:response_reason_text].nil? ? '' : response[:response_reason_text][0..-1]
301
+ end
302
+
303
+ def parse(xml)
304
+ response = {}
305
+ xml = REXML::Document.new(xml)
306
+ root = REXML::XPath.first(xml, "//GATEWAYRESPONSE")# ||
307
+ # root = REXML::XPath.first(xml, "//ProcessTransactionResponse")# ||
308
+ # REXML::XPath.first(xml, "//ErrorResponse")
309
+ if root
310
+ root.elements.to_a.each do |node|
311
+ recurring_parse_element(response, node)
312
+ end
313
+ end
314
+
315
+ response
316
+ end
317
+
318
+ def recurring_parse_element(response, node)
319
+ if node.has_elements?
320
+ node.elements.each{|e| recurring_parse_element(response, e) }
321
+ else
322
+ response[node.name.underscore.to_sym] = node.text
323
+ end
324
+ end
325
+
326
+
327
+ end
328
+ end
329
+ end
330
+
@@ -17,7 +17,7 @@ module ActiveMerchant #:nodoc:
17
17
  # The name of the gateway
18
18
  self.display_name = 'SecurePay'
19
19
 
20
- class_inheritable_accessor :request_timeout
20
+ class_attribute :request_timeout
21
21
  self.request_timeout = 60
22
22
 
23
23
  self.money_format = :cents
@@ -33,7 +33,7 @@ module ActiveMerchant #:nodoc:
33
33
  :authorization => 10,
34
34
  :capture => 11,
35
35
  :void => 6,
36
- :credit => 4
36
+ :refund => 4
37
37
  }
38
38
 
39
39
  SUCCESS_CODES = [ '00', '08', '11', '16', '77' ]
@@ -49,9 +49,32 @@ module ActiveMerchant #:nodoc:
49
49
  end
50
50
 
51
51
  def purchase(money, credit_card, options = {})
52
+ requires!(options, :order_id)
52
53
  commit :purchase, build_purchase_request(money, credit_card, options)
53
54
  end
54
55
 
56
+ def authorize(money, credit_card, options = {})
57
+ requires!(options, :order_id)
58
+ commit :authorization, build_purchase_request(money, credit_card, options)
59
+ end
60
+
61
+ def capture(money, reference, options = {})
62
+ commit :capture, build_reference_request(money, reference)
63
+ end
64
+
65
+ def refund(money, reference, options = {})
66
+ commit :refund, build_reference_request(money, reference)
67
+ end
68
+
69
+ def credit(money, reference, options = {})
70
+ deprecated CREDIT_DEPRECATION_MESSAGE
71
+ refund(money, reference)
72
+ end
73
+
74
+ def void(reference, options = {})
75
+ commit :void, build_reference_request(nil, reference)
76
+ end
77
+
55
78
  private
56
79
 
57
80
  def build_purchase_request(money, credit_card, options)
@@ -70,6 +93,19 @@ module ActiveMerchant #:nodoc:
70
93
  xml.target!
71
94
  end
72
95
 
96
+ def build_reference_request(money, reference)
97
+ xml = Builder::XmlMarkup.new
98
+
99
+ transaction_id, order_id, preauth_id, original_amount = reference.split("*")
100
+ xml.tag! 'amount', (money ? amount(money) : original_amount)
101
+ xml.tag! 'currency', options[:currency] || currency(money)
102
+ xml.tag! 'txnID', transaction_id
103
+ xml.tag! 'purchaseOrderNo', order_id
104
+ xml.tag! 'preauthID', preauth_id
105
+
106
+ xml.target!
107
+ end
108
+
73
109
  def build_request(action, body)
74
110
  xml = Builder::XmlMarkup.new
75
111
  xml.instruct!
@@ -115,7 +151,7 @@ module ActiveMerchant #:nodoc:
115
151
  end
116
152
 
117
153
  def authorization_from(response)
118
- response[:txn_id]
154
+ [response[:txn_id], response[:purchase_order_no], response[:preauth_id], response[:amount]].join('*')
119
155
  end
120
156
 
121
157
  def message_from(response)