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.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +310 -294
- data/CONTRIBUTERS +13 -0
- data/README +55 -31
- data/Rakefile +21 -13
- data/lib/active_merchant.rb +7 -0
- data/lib/active_merchant/billing/avs_result.rb +95 -0
- data/lib/active_merchant/billing/base.rb +8 -3
- data/lib/active_merchant/billing/check.rb +61 -0
- data/lib/active_merchant/billing/credit_card.rb +104 -80
- data/lib/active_merchant/billing/credit_card_formatting.rb +11 -8
- data/lib/active_merchant/billing/credit_card_methods.rb +76 -32
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/expiry_date.rb +28 -0
- data/lib/active_merchant/billing/gateway.rb +47 -111
- data/lib/active_merchant/billing/gateways/authorize_net.rb +508 -121
- data/lib/active_merchant/billing/gateways/bogus.rb +26 -32
- data/lib/active_merchant/billing/gateways/brain_tree.rb +82 -70
- data/lib/active_merchant/billing/gateways/card_stream.rb +43 -15
- data/lib/active_merchant/billing/gateways/cyber_source.rb +9 -29
- data/lib/active_merchant/billing/gateways/data_cash.rb +18 -38
- data/lib/active_merchant/billing/gateways/efsnet.rb +23 -50
- data/lib/active_merchant/billing/gateways/eway.rb +8 -19
- data/lib/active_merchant/billing/gateways/exact.rb +17 -25
- data/lib/active_merchant/billing/gateways/linkpoint.rb +18 -25
- data/lib/active_merchant/billing/gateways/moneris.rb +9 -39
- data/lib/active_merchant/billing/gateways/net_registry.rb +113 -182
- data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +52 -73
- data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +13 -14
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +55 -37
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +4 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +2 -4
- data/lib/active_merchant/billing/gateways/payment_express.rb +11 -30
- data/lib/active_merchant/billing/gateways/paypal.rb +3 -14
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +36 -16
- data/lib/active_merchant/billing/gateways/paypal_express.rb +1 -2
- data/lib/active_merchant/billing/gateways/plugnpay.rb +7 -15
- data/lib/active_merchant/billing/gateways/protx.rb +24 -25
- data/lib/active_merchant/billing/gateways/psigate.rb +34 -71
- data/lib/active_merchant/billing/gateways/psl_card.rb +24 -19
- data/lib/active_merchant/billing/gateways/quickpay.rb +10 -24
- data/lib/active_merchant/billing/gateways/realex.rb +7 -19
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +437 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +5 -14
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +100 -39
- data/lib/active_merchant/billing/gateways/usa_epay.rb +60 -55
- data/lib/active_merchant/billing/gateways/verifi.rb +32 -39
- data/lib/active_merchant/billing/gateways/viaklix.rb +31 -37
- data/lib/active_merchant/billing/integrations.rb +2 -0
- data/lib/active_merchant/billing/integrations/bogus.rb +5 -0
- data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/chronopay.rb +5 -0
- data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/gestpay.rb +5 -0
- data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/hi_trust.rb +26 -0
- data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
- data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +57 -0
- data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
- data/lib/active_merchant/billing/integrations/nochex.rb +5 -0
- data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/paypal.rb +5 -0
- data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/return.rb +35 -0
- data/lib/active_merchant/billing/integrations/two_checkout.rb +5 -0
- data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
- data/lib/active_merchant/billing/response.rb +12 -8
- data/lib/active_merchant/lib/posts_data.rb +39 -7
- data/lib/active_merchant/lib/requires_parameters.rb +2 -3
- data/lib/active_merchant/lib/utils.rb +18 -0
- data/lib/active_merchant/lib/validateable.rb +3 -3
- data/lib/support/gateway_support.rb +22 -9
- data/script/destroy +14 -0
- data/script/generate +7 -7
- data/test/fixtures.yml +25 -3
- data/test/remote/gateways/remote_authorize_net_test.rb +145 -0
- data/test/remote/gateways/remote_brain_tree_test.rb +118 -0
- data/test/{remote_tests → remote/gateways}/remote_card_stream_test.rb +56 -68
- data/test/{remote_tests → remote/gateways}/remote_cyber_source_test.rb +21 -32
- data/test/{remote_tests → remote/gateways}/remote_data_cash_test.rb +2 -2
- data/test/{remote_tests → remote/gateways}/remote_efsnet_test.rb +22 -34
- data/test/{remote_tests → remote/gateways}/remote_eway_test.rb +18 -15
- data/test/{remote_tests → remote/gateways}/remote_exact_test.rb +20 -19
- data/test/{remote_tests → remote/gateways}/remote_linkpoint_test.rb +31 -63
- data/test/remote/gateways/remote_moneris_test.rb +82 -0
- data/test/{remote_tests → remote/gateways}/remote_net_registry_test.rb +19 -54
- data/test/remote/gateways/remote_netbilling_test.rb +70 -0
- data/test/{remote_tests → remote/gateways}/remote_pay_junction_test.rb +41 -60
- data/test/remote/gateways/remote_pay_secure_test.rb +39 -0
- data/test/{remote_tests → remote/gateways}/remote_payflow_express_test.rb +2 -2
- data/test/{remote_tests → remote/gateways}/remote_payflow_test.rb +34 -38
- data/test/{remote_tests → remote/gateways}/remote_payflow_uk_test.rb +13 -12
- data/test/{remote_tests → remote/gateways}/remote_payment_express_test.rb +26 -36
- data/test/{remote_tests → remote/gateways}/remote_paypal_express_test.rb +3 -3
- data/test/{remote_tests → remote/gateways}/remote_paypal_test.rb +25 -21
- data/test/{remote_tests → remote/gateways}/remote_plugnpay_test.rb +18 -16
- data/test/{remote_tests → remote/gateways}/remote_protx_test.rb +33 -33
- data/test/remote/gateways/remote_psigate_test.rb +50 -0
- data/test/{remote_tests → remote/gateways}/remote_psl_card_test.rb +27 -26
- data/test/{remote_tests → remote/gateways}/remote_quickpay_test.rb +48 -48
- data/test/{remote_tests → remote/gateways}/remote_realex_test.rb +30 -33
- data/test/remote/gateways/remote_secure_pay_tech_test.rb +37 -0
- data/test/remote/gateways/remote_secure_pay_test.rb +28 -0
- data/test/remote/gateways/remote_skipjack_test.rb +105 -0
- data/test/{remote_tests → remote/gateways}/remote_trans_first_test.rb +7 -10
- data/test/remote/gateways/remote_trust_commerce_test.rb +152 -0
- data/test/{remote_tests → remote/gateways}/remote_usa_epay_test.rb +11 -22
- data/test/{remote_tests → remote/gateways}/remote_verifi_test.rb +27 -27
- data/test/{remote_tests → remote/gateways}/remote_viaklix_test.rb +8 -18
- data/test/{remote_tests → remote/integrations}/remote_gestpay_integration_test.rb +1 -1
- data/test/{remote_tests → remote/integrations}/remote_paypal_integration_test.rb +1 -1
- data/test/test_helper.rb +102 -61
- data/test/unit/avs_result_test.rb +59 -0
- data/test/unit/base_test.rb +33 -39
- data/test/unit/check_test.rb +76 -0
- data/test/unit/credit_card_formatting_test.rb +10 -15
- data/test/unit/credit_card_methods_test.rb +132 -17
- data/test/unit/credit_card_test.rb +157 -228
- data/test/unit/cvv_result_test.rb +33 -0
- data/test/unit/expiry_date_test.rb +21 -0
- data/test/unit/gateways/authorize_net_test.rb +180 -40
- data/test/unit/gateways/bogus_test.rb +2 -3
- data/test/unit/gateways/brain_tree_test.rb +63 -29
- data/test/unit/gateways/card_stream_test.rb +59 -6
- data/test/unit/gateways/cyber_source_test.rb +59 -40
- data/test/unit/gateways/data_cash_test.rb +82 -1
- data/test/unit/gateways/efsnet_test.rb +97 -44
- data/test/unit/gateways/eway_test.rb +55 -42
- data/test/unit/gateways/exact_test.rb +93 -55
- data/test/unit/gateways/gateway_test.rb +7 -0
- data/test/unit/gateways/linkpoint_test.rb +60 -58
- data/test/unit/gateways/moneris_test.rb +67 -76
- data/test/unit/gateways/net_registry_test.rb +351 -419
- data/test/unit/gateways/netbilling_test.rb +54 -0
- data/test/unit/gateways/pay_junction_test.rb +108 -46
- data/test/unit/gateways/pay_secure_test.rb +71 -0
- data/test/unit/gateways/payflow_express_test.rb +0 -8
- data/test/unit/gateways/payflow_test.rb +136 -65
- data/test/unit/gateways/payflow_uk_test.rb +0 -38
- data/test/unit/gateways/payment_express_test.rb +31 -51
- data/test/unit/gateways/paypal_express_test.rb +8 -2
- data/test/unit/gateways/paypal_test.rb +213 -54
- data/test/unit/gateways/plugnpay_test.rb +39 -32
- data/test/unit/gateways/protx_test.rb +45 -33
- data/test/unit/gateways/psigate_test.rb +146 -87
- data/test/unit/gateways/psl_card_test.rb +37 -24
- data/test/unit/gateways/quickpay_test.rb +33 -46
- data/test/unit/gateways/realex_test.rb +32 -31
- data/test/unit/gateways/secure_pay_tech_test.rb +44 -0
- data/test/unit/gateways/secure_pay_test.rb +35 -26
- data/test/unit/gateways/skip_jack_test.rb +125 -0
- data/test/unit/gateways/trans_first_test.rb +24 -37
- data/test/unit/gateways/trust_commerce_test.rb +47 -26
- data/test/unit/gateways/usa_epay_test.rb +52 -41
- data/test/unit/gateways/verifi_test.rb +41 -35
- data/test/unit/gateways/viaklix_test.rb +38 -32
- data/test/unit/generators/test_gateway_generator.rb +46 -0
- data/test/unit/generators/test_generator_helper.rb +20 -0
- data/test/unit/generators/test_integration_generator.rb +53 -0
- data/test/unit/integrations/action_view_helper_test.rb +7 -14
- data/test/unit/integrations/bogus_module_test.rb +4 -0
- data/test/unit/integrations/chronopay_module_test.rb +4 -0
- data/test/unit/integrations/gestpay_module_test.rb +4 -0
- data/test/unit/integrations/helpers/hi_trust_helper_test.rb +16 -0
- data/test/unit/integrations/hi_trust_module_test.rb +13 -0
- data/test/unit/integrations/nochex_module_test.rb +4 -0
- data/test/unit/integrations/notifications/hi_trust_notification_test.rb +38 -0
- data/test/unit/integrations/paypal_module_test.rb +4 -0
- data/test/unit/integrations/returns/chronopay_return_test.rb +11 -0
- data/test/unit/integrations/returns/gestpay_return_test.rb +10 -0
- data/test/unit/integrations/returns/hi_trust_return_test.rb +24 -0
- data/test/unit/integrations/returns/nochex_return_test.rb +10 -0
- data/test/unit/integrations/returns/paypal_return_test.rb +10 -0
- data/test/unit/integrations/returns/return_test.rb +11 -0
- data/test/unit/integrations/returns/two_checkout_return_test.rb +24 -0
- data/test/unit/integrations/two_checkout_module_test.rb +4 -0
- data/test/unit/posts_data_test.rb +86 -0
- data/test/unit/response_test.rb +15 -1
- data/test/unit/utils_test.rb +7 -0
- data/test/unit/validateable_test.rb +10 -6
- metadata +180 -142
- metadata.gz.sig +0 -0
- data/lib/active_merchant/billing/gateways/paypal/api_cert_chain.crt +0 -35
- data/script/generator/base.rb +0 -45
- data/script/generator/generator.rb +0 -24
- data/script/generator/generators/gateway/gateway_generator.rb +0 -14
- data/script/generator/generators/gateway/templates/gateway.rb +0 -73
- data/script/generator/generators/gateway/templates/gateway_test.rb +0 -41
- data/script/generator/generators/gateway/templates/remote_gateway_test.rb +0 -56
- data/script/generator/generators/integration/integration_generator.rb +0 -25
- data/script/generator/generators/integration/templates/helper.rb +0 -34
- data/script/generator/generators/integration/templates/helper_test.rb +0 -54
- data/script/generator/generators/integration/templates/integration.rb +0 -18
- data/script/generator/generators/integration/templates/module_test.rb +0 -9
- data/script/generator/generators/integration/templates/notification.rb +0 -100
- data/script/generator/generators/integration/templates/notification_test.rb +0 -41
- data/script/generator/manifest.rb +0 -20
- data/test/remote_tests/remote_authorize_net_test.rb +0 -113
- data/test/remote_tests/remote_brain_tree_test.rb +0 -78
- data/test/remote_tests/remote_moneris_test.rb +0 -110
- data/test/remote_tests/remote_psigate_test.rb +0 -87
- data/test/remote_tests/remote_secure_pay_test.rb +0 -36
- 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
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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(
|
|
122
|
+
Response.new(successful?(response), message_from(response[:message]), response,
|
|
133
123
|
:test => test?,
|
|
134
|
-
:authorization =>
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
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
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|