n8_activemerchant 1.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. data/CHANGELOG +574 -0
  2. data/CONTRIBUTORS +175 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +151 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant.rb +49 -0
  7. data/lib/active_merchant/billing.rb +9 -0
  8. data/lib/active_merchant/billing/avs_result.rb +98 -0
  9. data/lib/active_merchant/billing/base.rb +57 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +161 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  15. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  16. data/lib/active_merchant/billing/gateway.rb +169 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +654 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +736 -0
  20. data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
  21. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +244 -0
  22. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  23. data/lib/active_merchant/billing/gateways/bogus.rb +102 -0
  24. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  25. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  26. data/lib/active_merchant/billing/gateways/braintree_blue.rb +210 -0
  27. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  28. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  29. data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
  30. data/lib/active_merchant/billing/gateways/data_cash.rb +593 -0
  31. data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
  32. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  33. data/lib/active_merchant/billing/gateways/epay.rb +263 -0
  34. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  35. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  36. data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
  37. data/lib/active_merchant/billing/gateways/garanti.rb +222 -0
  38. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  39. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  40. data/lib/active_merchant/billing/gateways/iridium.rb +253 -0
  41. data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
  42. data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
  43. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
  44. data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
  45. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  46. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  47. data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
  48. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  49. data/lib/active_merchant/billing/gateways/netaxept.rb +234 -0
  50. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  51. data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
  52. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  53. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  54. data/lib/active_merchant/billing/gateways/paybox_direct.rb +203 -0
  55. data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
  56. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  57. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  58. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  59. data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
  60. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  61. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  62. data/lib/active_merchant/billing/gateways/payment_express.rb +230 -0
  63. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  64. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
  65. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
  66. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  67. data/lib/active_merchant/billing/gateways/paypal_express.rb +145 -0
  68. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
  69. data/lib/active_merchant/billing/gateways/paysimple/paysimple.rb +333 -0
  70. data/lib/active_merchant/billing/gateways/paysimple/usaepay.wsdl +1596 -0
  71. data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
  72. data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
  73. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  74. data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
  75. data/lib/active_merchant/billing/gateways/realex.rb +200 -0
  76. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  77. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  78. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  79. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  80. data/lib/active_merchant/billing/gateways/sage_pay.rb +315 -0
  81. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  82. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  83. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  84. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
  85. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  86. data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
  87. data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
  88. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  89. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  90. data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
  91. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  92. data/lib/active_merchant/billing/gateways/usa_epay_soap.rb +154 -0
  93. data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
  94. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  95. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  96. data/lib/active_merchant/billing/integrations.rb +17 -0
  97. data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
  98. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  99. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  100. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  101. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  102. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  103. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  104. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  105. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  106. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  107. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +188 -0
  108. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  109. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  110. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  111. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  112. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  113. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  114. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  115. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  116. data/lib/active_merchant/billing/integrations/helper.rb +96 -0
  117. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  118. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  119. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  120. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  121. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  122. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  123. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  124. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  125. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  126. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  127. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  128. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  129. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  130. data/lib/active_merchant/billing/integrations/quickpay.rb +17 -0
  131. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  132. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  133. data/lib/active_merchant/billing/integrations/return.rb +37 -0
  134. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  135. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  136. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +109 -0
  137. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +204 -0
  138. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +27 -0
  139. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  140. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  141. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  142. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  143. data/lib/active_merchant/billing/response.rb +32 -0
  144. data/lib/active_merchant/common.rb +14 -0
  145. data/lib/active_merchant/common/connection.rb +162 -0
  146. data/lib/active_merchant/common/country.rb +328 -0
  147. data/lib/active_merchant/common/error.rb +26 -0
  148. data/lib/active_merchant/common/post_data.rb +24 -0
  149. data/lib/active_merchant/common/posts_data.rb +61 -0
  150. data/lib/active_merchant/common/requires_parameters.rb +16 -0
  151. data/lib/active_merchant/common/utils.rb +18 -0
  152. data/lib/active_merchant/common/validateable.rb +76 -0
  153. data/lib/active_merchant/version.rb +3 -0
  154. data/lib/activemerchant.rb +1 -0
  155. data/lib/certs/cacert.pem +7815 -0
  156. data/lib/support/gateway_support.rb +58 -0
  157. data/lib/support/outbound_hosts.rb +25 -0
  158. metadata +270 -0
@@ -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
+
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/authorize_net'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class SecurePayGateway < AuthorizeNetGateway
6
+ self.live_url = self.test_url = 'https://www.securepay.com/AuthSpayAdapter/process.aspx'
7
+
8
+ self.homepage_url = 'http://www.securepay.com/'
9
+ self.display_name = 'SecurePay'
10
+
11
+ # Limit support to purchase() for the time being
12
+ # JRuby chokes here
13
+ # undef_method :authorize, :capture, :void, :credit
14
+
15
+ undef_method :authorize
16
+ undef_method :capture
17
+ undef_method :void
18
+ undef_method :credit
19
+
20
+ def test?
21
+ Base.gateway_mode == :test
22
+ end
23
+
24
+ private
25
+ def split(response)
26
+ response.split(',')
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,157 @@
1
+ require 'rexml/document'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class SecurePayAuGateway < Gateway
6
+ API_VERSION = 'xml-4.2'
7
+
8
+ TEST_URL = 'https://www.securepay.com.au/test/payment'
9
+ LIVE_URL = 'https://www.securepay.com.au/xmlapi/payment'
10
+
11
+ self.supported_countries = ['AU']
12
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :jcb]
13
+
14
+ # The homepage URL of the gateway
15
+ self.homepage_url = 'http://securepay.com.au'
16
+
17
+ # The name of the gateway
18
+ self.display_name = 'SecurePay'
19
+
20
+ class_inheritable_accessor :request_timeout
21
+ self.request_timeout = 60
22
+
23
+ self.money_format = :cents
24
+ self.default_currency = 'AUD'
25
+
26
+ # 0 Standard Payment
27
+ # 4 Refund
28
+ # 6 Client Reversal (Void)
29
+ # 10 Preauthorise
30
+ # 11 Preauth Complete (Advice)
31
+ TRANSACTIONS = {
32
+ :purchase => 0,
33
+ :authorization => 10,
34
+ :capture => 11,
35
+ :void => 6,
36
+ :credit => 4
37
+ }
38
+
39
+ SUCCESS_CODES = [ '00', '08', '11', '16', '77' ]
40
+
41
+ def initialize(options = {})
42
+ requires!(options, :login, :password)
43
+ @options = options
44
+ super
45
+ end
46
+
47
+ def test?
48
+ @options[:test] || super
49
+ end
50
+
51
+ def purchase(money, credit_card, options = {})
52
+ commit :purchase, build_purchase_request(money, credit_card, options)
53
+ end
54
+
55
+ private
56
+
57
+ def build_purchase_request(money, credit_card, options)
58
+ xml = Builder::XmlMarkup.new
59
+
60
+ xml.tag! 'amount', amount(money)
61
+ xml.tag! 'currency', options[:currency] || currency(money)
62
+ xml.tag! 'purchaseOrderNo', options[:order_id].to_s.gsub(/[ ']/, '')
63
+
64
+ xml.tag! 'CreditCardInfo' do
65
+ xml.tag! 'cardNumber', credit_card.number
66
+ xml.tag! 'expiryDate', expdate(credit_card)
67
+ xml.tag! 'cvv', credit_card.verification_value if credit_card.verification_value?
68
+ end
69
+
70
+ xml.target!
71
+ end
72
+
73
+ def build_request(action, body)
74
+ xml = Builder::XmlMarkup.new
75
+ xml.instruct!
76
+ xml.tag! 'SecurePayMessage' do
77
+ xml.tag! 'MessageInfo' do
78
+ xml.tag! 'messageID', Utils.generate_unique_id.slice(0, 30)
79
+ xml.tag! 'messageTimestamp', generate_timestamp
80
+ xml.tag! 'timeoutValue', request_timeout
81
+ xml.tag! 'apiVersion', API_VERSION
82
+ end
83
+
84
+ xml.tag! 'MerchantInfo' do
85
+ xml.tag! 'merchantID', @options[:login]
86
+ xml.tag! 'password', @options[:password]
87
+ end
88
+
89
+ xml.tag! 'RequestType', 'Payment'
90
+ xml.tag! 'Payment' do
91
+ xml.tag! 'TxnList', "count" => 1 do
92
+ xml.tag! 'Txn', "ID" => 1 do
93
+ xml.tag! 'txnType', TRANSACTIONS[action]
94
+ xml.tag! 'txnSource', 23
95
+ xml << body
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ xml.target!
102
+ end
103
+
104
+ def commit(action, request)
105
+ response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, build_request(action, request)))
106
+
107
+ Response.new(success?(response), message_from(response), response,
108
+ :test => test?,
109
+ :authorization => authorization_from(response)
110
+ )
111
+ end
112
+
113
+ def success?(response)
114
+ SUCCESS_CODES.include?(response[:response_code])
115
+ end
116
+
117
+ def authorization_from(response)
118
+ response[:txn_id]
119
+ end
120
+
121
+ def message_from(response)
122
+ response[:response_text] || response[:status_description]
123
+ end
124
+
125
+ def expdate(credit_card)
126
+ "#{format(credit_card.month, :two_digits)}/#{format(credit_card.year, :two_digits)}"
127
+ end
128
+
129
+ def parse(body)
130
+ xml = REXML::Document.new(body)
131
+
132
+ response = {}
133
+
134
+ xml.root.elements.to_a.each do |node|
135
+ parse_element(response, node)
136
+ end
137
+
138
+ response
139
+ end
140
+
141
+ def parse_element(response, node)
142
+ if node.has_elements?
143
+ node.elements.each{|element| parse_element(response, element) }
144
+ else
145
+ response[node.name.underscore.to_sym] = node.text
146
+ end
147
+ end
148
+
149
+ # YYYYDDMMHHNNSSKKK000sOOO
150
+ def generate_timestamp
151
+ time = Time.now.utc
152
+ time.strftime("%Y%d%m%H%M%S#{time.usec}+000")
153
+ end
154
+ end
155
+ end
156
+ end
157
+