safecharge 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/runConfigurations/safe_change_spec.xml +35 -0
- data/lib/safecharge.rb +35 -0
- data/lib/safecharge/constants.rb +10 -3
- data/lib/safecharge/request.rb +2 -0
- data/lib/safecharge/sg_request.rb +66 -0
- data/lib/safecharge/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e16fac48537c2dc644f47d804971ff2d239934f2
|
4
|
+
data.tar.gz: 1a800151f2898ae5d67f5e53b0c271c905a278a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9ab27671b505cecc2009e3dcfc35d358f06399f5457f610fc8d920008010538e3a7462e5a541fa458ff7ae3b140889ee2838d8887c461bf224f1c16ea19b03c
|
7
|
+
data.tar.gz: a5528c5b61159db404acff2f829fc4b156b64161946a017130a14886d27cdfa7fd7e0d991b92d3e9d30531fe83f03f0e559df9cc9be7907e0013ad815aae4ccd
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<component name="ProjectRunConfigurationManager">
|
2
|
+
<configuration default="false" name="safe_change_spec" type="RSpecRunConfigurationType" factoryName="RSpec">
|
3
|
+
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
4
|
+
<module name="safecharge-api" />
|
5
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
6
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="" />
|
7
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
|
8
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
|
9
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
|
10
|
+
<envs />
|
11
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
|
12
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
13
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
14
|
+
<COVERAGE_PATTERN ENABLED="true">
|
15
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
16
|
+
</COVERAGE_PATTERN>
|
17
|
+
</EXTENSION>
|
18
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
19
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
|
20
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="spec/safecharge_spec.rb" />
|
21
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
22
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
23
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
|
24
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
25
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
26
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
27
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
28
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
29
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
|
30
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
31
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
32
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
33
|
+
<method />
|
34
|
+
</configuration>
|
35
|
+
</component>
|
data/lib/safecharge.rb
CHANGED
@@ -145,4 +145,39 @@ module Safecharge
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
+
# module level method to get the redirection URL given some params.
|
149
|
+
# you must explicitly set the mode to 'live' to generate the production URL.
|
150
|
+
def self.sg_request_url(params = {}, mode = 'test')
|
151
|
+
result = nil
|
152
|
+
url = ''
|
153
|
+
case mode
|
154
|
+
when 'test'
|
155
|
+
url = Safecharge::Constants::SG_SERVER_TEST
|
156
|
+
when 'live'
|
157
|
+
url = Safecharge::Constants::SG_SERVER_LIVE
|
158
|
+
else
|
159
|
+
raise ArgumentError, "Invalid request mode #{mode}"
|
160
|
+
end
|
161
|
+
|
162
|
+
begin
|
163
|
+
request = Safecharge::SgRequest.new(url, params)
|
164
|
+
return request.full_url
|
165
|
+
|
166
|
+
rescue InternalException => e
|
167
|
+
puts "Caught Internal Exception: #{e.message}"
|
168
|
+
puts e.backtrace
|
169
|
+
raise RuntimeError, "Internal server error. Please try again later."
|
170
|
+
|
171
|
+
rescue ValidationException => e
|
172
|
+
puts "Caught Validation Exception: #{e.message}"
|
173
|
+
puts e.backtrace
|
174
|
+
raise RuntimeError, "Validation error: #{e.message} Fix your data and retry."
|
175
|
+
|
176
|
+
rescue SafechargeError => e
|
177
|
+
puts "Caught General Safecharge Error: #{e.message}"
|
178
|
+
puts e.backtrace
|
179
|
+
raise RuntimeError, "Undocumented Internal error: #{e.message}"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
148
183
|
end
|
data/lib/safecharge/constants.rb
CHANGED
@@ -4,18 +4,25 @@
|
|
4
4
|
module Safecharge
|
5
5
|
class Constants
|
6
6
|
API_VERSION = '3.0.0'
|
7
|
+
SG_API_VERSION = '4.0.2'
|
7
8
|
|
8
9
|
SERVER_TEST = ENV['SAFECHARGE_SERVER_TEST'] # provided by SafeCharge
|
9
10
|
SERVER_LIVE = ENV['SAFECHARGE_SERVER_LIVE'] # provided by SafeCharge
|
10
|
-
|
11
|
+
|
12
|
+
SG_SERVER_TEST = ENV['SAFECHARGE_SG_SERVER_TEST'] # provided by SafeCharge
|
13
|
+
SG_SERVER_LIVE = ENV['SAFECHARGE_SG_SERVER_LIVE'] # provided by SafeCharge
|
14
|
+
SG_RESPONSE_FORMAT = 4 # XML
|
15
|
+
SG_DEFAULT_CREDIT_TYPE = 1 # Regular Credit
|
16
|
+
|
11
17
|
SECRET_KEY = ENV['SAFECHARGE_SECRET_KEY'] # provided by SafeCharge
|
12
18
|
MERCHANT_ID = ENV['SAFECHARGE_MERCHANT_ID'].to_i # provided by SafeCharge
|
13
19
|
MERCHANT_SITE_ID = ENV['SAFECHARGE_MERCHANT_SITE_ID'].to_i # provided by SafeCharge
|
14
20
|
MERCHANT_3D_SITE_ID = ENV['SAFECHARGE_MERCHANT_3D_SITE_ID'].to_i # provided by SafeCharge
|
15
|
-
|
21
|
+
|
22
|
+
SG_CLIENT_LOGIN_ID = ENV['SAFECHARGE_SG_CLIENT_LOGIN_ID'] # provided by SafeCharge
|
16
23
|
SG_CLIENT_PASSWORD = ENV['SAFECHARGE_SG_CLIENT_PASSWORD'] # provided by SafeCharge
|
17
24
|
SG_3D_CLIENT_PASSWORD = ENV['SAFECHARGE_SG_3D_CLIENT_PASSWORD'] # provided by SafeCharge
|
18
|
-
|
25
|
+
|
19
26
|
CPANEL_PASSWORD = ENV['SAFECHARGE_CPANEL_PASSWORD'] # provided by SafeCharge
|
20
27
|
|
21
28
|
APPROVED = 'APPROVED'
|
data/lib/safecharge/request.rb
CHANGED
@@ -143,6 +143,8 @@ module Safecharge
|
|
143
143
|
correct_type = p.is_a?(String) && ['true', 'false'].include?(p)
|
144
144
|
when 'usertoken'
|
145
145
|
correct_type = p.is_a?(String) && ['register', 'auto'].include?(p)
|
146
|
+
when 'sgtranstype'
|
147
|
+
correct_type = p.is_a?(String) && ['Sale', 'Auth', 'Settle', 'Credit', 'AVSOnly', 'Void', 'Auth3D'].include?(p)
|
146
148
|
when 'string'
|
147
149
|
correct_type = p.is_a? String
|
148
150
|
raise ValidationException, sprintf("Value '%s' in field '%s' is too long.", p, name) if p.size > meta[:length]
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#!/user/bin/env ruby
|
2
|
+
#coding: utf-8
|
3
|
+
|
4
|
+
require "safecharge"
|
5
|
+
require "safecharge/constants"
|
6
|
+
|
7
|
+
module Safecharge
|
8
|
+
class SgRequest < Request
|
9
|
+
|
10
|
+
ALLOWED_FIELDS = {
|
11
|
+
'sg_NameOnCard' => {:required => true, :type => 'string', length: 70},
|
12
|
+
'sg_CardNumber' => {:required => false, :type => 'string', length: 20},
|
13
|
+
'sg_ExpMonth' => {:required => true, :type => 'string', length: 2},
|
14
|
+
'sg_ExpYear' => {:required => true, :type => 'string', length: 2},
|
15
|
+
'sg_TransType' => {:required => true, :type => 'sgtranstype'},
|
16
|
+
'sg_Currency' => {:required => true, :type => 'currency_code'},
|
17
|
+
'sg_Amount' => {:required => true, :type => 'currency'},
|
18
|
+
'sg_AuthCode' => {:required => false, :type => 'string', length: 10},
|
19
|
+
'sg_ClientLoginID' => {:required => true, :type => 'string', length: 24},
|
20
|
+
'sg_ClientPassword' => {:required => true, :type => 'string', length: 24},
|
21
|
+
'sg_ClientUniqueID' => {:required => false, :type => 'string', length: 64},
|
22
|
+
'sg_TransactionID' => {:required => false, :type => 'string', length: 32},
|
23
|
+
'sg_CreditType' => {:required => true, :type => 'int'},
|
24
|
+
'sg_ResponseFormat' => {:required => true, :type => 'int'},
|
25
|
+
'sg_Version' => {:required => false, :type => 'string', length: 5},
|
26
|
+
'sg_FirstName' => {:required => true, :type => 'string', length: 30},
|
27
|
+
'sg_LastName' => {:required => true, :type => 'string', length: 40},
|
28
|
+
'sg_Address' => {:required => true, :type => 'string', length: 60},
|
29
|
+
'sg_City' => {:required => true, :type => 'string', length: 30},
|
30
|
+
'sg_State' => {:required => false, :type => 'string', length: 30},
|
31
|
+
'sg_Zip' => {:required => true, :type => 'string', length: 10}, # post code
|
32
|
+
'sg_Country' => {:required => true, :type => 'string', length: 3}, # ISO Code
|
33
|
+
'sg_Phone' => {:required => true, :type => 'string', length: 18},
|
34
|
+
'sg_IPAddress' => {:required => true, :type => 'string', length: 15},
|
35
|
+
'sg_Email' => {:required => true, :type => 'string', length: 100},
|
36
|
+
'sg_CCToken' => {:required => false, :type => 'string', length: 150}
|
37
|
+
|
38
|
+
}
|
39
|
+
|
40
|
+
DEFAULT_PARAMS = {
|
41
|
+
'sg_ClientLoginID' => Safecharge::Constants::SG_CLIENT_LOGIN_ID,
|
42
|
+
'sg_ClientPassword' => Safecharge::Constants::SG_CLIENT_PASSWORD,
|
43
|
+
'sg_Currency' => Safecharge::Constants::DEFAULT_CURRENCY_CODE,
|
44
|
+
'sg_CreditType' => Safecharge::Constants::SG_DEFAULT_CREDIT_TYPE,
|
45
|
+
'sg_Version' => Safecharge::Constants::SG_API_VERSION,
|
46
|
+
'sg_ResponseFormat' => Safecharge::Constants::SG_RESPONSE_FORMAT
|
47
|
+
}
|
48
|
+
|
49
|
+
def initialize(a_url, some_params = {})
|
50
|
+
raise ArgumentError, "missing url" if a_url == nil || a_url.empty?
|
51
|
+
if a_url === Safecharge::Constants::SG_SERVER_TEST
|
52
|
+
self.mode = 'test'
|
53
|
+
elsif a_url === Safecharge::Constants::SG_SERVER_LIVE
|
54
|
+
self.mode = 'live'
|
55
|
+
else
|
56
|
+
raise ArgumentError, "invalid url #{a_url}"
|
57
|
+
end
|
58
|
+
self.url = a_url
|
59
|
+
self.full_url = a_url
|
60
|
+
self.params = DEFAULT_PARAMS.merge(convert_symbols_to_strings(some_params))
|
61
|
+
self.validate_parameters(self.params)
|
62
|
+
self.construct_url
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
data/lib/safecharge/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safecharge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Sag
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,7 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- .idea/runConfigurations/safe_change_spec.xml
|
76
77
|
- Gemfile
|
77
78
|
- LICENSE.txt
|
78
79
|
- README.md
|
@@ -81,6 +82,7 @@ files:
|
|
81
82
|
- lib/safecharge/dmn.rb
|
82
83
|
- lib/safecharge/request.rb
|
83
84
|
- lib/safecharge/response.rb
|
85
|
+
- lib/safecharge/sg_request.rb
|
84
86
|
- lib/safecharge/version.rb
|
85
87
|
- lib/safecharge/wc_request.rb
|
86
88
|
- safecharge.gemspec
|