activemerchant 1.2.1 → 1.3.0

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 (206) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +310 -294
  3. data/CONTRIBUTERS +13 -0
  4. data/README +55 -31
  5. data/Rakefile +21 -13
  6. data/lib/active_merchant.rb +7 -0
  7. data/lib/active_merchant/billing/avs_result.rb +95 -0
  8. data/lib/active_merchant/billing/base.rb +8 -3
  9. data/lib/active_merchant/billing/check.rb +61 -0
  10. data/lib/active_merchant/billing/credit_card.rb +104 -80
  11. data/lib/active_merchant/billing/credit_card_formatting.rb +11 -8
  12. data/lib/active_merchant/billing/credit_card_methods.rb +76 -32
  13. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  14. data/lib/active_merchant/billing/expiry_date.rb +28 -0
  15. data/lib/active_merchant/billing/gateway.rb +47 -111
  16. data/lib/active_merchant/billing/gateways/authorize_net.rb +508 -121
  17. data/lib/active_merchant/billing/gateways/bogus.rb +26 -32
  18. data/lib/active_merchant/billing/gateways/brain_tree.rb +82 -70
  19. data/lib/active_merchant/billing/gateways/card_stream.rb +43 -15
  20. data/lib/active_merchant/billing/gateways/cyber_source.rb +9 -29
  21. data/lib/active_merchant/billing/gateways/data_cash.rb +18 -38
  22. data/lib/active_merchant/billing/gateways/efsnet.rb +23 -50
  23. data/lib/active_merchant/billing/gateways/eway.rb +8 -19
  24. data/lib/active_merchant/billing/gateways/exact.rb +17 -25
  25. data/lib/active_merchant/billing/gateways/linkpoint.rb +18 -25
  26. data/lib/active_merchant/billing/gateways/moneris.rb +9 -39
  27. data/lib/active_merchant/billing/gateways/net_registry.rb +113 -182
  28. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  29. data/lib/active_merchant/billing/gateways/pay_junction.rb +52 -73
  30. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  31. data/lib/active_merchant/billing/gateways/payflow.rb +13 -14
  32. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +55 -37
  33. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +4 -0
  34. data/lib/active_merchant/billing/gateways/payflow_express.rb +2 -4
  35. data/lib/active_merchant/billing/gateways/payment_express.rb +11 -30
  36. data/lib/active_merchant/billing/gateways/paypal.rb +3 -14
  37. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +36 -16
  38. data/lib/active_merchant/billing/gateways/paypal_express.rb +1 -2
  39. data/lib/active_merchant/billing/gateways/plugnpay.rb +7 -15
  40. data/lib/active_merchant/billing/gateways/protx.rb +24 -25
  41. data/lib/active_merchant/billing/gateways/psigate.rb +34 -71
  42. data/lib/active_merchant/billing/gateways/psl_card.rb +24 -19
  43. data/lib/active_merchant/billing/gateways/quickpay.rb +10 -24
  44. data/lib/active_merchant/billing/gateways/realex.rb +7 -19
  45. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  46. data/lib/active_merchant/billing/gateways/skip_jack.rb +437 -0
  47. data/lib/active_merchant/billing/gateways/trans_first.rb +5 -14
  48. data/lib/active_merchant/billing/gateways/trust_commerce.rb +100 -39
  49. data/lib/active_merchant/billing/gateways/usa_epay.rb +60 -55
  50. data/lib/active_merchant/billing/gateways/verifi.rb +32 -39
  51. data/lib/active_merchant/billing/gateways/viaklix.rb +31 -37
  52. data/lib/active_merchant/billing/integrations.rb +2 -0
  53. data/lib/active_merchant/billing/integrations/bogus.rb +5 -0
  54. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  55. data/lib/active_merchant/billing/integrations/chronopay.rb +5 -0
  56. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  57. data/lib/active_merchant/billing/integrations/gestpay.rb +5 -0
  58. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  59. data/lib/active_merchant/billing/integrations/hi_trust.rb +26 -0
  60. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  61. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +57 -0
  62. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  63. data/lib/active_merchant/billing/integrations/nochex.rb +5 -0
  64. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  65. data/lib/active_merchant/billing/integrations/paypal.rb +5 -0
  66. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  67. data/lib/active_merchant/billing/integrations/return.rb +35 -0
  68. data/lib/active_merchant/billing/integrations/two_checkout.rb +5 -0
  69. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  70. data/lib/active_merchant/billing/response.rb +12 -8
  71. data/lib/active_merchant/lib/posts_data.rb +39 -7
  72. data/lib/active_merchant/lib/requires_parameters.rb +2 -3
  73. data/lib/active_merchant/lib/utils.rb +18 -0
  74. data/lib/active_merchant/lib/validateable.rb +3 -3
  75. data/lib/support/gateway_support.rb +22 -9
  76. data/script/destroy +14 -0
  77. data/script/generate +7 -7
  78. data/test/fixtures.yml +25 -3
  79. data/test/remote/gateways/remote_authorize_net_test.rb +145 -0
  80. data/test/remote/gateways/remote_brain_tree_test.rb +118 -0
  81. data/test/{remote_tests → remote/gateways}/remote_card_stream_test.rb +56 -68
  82. data/test/{remote_tests → remote/gateways}/remote_cyber_source_test.rb +21 -32
  83. data/test/{remote_tests → remote/gateways}/remote_data_cash_test.rb +2 -2
  84. data/test/{remote_tests → remote/gateways}/remote_efsnet_test.rb +22 -34
  85. data/test/{remote_tests → remote/gateways}/remote_eway_test.rb +18 -15
  86. data/test/{remote_tests → remote/gateways}/remote_exact_test.rb +20 -19
  87. data/test/{remote_tests → remote/gateways}/remote_linkpoint_test.rb +31 -63
  88. data/test/remote/gateways/remote_moneris_test.rb +82 -0
  89. data/test/{remote_tests → remote/gateways}/remote_net_registry_test.rb +19 -54
  90. data/test/remote/gateways/remote_netbilling_test.rb +70 -0
  91. data/test/{remote_tests → remote/gateways}/remote_pay_junction_test.rb +41 -60
  92. data/test/remote/gateways/remote_pay_secure_test.rb +39 -0
  93. data/test/{remote_tests → remote/gateways}/remote_payflow_express_test.rb +2 -2
  94. data/test/{remote_tests → remote/gateways}/remote_payflow_test.rb +34 -38
  95. data/test/{remote_tests → remote/gateways}/remote_payflow_uk_test.rb +13 -12
  96. data/test/{remote_tests → remote/gateways}/remote_payment_express_test.rb +26 -36
  97. data/test/{remote_tests → remote/gateways}/remote_paypal_express_test.rb +3 -3
  98. data/test/{remote_tests → remote/gateways}/remote_paypal_test.rb +25 -21
  99. data/test/{remote_tests → remote/gateways}/remote_plugnpay_test.rb +18 -16
  100. data/test/{remote_tests → remote/gateways}/remote_protx_test.rb +33 -33
  101. data/test/remote/gateways/remote_psigate_test.rb +50 -0
  102. data/test/{remote_tests → remote/gateways}/remote_psl_card_test.rb +27 -26
  103. data/test/{remote_tests → remote/gateways}/remote_quickpay_test.rb +48 -48
  104. data/test/{remote_tests → remote/gateways}/remote_realex_test.rb +30 -33
  105. data/test/remote/gateways/remote_secure_pay_tech_test.rb +37 -0
  106. data/test/remote/gateways/remote_secure_pay_test.rb +28 -0
  107. data/test/remote/gateways/remote_skipjack_test.rb +105 -0
  108. data/test/{remote_tests → remote/gateways}/remote_trans_first_test.rb +7 -10
  109. data/test/remote/gateways/remote_trust_commerce_test.rb +152 -0
  110. data/test/{remote_tests → remote/gateways}/remote_usa_epay_test.rb +11 -22
  111. data/test/{remote_tests → remote/gateways}/remote_verifi_test.rb +27 -27
  112. data/test/{remote_tests → remote/gateways}/remote_viaklix_test.rb +8 -18
  113. data/test/{remote_tests → remote/integrations}/remote_gestpay_integration_test.rb +1 -1
  114. data/test/{remote_tests → remote/integrations}/remote_paypal_integration_test.rb +1 -1
  115. data/test/test_helper.rb +102 -61
  116. data/test/unit/avs_result_test.rb +59 -0
  117. data/test/unit/base_test.rb +33 -39
  118. data/test/unit/check_test.rb +76 -0
  119. data/test/unit/credit_card_formatting_test.rb +10 -15
  120. data/test/unit/credit_card_methods_test.rb +132 -17
  121. data/test/unit/credit_card_test.rb +157 -228
  122. data/test/unit/cvv_result_test.rb +33 -0
  123. data/test/unit/expiry_date_test.rb +21 -0
  124. data/test/unit/gateways/authorize_net_test.rb +180 -40
  125. data/test/unit/gateways/bogus_test.rb +2 -3
  126. data/test/unit/gateways/brain_tree_test.rb +63 -29
  127. data/test/unit/gateways/card_stream_test.rb +59 -6
  128. data/test/unit/gateways/cyber_source_test.rb +59 -40
  129. data/test/unit/gateways/data_cash_test.rb +82 -1
  130. data/test/unit/gateways/efsnet_test.rb +97 -44
  131. data/test/unit/gateways/eway_test.rb +55 -42
  132. data/test/unit/gateways/exact_test.rb +93 -55
  133. data/test/unit/gateways/gateway_test.rb +7 -0
  134. data/test/unit/gateways/linkpoint_test.rb +60 -58
  135. data/test/unit/gateways/moneris_test.rb +67 -76
  136. data/test/unit/gateways/net_registry_test.rb +351 -419
  137. data/test/unit/gateways/netbilling_test.rb +54 -0
  138. data/test/unit/gateways/pay_junction_test.rb +108 -46
  139. data/test/unit/gateways/pay_secure_test.rb +71 -0
  140. data/test/unit/gateways/payflow_express_test.rb +0 -8
  141. data/test/unit/gateways/payflow_test.rb +136 -65
  142. data/test/unit/gateways/payflow_uk_test.rb +0 -38
  143. data/test/unit/gateways/payment_express_test.rb +31 -51
  144. data/test/unit/gateways/paypal_express_test.rb +8 -2
  145. data/test/unit/gateways/paypal_test.rb +213 -54
  146. data/test/unit/gateways/plugnpay_test.rb +39 -32
  147. data/test/unit/gateways/protx_test.rb +45 -33
  148. data/test/unit/gateways/psigate_test.rb +146 -87
  149. data/test/unit/gateways/psl_card_test.rb +37 -24
  150. data/test/unit/gateways/quickpay_test.rb +33 -46
  151. data/test/unit/gateways/realex_test.rb +32 -31
  152. data/test/unit/gateways/secure_pay_tech_test.rb +44 -0
  153. data/test/unit/gateways/secure_pay_test.rb +35 -26
  154. data/test/unit/gateways/skip_jack_test.rb +125 -0
  155. data/test/unit/gateways/trans_first_test.rb +24 -37
  156. data/test/unit/gateways/trust_commerce_test.rb +47 -26
  157. data/test/unit/gateways/usa_epay_test.rb +52 -41
  158. data/test/unit/gateways/verifi_test.rb +41 -35
  159. data/test/unit/gateways/viaklix_test.rb +38 -32
  160. data/test/unit/generators/test_gateway_generator.rb +46 -0
  161. data/test/unit/generators/test_generator_helper.rb +20 -0
  162. data/test/unit/generators/test_integration_generator.rb +53 -0
  163. data/test/unit/integrations/action_view_helper_test.rb +7 -14
  164. data/test/unit/integrations/bogus_module_test.rb +4 -0
  165. data/test/unit/integrations/chronopay_module_test.rb +4 -0
  166. data/test/unit/integrations/gestpay_module_test.rb +4 -0
  167. data/test/unit/integrations/helpers/hi_trust_helper_test.rb +16 -0
  168. data/test/unit/integrations/hi_trust_module_test.rb +13 -0
  169. data/test/unit/integrations/nochex_module_test.rb +4 -0
  170. data/test/unit/integrations/notifications/hi_trust_notification_test.rb +38 -0
  171. data/test/unit/integrations/paypal_module_test.rb +4 -0
  172. data/test/unit/integrations/returns/chronopay_return_test.rb +11 -0
  173. data/test/unit/integrations/returns/gestpay_return_test.rb +10 -0
  174. data/test/unit/integrations/returns/hi_trust_return_test.rb +24 -0
  175. data/test/unit/integrations/returns/nochex_return_test.rb +10 -0
  176. data/test/unit/integrations/returns/paypal_return_test.rb +10 -0
  177. data/test/unit/integrations/returns/return_test.rb +11 -0
  178. data/test/unit/integrations/returns/two_checkout_return_test.rb +24 -0
  179. data/test/unit/integrations/two_checkout_module_test.rb +4 -0
  180. data/test/unit/posts_data_test.rb +86 -0
  181. data/test/unit/response_test.rb +15 -1
  182. data/test/unit/utils_test.rb +7 -0
  183. data/test/unit/validateable_test.rb +10 -6
  184. metadata +180 -142
  185. metadata.gz.sig +0 -0
  186. data/lib/active_merchant/billing/gateways/paypal/api_cert_chain.crt +0 -35
  187. data/script/generator/base.rb +0 -45
  188. data/script/generator/generator.rb +0 -24
  189. data/script/generator/generators/gateway/gateway_generator.rb +0 -14
  190. data/script/generator/generators/gateway/templates/gateway.rb +0 -73
  191. data/script/generator/generators/gateway/templates/gateway_test.rb +0 -41
  192. data/script/generator/generators/gateway/templates/remote_gateway_test.rb +0 -56
  193. data/script/generator/generators/integration/integration_generator.rb +0 -25
  194. data/script/generator/generators/integration/templates/helper.rb +0 -34
  195. data/script/generator/generators/integration/templates/helper_test.rb +0 -54
  196. data/script/generator/generators/integration/templates/integration.rb +0 -18
  197. data/script/generator/generators/integration/templates/module_test.rb +0 -9
  198. data/script/generator/generators/integration/templates/notification.rb +0 -100
  199. data/script/generator/generators/integration/templates/notification_test.rb +0 -41
  200. data/script/generator/manifest.rb +0 -20
  201. data/test/remote_tests/remote_authorize_net_test.rb +0 -113
  202. data/test/remote_tests/remote_brain_tree_test.rb +0 -78
  203. data/test/remote_tests/remote_moneris_test.rb +0 -110
  204. data/test/remote_tests/remote_psigate_test.rb +0 -87
  205. data/test/remote_tests/remote_secure_pay_test.rb +0 -36
  206. data/test/remote_tests/remote_trust_commerce_test.rb +0 -136
@@ -35,11 +35,6 @@ module ActiveMerchant
35
35
  # Datacash success code
36
36
  DATACASH_SUCCESS = '1'
37
37
 
38
- # Class attributes
39
- attr_reader :url
40
- attr_reader :response
41
- attr_reader :options
42
-
43
38
  # Creates a new DataCashGateway
44
39
  #
45
40
  # The gateway requires that a valid login and password be passed
@@ -65,13 +60,7 @@ module ActiveMerchant
65
60
  # * <tt>credit_card</tt> -- The CreditCard details for the transaction.
66
61
  # * <tt>options</tt> -- A hash of optional parameters.
67
62
  def purchase(money, credit_card, options = {})
68
- if result = test_result_from_cc_number(credit_card.number)
69
- return result
70
- end
71
-
72
- request = build_purchase_or_authorization_request(AUTH_TYPE, money, credit_card, options)
73
-
74
- commit(request)
63
+ commit(build_purchase_or_authorization_request(AUTH_TYPE, money, credit_card, options))
75
64
  end
76
65
 
77
66
  # Performs an authorization, which reserves the funds on the customer's credit card, but does not
@@ -83,13 +72,7 @@ module ActiveMerchant
83
72
  # * <tt>credit_card</tt> -- The CreditCard details for the transaction.
84
73
  # * <tt>options</tt> -- A hash of optional parameters.
85
74
  def authorize(money, credit_card, options = {})
86
- if result = test_result_from_cc_number(credit_card.number)
87
- return result
88
- end
89
-
90
- request = build_purchase_or_authorization_request(PRE_TYPE, money, credit_card, options)
91
-
92
- commit(request)
75
+ commit(build_purchase_or_authorization_request(PRE_TYPE, money, credit_card, options))
93
76
  end
94
77
 
95
78
  # Captures the funds from an authorized transaction.
@@ -99,9 +82,7 @@ module ActiveMerchant
99
82
  # * <tt>money</tt> -- The amount to be captured. Either an Integer value in cents or a Money object.
100
83
  # * <tt>authorization</tt> -- The authorization returned from the previous authorize request.
101
84
  def capture(money, authorization, options = {})
102
- request = build_void_or_capture_request(FULFILL_TYPE, money, authorization, options)
103
-
104
- commit(request)
85
+ commit(build_void_or_capture_request(FULFILL_TYPE, money, authorization, options))
105
86
  end
106
87
 
107
88
  # Void a previous transaction
@@ -117,7 +98,7 @@ module ActiveMerchant
117
98
 
118
99
  # Is the gateway running in test mode?
119
100
  def test?
120
- @options[:test] || Base.gateway_mode == :test
101
+ @options[:test] || super
121
102
  end
122
103
 
123
104
  private
@@ -286,6 +267,7 @@ module ActiveMerchant
286
267
  # -none: The results is stored in the passed xml document
287
268
  #
288
269
  def add_credit_card(xml, credit_card, address)
270
+
289
271
  xml.tag! :Card do
290
272
 
291
273
  # DataCash calls the CC number 'pan'
@@ -304,11 +286,13 @@ module ActiveMerchant
304
286
 
305
287
  xml.tag! :Cv2Avs do
306
288
  xml.tag! :cv2, credit_card.verification_value if credit_card.verification_value?
307
- xml.tag! :street_address1, address[:address1] unless address[:address1].blank?
308
- xml.tag! :street_address2, address[:address2] unless address[:address2].blank?
309
- xml.tag! :street_address3, address[:address3] unless address[:address3].blank?
310
- xml.tag! :street_address4, address[:address4] unless address[:address4].blank?
311
- xml.tag! :postcode, address[:zip] unless address[:zip].blank?
289
+ if address
290
+ xml.tag! :street_address1, address[:address1] unless address[:address1].blank?
291
+ xml.tag! :street_address2, address[:address2] unless address[:address2].blank?
292
+ xml.tag! :street_address3, address[:address3] unless address[:address3].blank?
293
+ xml.tag! :street_address4, address[:address4] unless address[:address4].blank?
294
+ xml.tag! :postcode, address[:zip] unless address[:zip].blank?
295
+ end
312
296
 
313
297
  # The ExtendedPolicy defines what to do when the passed data
314
298
  # matches, or not...
@@ -349,15 +333,11 @@ module ActiveMerchant
349
333
  # - ActiveMerchant::Billing::Response object
350
334
  #
351
335
  def commit(request)
352
- url = test? ? TEST_URL : LIVE_URL
353
-
354
- @response = parse(ssl_post(url, request))
355
- success = @response[:status] == DATACASH_SUCCESS
356
- message = @response[:reason]
357
-
358
- Response.new(success, message, @response,
359
- :test => test?,
360
- :authorization => "#{@response[:datacash_reference]};#{@response[:authcode]}"
336
+ response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, request))
337
+
338
+ Response.new(response[:status] == DATACASH_SUCCESS, response[:reason], response,
339
+ :test => test?,
340
+ :authorization => "#{response[:datacash_reference]};#{response[:authcode]}"
361
341
  )
362
342
  end
363
343
 
@@ -412,7 +392,7 @@ module ActiveMerchant
412
392
  end
413
393
 
414
394
  def format_reference_number(number)
415
- number.to_s.gsub(/[^A-Za-z0-9]/, '').rjust(6, "0")
395
+ number.to_s.gsub(/[^A-Za-z0-9]/, '').rjust(6, "0").first(30)
416
396
  end
417
397
  end
418
398
  end
@@ -4,10 +4,6 @@ module ActiveMerchant #:nodoc:
4
4
  module Billing #:nodoc:
5
5
 
6
6
  class EfsnetGateway < Gateway
7
- attr_reader :url
8
- attr_reader :response
9
- attr_reader :options
10
-
11
7
  self.supported_countries = ['US']
12
8
  self.supported_cardtypes = [:visa, :master, :american_express, :discover]
13
9
  self.homepage_url = 'http://www.concordefsnet.com/'
@@ -20,15 +16,12 @@ module ActiveMerchant #:nodoc:
20
16
  # password is your Store Key
21
17
  def initialize(options = {})
22
18
  requires!(options, :login, :password)
23
-
24
19
  @options = options
25
- @url = test? ? TEST_URL : LIVE_URL
26
-
27
20
  super
28
21
  end
29
22
 
30
23
  def test?
31
- @options[:test] || Base.gateway_mode == :test
24
+ @options[:test] || super
32
25
  end
33
26
 
34
27
  def authorize(money, creditcard, options = {})
@@ -61,7 +54,7 @@ module ActiveMerchant #:nodoc:
61
54
  def void(identification, options = {})
62
55
  requires!(options, :order_id)
63
56
  original_transaction_id, original_transaction_amount = identification.split(";")
64
- commit(:void_transaction, {:reference_number => options[:order_id], :transaction_ID => original_transaction_id})
57
+ commit(:void_transaction, {:reference_number => format_reference_number(options[:order_id]), :transaction_ID => original_transaction_id})
65
58
  end
66
59
 
67
60
  def voice_authorize(money, authorization_code, creditcard, options = {})
@@ -88,7 +81,7 @@ module ActiveMerchant #:nodoc:
88
81
  requires!(options, :order_id)
89
82
 
90
83
  post = {
91
- :reference_number => options[:order_id],
84
+ :reference_number => format_reference_number(options[:order_id]),
92
85
  :transaction_amount => amount(money),
93
86
  :original_transaction_amount => original_transaction_amount,
94
87
  :original_transaction_ID => original_transaction_id,
@@ -100,7 +93,7 @@ module ActiveMerchant #:nodoc:
100
93
  requires!(options, :order_id)
101
94
 
102
95
  post = {
103
- :reference_number => options[:order_id],
96
+ :reference_number => format_reference_number(options[:order_id]),
104
97
  :authorization_number => options[:authorization_number],
105
98
  :transaction_amount => amount(money),
106
99
  :client_ip_address => options[:ip]
@@ -110,6 +103,10 @@ module ActiveMerchant #:nodoc:
110
103
  add_address(post,options)
111
104
  post
112
105
  end
106
+
107
+ def format_reference_number(number)
108
+ number.to_s.slice(0,12)
109
+ end
113
110
 
114
111
  def add_address(post,options)
115
112
  if address = options[:billing_address] || options[:address]
@@ -146,49 +143,26 @@ module ActiveMerchant #:nodoc:
146
143
  end
147
144
 
148
145
 
149
- def commit(action, parameters)
150
- if result = test_result_from_cc_number(parameters[:account_number])
151
- return result
152
- end
153
-
154
- parameters.delete_if {|key,value| value.blank?}
155
-
156
- headers = { 'Content-Type' => 'text/xml' }
157
- data = ssl_post @url, post_data(action, parameters), headers
158
-
159
- @response = parse(data)
146
+ def commit(action, parameters)
147
+ response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, post_data(action, parameters), 'Content-Type' => 'text/xml'))
160
148
 
161
- success = (response[:response_code] and response[:response_code] == '0')
162
- message = message_form(response[:result_message])
163
-
164
- authorization = [ response[:transaction_id], parameters[:transaction_amount] ].compact.join(';')
165
-
166
- Response.new(success, message, @response,
149
+ Response.new(success?(response), message_from(response[:result_message]), response,
167
150
  :test => test?,
168
- :authorization => authorization
151
+ :authorization => authorization_from(response, parameters),
152
+ :avs_result => { :code => response[:avs_response_code] },
153
+ :cvv_result => response[:cvv_response_code]
169
154
  )
170
155
  end
156
+
157
+ def success?(response)
158
+ response[:response_code] == '0'
159
+ end
160
+
161
+ def authorization_from(response, params)
162
+ [ response[:transaction_id], params[:transaction_amount] ].compact.join(';')
163
+ end
171
164
 
172
- # Parse response xml into a convinient hash
173
165
  def parse(xml)
174
- #<Reply>
175
- #<TransactionReply>
176
- #<ResponseCode>0</ResponseCode>
177
- #<ResultCode>00</ResultCode>
178
- #<ResultMessage>APPROVED</ResultMessage>
179
- #<TransactionID>200011125443</TransactionID>
180
- #<AVSResponseCode>N</AVSResponseCode>
181
- #<CVVResponseCode></CVVResponseCode>
182
- #<ApprovalNumber>123456</ApprovalNumber>
183
- #<AuthorizationNumber>123456</AuthorizationNumber>
184
- #<TransactionDate>070728</TransactionDate>
185
- #<TransactionTime>024734</TransactionTime>
186
- #<ReferenceNumber>19786</ReferenceNumber>
187
- #<AccountNumber>XXXXXXXXXXXX5454</AccountNumber>
188
- #<TransactionAmount>1.00</TransactionAmount>
189
- #</TransactionReply>
190
- #</Reply>
191
-
192
166
  response = {}
193
167
 
194
168
  xml = REXML::Document.new(xml)
@@ -217,7 +191,7 @@ module ActiveMerchant #:nodoc:
217
191
  xml.to_s
218
192
  end
219
193
 
220
- def message_form(message)
194
+ def message_from(message)
221
195
  return 'Unspecified error' if message.blank?
222
196
  message.gsub(/[^\w]/, ' ').split.join(" ").capitalize
223
197
  end
@@ -237,7 +211,6 @@ module ActiveMerchant #:nodoc:
237
211
  ACTIONS
238
212
  end
239
213
 
240
-
241
214
  CREDIT_CARD_FIELDS = [:authorization_number, :client_ip_address, :billing_address, :billing_city, :billing_state, :billing_postal_code, :billing_country, :billing_name, :card_verification_value, :expiration_month, :expiration_year, :reference_number, :transaction_amount, :account_number ]
242
215
 
243
216
  ACTIONS = {
@@ -129,10 +129,6 @@ module ActiveMerchant #:nodoc:
129
129
  "96" => "System Error"
130
130
  }
131
131
 
132
- attr_reader :url
133
- attr_reader :response
134
- attr_reader :options
135
-
136
132
  self.money_format = :cents
137
133
  self.supported_countries = ['AU']
138
134
  self.supported_cardtypes = [:visa, :master]
@@ -195,27 +191,20 @@ module ActiveMerchant #:nodoc:
195
191
  post[:Option3] = nil
196
192
  end
197
193
 
198
- def commit(money, parameters)
199
-
194
+ def commit(money, parameters)
200
195
  parameters[:TotalAmount] = amount(money)
201
-
202
- if result = test_result_from_cc_number(parameters[:CardNumber])
203
- return result
204
- end
205
196
 
206
- data = ssl_post gateway_url(parameters[:CVN], test?), post_data(parameters)
207
-
208
- @response = parse(data)
197
+ response = parse( ssl_post(gateway_url(parameters[:CVN], test?), post_data(parameters)) )
209
198
 
210
- success = (response[:ewaytrxnstatus] == "True")
211
- message = message_from(response[:ewaytrxnerror])
212
- test = /\(Test( CVN)? Gateway\)/ === response[:ewaytrxnerror]
213
-
214
- Response.new(success, message, @response,
199
+ Response.new(success?(response), message_from(response[:ewaytrxnerror]), response,
215
200
  :authorization => response[:ewayauthcode],
216
- :test => test
201
+ :test => /\(Test( CVN)? Gateway\)/ === response[:ewaytrxnerror]
217
202
  )
218
203
  end
204
+
205
+ def success?(response)
206
+ response[:ewaytrxnstatus] == "True"
207
+ end
219
208
 
220
209
  # Parse eway response xml into a convinient hash
221
210
  def parse(xml)
@@ -39,11 +39,7 @@ module ActiveMerchant #:nodoc:
39
39
  self.supported_countries = ['CA', 'US']
40
40
  self.homepage_url = 'http://www.e-xact.com'
41
41
  self.display_name = 'E-xact'
42
-
43
- attr_reader :url
44
- attr_reader :response
45
- attr_reader :options
46
-
42
+
47
43
  def initialize(options = {})
48
44
  requires!(options, :login, :password)
49
45
  @options = options
@@ -60,18 +56,10 @@ module ActiveMerchant #:nodoc:
60
56
  end
61
57
 
62
58
  def authorize(money, credit_card, options = {})
63
- if result = test_result_from_cc_number(credit_card.number)
64
- return result
65
- end
66
-
67
59
  commit(:authorization, build_sale_or_authorization_request(money, credit_card, options))
68
60
  end
69
61
 
70
62
  def purchase(money, credit_card, options = {})
71
- if result = test_result_from_cc_number(credit_card.number)
72
- return result
73
- end
74
-
75
63
  commit(:sale, build_sale_or_authorization_request(money, credit_card, options))
76
64
  end
77
65
 
@@ -176,22 +164,26 @@ module ActiveMerchant #:nodoc:
176
164
  end
177
165
 
178
166
  def commit(action, request)
179
- data = ssl_post(URL, build_request(action, request), POST_HEADERS)
167
+ response = parse(ssl_post(URL, build_request(action, request), POST_HEADERS))
168
+
169
+ Response.new(successful?(response), message_from(response), response,
170
+ :test => test?,
171
+ :authorization => authorization_from(response),
172
+ :avs_result => { :code => response[:avs] },
173
+ :cvv_result => response[:cvv2]
174
+ )
175
+ end
180
176
 
181
- @response = parse(data)
177
+ def successful?(response)
178
+ response[:transaction_approved] == SUCCESS
179
+ end
182
180
 
183
- success = @response[:transaction_approved] == SUCCESS
184
-
185
- authorization = if @response[:authorization_num] && @response[:transaction_tag]
181
+ def authorization_from(response)
182
+ if response[:authorization_num] && response[:transaction_tag]
186
183
  "#{response[:authorization_num]};#{response[:transaction_tag]}"
187
- else
184
+ else
188
185
  ''
189
- end
190
-
191
- Response.new(success, message_from(@response), @response,
192
- :test => test?,
193
- :authorization => authorization
194
- )
186
+ end
195
187
  end
196
188
 
197
189
  def message_from(response)
@@ -90,9 +90,6 @@ module ActiveMerchant #:nodoc:
90
90
  # LinkPoint's Items entity is not yet supported in this module.
91
91
  #
92
92
  class LinkpointGateway < Gateway
93
- attr_reader :response
94
- attr_reader :options
95
-
96
93
  # Your global PEM file. This will be assigned to you by linkpoint
97
94
  #
98
95
  # Example:
@@ -216,34 +213,30 @@ module ActiveMerchant #:nodoc:
216
213
  end
217
214
 
218
215
  def test?
219
- @options[:test] || Base.gateway_mode == :test
216
+ @options[:test] || super
220
217
  end
221
218
 
222
219
  private
223
220
  # Commit the transaction by posting the XML file to the LinkPoint server
224
221
  def commit(money, creditcard, options = {})
225
- parameters = parameters(money, creditcard, options)
226
- url = test? ? TEST_URL : LIVE_URL
227
-
228
- if creditcard and result = test_result_from_cc_number(parameters[:creditcard][:cardnumber])
229
- return result
230
- end
231
-
232
- data = ssl_post(url, post_data(parameters))
233
-
234
- @response = parse(data)
222
+ response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, post_data(money, creditcard, options)))
235
223
 
236
- success = (@response[:approved] == "APPROVED")
237
- message = response[:message]
238
-
239
- Response.new(success, message, @response,
224
+ Response.new(successful?(response), response[:message], response,
240
225
  :test => test?,
241
- :authorization => response[:ordernum]
226
+ :authorization => response[:ordernum],
227
+ :avs_result => { :code => response[:avs].to_s[2,1] },
228
+ :cvv_result => response[:avs].to_s[3,1]
242
229
  )
243
230
  end
244
231
 
232
+ def successful?(response)
233
+ response[:approved] == "APPROVED"
234
+ end
235
+
245
236
  # Build the XML file
246
- def post_data(parameters = {})
237
+ def post_data(money, creditcard, options)
238
+ params = parameters(money, creditcard, options)
239
+
247
240
  xml = REXML::Document.new
248
241
  order = xml.add_element("order")
249
242
 
@@ -251,11 +244,11 @@ module ActiveMerchant #:nodoc:
251
244
  merchantinfo = order.add_element("merchantinfo")
252
245
  merchantinfo.add_element("configfile").text = @options[:login]
253
246
 
254
- # Loop over the parameters hash to construct the XML string
255
- for key, value in parameters
247
+ # Loop over the params hash to construct the XML string
248
+ for key, value in params
256
249
  elem = order.add_element(key.to_s)
257
- for k, v in parameters[key]
258
- elem.add_element(k.to_s).text = parameters[key][k].to_s if parameters[key][k]
250
+ for k, v in params[key]
251
+ elem.add_element(k.to_s).text = params[key][k].to_s if params[key][k]
259
252
  end
260
253
  # Linkpoint doesn't understand empty elements:
261
254
  order.delete(elem) if elem.size == 0
@@ -343,7 +336,7 @@ module ActiveMerchant #:nodoc:
343
336
  params[:billing][:email] = options[:email] unless options[:email].blank?
344
337
  end
345
338
 
346
- if shipping_address = options[:shipping_address] || billing_address
339
+ if shipping_address = options[:shipping_address]
347
340
 
348
341
  params[:shipping] = {}
349
342
  params[:shipping][:name] = shipping_address[:name] || creditcard ? creditcard.name : nil