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
@@ -10,24 +10,19 @@ module ActiveMerchant #:nodoc:
10
10
  # Response Values", available at Moneris' {eSelect Plus Documentation
11
11
  # Centre}[https://www3.moneris.com/connect/en/documents/index.html].
12
12
  class MonerisGateway < Gateway
13
- attr_reader :url
14
- attr_reader :response
15
- attr_reader :options
13
+ TEST_URL = 'https://esqa.moneris.com/gateway2/servlet/MpgRequest'
14
+ LIVE_URL = 'https://www3.moneris.com/gateway2/servlet/MpgRequest'
16
15
 
17
16
  self.supported_countries = ['CA']
18
17
  self.supported_cardtypes = [:visa, :master]
19
18
  self.homepage_url = 'http://www.moneris.com/'
20
19
  self.display_name = 'Moneris'
21
-
22
- TEST_URL = 'https://esqa.moneris.com/gateway2/servlet/MpgRequest'
23
- LIVE_URL = 'https://www3.moneris.com/gateway2/servlet/MpgRequest'
24
-
20
+
25
21
  # login is your Store ID
26
22
  # password is your API Token
27
23
  def initialize(options = {})
28
24
  requires!(options, :login, :password)
29
25
  @options = { :crypt_type => 7 }.update(options)
30
- @url = test? ? TEST_URL : LIVE_URL
31
26
  super
32
27
  end
33
28
 
@@ -122,53 +117,28 @@ module ActiveMerchant #:nodoc:
122
117
  end
123
118
 
124
119
  def commit(action, parameters = {})
125
- # TODO This part still needs to be refactored
126
- if result = test_result_from_cc_number(parameters[:pan])
127
- return result
128
- end
129
-
130
- @response = parse(ssl_post(@url, post_data(action, parameters)))
120
+ response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, post_data(action, parameters)))
131
121
 
132
- Response.new(successful_response?(response), message_form(response[:message]), @response,
122
+ Response.new(successful?(response), message_from(response[:message]), response,
133
123
  :test => test?,
134
- :authorization => authorization_string(response)
124
+ :authorization => authorization_from(response)
135
125
  )
136
126
  end
137
127
 
138
128
  # Generates a Moneris authorization string of the form 'trans_id;receipt_id'.
139
- def authorization_string(response = {})
129
+ def authorization_from(response = {})
140
130
  if response[:trans_id] && response[:receipt_id]
141
131
  "#{response[:trans_id]};#{response[:receipt_id]}"
142
132
  end
143
133
  end
144
134
 
145
135
  # Tests for a successful response from Moneris' servers
146
- def successful_response?(response = {})
136
+ def successful?(response)
147
137
  response[:response_code] &&
148
138
  response[:complete] &&
149
139
  (0..49).include?(response[:response_code].to_i)
150
140
  end
151
141
 
152
- # Parse Moneris' response XML into a convinient Hash.
153
- #
154
- # Expected XML format:
155
- #
156
- # "<?xml version=\"1.0\"?><response><receipt>".
157
- # "<ReceiptId>Global Error Receipt</ReceiptId>".
158
- # "<ReferenceNum>null</ReferenceNum>
159
- # <ResponseCode>null</ResponseCode>".
160
- # "<ISO>null</ISO>
161
- # <AuthCode>null</AuthCode>
162
- # <TransTime>null</TransTime>".
163
- # "<TransDate>null</TransDate>
164
- # <TransType>null</TransType>
165
- # <Complete>false</Complete>".
166
- # "<Message>null</Message>
167
- # <TransAmount>null</TransAmount>".
168
- # "<CardType>null</CardType>".
169
- # "<TransID>null</TransID>
170
- # <TimedOut>null</TimedOut>".
171
- # "</receipt></response>
172
142
  def parse(xml)
173
143
  response = { :message => "Global Error Receipt", :complete => false }
174
144
  hashify_xml!(xml, response)
@@ -198,7 +168,7 @@ module ActiveMerchant #:nodoc:
198
168
  xml.to_s
199
169
  end
200
170
 
201
- def message_form(message)
171
+ def message_from(message)
202
172
  return 'Unspecified error' if message.blank?
203
173
  message.gsub(/[^\w]/, ' ').split.join(" ").capitalize
204
174
  end
@@ -1,33 +1,30 @@
1
- #
2
- # Gateway for netregistry.com.au.
3
- #
4
- # Note that NetRegistry itself uses gateway service providers. At the
5
- # time of this writing, there are at least two (Quest and Ingenico).
6
- # This module has only been tested with Quest.
7
- #
8
- # Also note that NetRegistry does not offer a test mode, nor does it
9
- # have support for the authorize/capture/void functionality by default
10
- # (you may arrange for this as described in "Programming for
11
- # NetRegistry's E-commerce Gateway." [http://rubyurl.com/hNG]), and no
12
- # #void functionality is documented. As a result, the #authorize and
13
- # #capture have not yet been tested through a live gateway, and #void
14
- # will raise an error.
15
- #
16
- # If you have this functionality enabled, please consider contributing
17
- # to ActiveMerchant by writing tests/code for these methods, and
18
- # submitting a patch.
19
- #
20
- # In addition to the standard ActiveMerchant functionality, the
21
- # response will contain a 'receipt' parameter
22
- # (response.params['receipt']) if a receipt was issued by the gateway.
23
- # Also, a logger may be provided when instantiating the gateway to log
24
- # all data sent to/from the gateway (with sensitive information
25
- # hidden).
26
- #
27
1
  module ActiveMerchant
28
2
  module Billing
3
+ # Gateway for netregistry.com.au.
4
+ #
5
+ # Note that NetRegistry itself uses gateway service providers. At the
6
+ # time of this writing, there are at least two (Quest and Ingenico).
7
+ # This module has only been tested with Quest.
8
+ #
9
+ # Also note that NetRegistry does not offer a test mode, nor does it
10
+ # have support for the authorize/capture/void functionality by default
11
+ # (you may arrange for this as described in "Programming for
12
+ # NetRegistry's E-commerce Gateway." [http://rubyurl.com/hNG]), and no
13
+ # #void functionality is documented. As a result, the #authorize and
14
+ # #capture have not yet been tested through a live gateway, and #void
15
+ # will raise an error.
16
+ #
17
+ # If you have this functionality enabled, please consider contributing
18
+ # to ActiveMerchant by writing tests/code for these methods, and
19
+ # submitting a patch.
20
+ #
21
+ # In addition to the standard ActiveMerchant functionality, the
22
+ # response will contain a 'receipt' parameter
23
+ # (response.params['receipt']) if a receipt was issued by the gateway.
29
24
  class NetRegistryGateway < Gateway
30
- LIVE_URL = 'https://4tknox.au.com/cgi-bin/themerchant.au.com/ecom/external2.pl'
25
+ URL = 'https://4tknox.au.com/cgi-bin/themerchant.au.com/ecom/external2.pl'
26
+
27
+ FILTERED_PARAMS = [ 'card_no', 'card_expiry', 'receipt_array' ]
31
28
 
32
29
  self.supported_countries = ['AU']
33
30
 
@@ -39,66 +36,71 @@ module ActiveMerchant
39
36
  self.display_name = 'NetRegistry'
40
37
  self.homepage_url = 'http://www.netregistry.com.au'
41
38
 
39
+ TRANSACTIONS = {
40
+ :authorization => 'preauth',
41
+ :purchase => 'purchase',
42
+ :capture => 'completion',
43
+ :status => 'status',
44
+ :credit => 'refund'
45
+ }
46
+
42
47
  # Create a new NetRegistry gateway.
43
48
  #
44
49
  # Options :login and :password must be given.
45
- #
46
50
  def initialize(options = {})
47
51
  requires!(options, :login, :password)
48
- @logger = options[:logger]
49
52
  @options = options
50
53
  super
51
54
  end
52
55
 
53
- #
54
- # A Logger object used to write extra debugging output to. nil
55
- # for none.
56
- #
57
- attr_accessor :logger
58
-
59
- #
60
56
  # Note that #authorize and #capture only work if your account
61
57
  # vendor is St George, and if your account has been setup as
62
58
  # described in "Programming for NetRegistry's E-commerce
63
59
  # Gateway." [http://rubyurl.com/hNG]
64
- #
65
60
  def authorize(money, credit_card, options = {})
66
- post(options[:description],
67
- 'COMMAND' => 'preauth',
68
- 'AMOUNT' => amount(money),
69
- 'CCNUM' => credit_card.number,
70
- 'CCEXP' => expiry(credit_card))
61
+ params = {
62
+ 'AMOUNT' => amount(money),
63
+ 'CCNUM' => credit_card.number,
64
+ 'CCEXP' => expiry(credit_card)
65
+ }
66
+ add_request_details(params, options)
67
+ commit(:authorization, params)
71
68
  end
72
69
 
73
- #
74
70
  # Note that #authorize and #capture only work if your account
75
71
  # vendor is St George, and if your account has been setup as
76
72
  # described in "Programming for NetRegistry's E-commerce
77
73
  # Gateway." [http://rubyurl.com/hNG]
78
- #
79
74
  def capture(money, authorization, options = {})
80
75
  credit_card = options[:credit_card]
81
- post(options[:description],
82
- 'COMMAND' => 'completion',
83
- 'PREAUTHNUM' => authorization,
84
- 'AMOUNT' => amount(money),
85
- 'CCNUM' => credit_card.number,
86
- 'CCEXP' => expiry(credit_card))
76
+
77
+ params = {
78
+ 'PREAUTHNUM' => authorization,
79
+ 'AMOUNT' => amount(money),
80
+ 'CCNUM' => credit_card.number,
81
+ 'CCEXP' => expiry(credit_card)
82
+ }
83
+ add_request_details(params, options)
84
+ commit(:capture, params)
87
85
  end
88
86
 
89
87
  def purchase(money, credit_card, options = {})
90
- post(options[:description],
91
- 'COMMAND' => 'purchase',
92
- 'AMOUNT' => amount(money),
93
- 'CCNUM' => credit_card.number,
94
- 'CCEXP' => expiry(credit_card))
88
+ params = {
89
+ 'AMOUNT' => amount(money),
90
+ 'CCNUM' => credit_card.number,
91
+ 'CCEXP' => expiry(credit_card)
92
+ }
93
+ add_request_details(params, options)
94
+ commit(:purchase, params)
95
95
  end
96
96
 
97
97
  def credit(money, identification, options = {})
98
- post(options[:description],
99
- 'COMMAND' => 'refund',
100
- 'AMOUNT' => amount(money),
101
- 'TXNREF' => identification)
98
+ params = {
99
+ 'AMOUNT' => amount(money),
100
+ 'TXNREF' => identification
101
+ }
102
+ add_request_details(params, options)
103
+ commit(:credit, params)
102
104
  end
103
105
 
104
106
  # Specific to NetRegistry.
@@ -107,150 +109,79 @@ module ActiveMerchant
107
109
  # completed transaction.
108
110
  #
109
111
  def status(identification)
110
- post(options[:description],
111
- 'COMMAND' => 'status',
112
- 'TXNREF' => identification)
112
+ params = {
113
+ 'TXNREF' => identification
114
+ }
115
+
116
+ commit(:status, params)
113
117
  end
114
118
 
115
- private # -----------------------------------------------------
116
-
117
- #
119
+ private
120
+ def add_request_details(params, options)
121
+ params['COMMENT'] = options[:description] unless options[:description].blank?
122
+ end
123
+
118
124
  # Return the expiry for the given creditcard in the required
119
125
  # format for a command.
120
- #
121
126
  def expiry(credit_card)
122
127
  month = format(credit_card.month, :two_digits)
123
128
  year = format(credit_card.year , :two_digits)
124
129
  "#{month}/#{year}"
125
130
  end
126
131
 
127
- #
128
132
  # Post the a request with the given parameters and return the
129
133
  # response object.
130
134
  #
131
135
  # Login and password are added automatically, and the comment is
132
136
  # omitted if nil.
133
- #
134
- def post(comment, keyvals)
135
- if result = test_result_from_cc_number(keyvals['CCNUM'])
136
- return result
137
- end
138
-
139
- log "Executing #{keyvals['COMMAND']}:"
140
- login = @options[:login]
141
- password = @options[:password]
142
-
143
- # make query
144
- keyvals['COMMENT'] = comment if comment
145
- keyvals['LOGIN'] = "#{login}/#{password}"
146
- str = URI.encode(keyvals.map{|k,v| "#{k}=#{v}"}.join('&'))
147
- log " ActiveMerchant/NetRegistry: sending: #{obscure_send_string(str)}"
148
-
137
+ def commit(action, params)
149
138
  # get gateway response
150
- text = ssl_post(LIVE_URL, str)
151
- log " ActiveMerchant/NetRegistry: received:"
152
- obscure_recv_string(text).each do |line|
153
- log " #{line}"
154
- end
155
-
156
- # make response object
157
- response = parse_response(text, keyvals['COMMAND'])
158
-
159
- return response
160
- end
161
-
162
- #
163
- # Parse the text returned from the gateway into a Response object.
164
- #
165
- def parse_response(text, command)
166
- params = {'original_text' => text}
167
- sio = StringIO.new(text)
168
- params['status'] = sio.gets.chomp
169
- params['rrn'] = sio.gets.chomp
170
-
171
- if sio.eof?
172
- # some short errors have nothing else, e.g., "Invalid expiry
173
- # format"
174
- message = params.delete('rrn')
175
- return Response.new(false, message, params)
176
- end
177
-
178
- # parse receipt
179
- receipt = ''
180
- while (line = sio.gets)
181
- break if line.strip == '.'
182
- receipt << line
183
- end
184
-
185
- # parse params
186
- while (line = sio.gets)
187
- line.chomp!
188
- key, val = line.split(/=/, 2)
189
- params[key] = val
190
- end
191
-
192
- params['receipt'] = receipt
193
- authorization =
194
- case command
195
- when 'purchase'
196
- params['txn_ref']
197
- when 'preauth'
198
- params['transaction_no']
199
- else
200
- nil
201
- end
202
-
203
- Response.new(params['status'] == 'approved',
204
- params['response_text'],
205
- params,
206
- :authorization => authorization)
139
+ response = parse( ssl_post(URL, post_data(action, params)) )
140
+
141
+ Response.new(response['status'] == 'approved', message_from(response), response,
142
+ :authorization => authorization_from(response, action)
143
+ )
207
144
  end
208
-
209
- #
210
- # Log a message if logging is enabled.
211
- #
212
- def log(msg)
213
- logger.info(msg.chomp) unless logger.nil?
145
+
146
+ def post_data(action, params)
147
+ params['COMMAND'] = TRANSACTIONS[action]
148
+ params['LOGIN'] = "#{@options[:login]}/#{@options[:password]}"
149
+ URI.encode(params.map{|k,v| "#{k}=#{v}"}.join('&'))
214
150
  end
215
-
216
- #
217
- # Return a copy of the given string (to be sent to the gateway),
218
- # with sensitive information hidden.
219
- #
220
- def obscure_send_string(string)
221
- string.gsub(/LOGIN=[^&]+/) do |keyval|
222
- keyval.sub(/[^\/]+\z/){|pass| '*'*pass.size}
223
- end.gsub(/CCNUM=[^&]+/) do |keyval|
224
- keyval.sub(/[^=]+\z/){|num| obscure_card_number(num)}
225
- end.gsub(/CCEXP=[^&]+/) do |keyval|
226
- keyval.sub(/[^=]+\z/){|num| obscure_card_expiry(num)}
151
+
152
+ def parse(response)
153
+ params = {}
154
+
155
+ lines = response.split("\n")
156
+
157
+ # Just incase there is no real response returned
158
+ params['status'] = lines[0]
159
+ params['response_text'] = lines[1]
160
+
161
+ started = false
162
+ lines.each do |line|
163
+ if started
164
+ key, val = line.chomp.split(/=/, 2)
165
+ params[key] = val unless FILTERED_PARAMS.include?(key)
166
+ end
167
+
168
+ started = line.chomp =~ /^\.$/ unless started
227
169
  end
170
+
171
+ params
228
172
  end
229
-
230
- #
231
- # Return a copy of the given string (received from the gateway),
232
- # with sensitive information hidden.
233
- #
234
- def obscure_recv_string(string)
235
- string.
236
- gsub(/(card_(?:no|number)=)(.*)$/){$1 << obscure_card_number($2)}.
237
- gsub(/(card_expiry=)(.*)$/){$1 << obscure_card_expiry($2)}
238
- end
239
-
240
- #
241
- # Obscure a credit card number.
242
- #
243
- def obscure_card_number(number)
244
- return number if number.size < 4
245
- number[0...-4] = '*'*(number.size-4)
246
- return number
173
+
174
+ def message_from(response)
175
+ response['response_text']
247
176
  end
248
-
249
- #
250
- # Obscure a credit card expiry.
251
- #
252
- def obscure_card_expiry(expiry)
253
- expiry.gsub(/\d/, '*')
177
+
178
+ def authorization_from(response, command)
179
+ case command
180
+ when :purchase
181
+ response['txn_ref']
182
+ when :authorization
183
+ response['transaction_no']
184
+ end
254
185
  end
255
186
  end
256
187
  end