agms 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +4 -1
- data/lib/agms/configuration.rb +4 -4
- data/lib/agms/connect.rb +54 -54
- data/lib/agms/error/agms_error.rb +7 -6
- data/lib/agms/error/authentication_error.rb +4 -4
- data/lib/agms/error/authorization_error.rb +1 -1
- data/lib/agms/error/client_error_error.rb +1 -1
- data/lib/agms/error/configuation_error.rb +1 -1
- data/lib/agms/error/down_for_maintenance_error.rb +1 -1
- data/lib/agms/error/forged_query_String_error.rb +1 -1
- data/lib/agms/error/invalid_parameter_error.rb +1 -1
- data/lib/agms/error/invalid_request_error.rb +1 -1
- data/lib/agms/error/invalid_signature_error.rb +1 -1
- data/lib/agms/error/not_found_error.rb +1 -1
- data/lib/agms/error/request_validation_error.rb +1 -1
- data/lib/agms/error/response_error.rb +4 -4
- data/lib/agms/error/server_error_error.rb +1 -1
- data/lib/agms/error/ssl_certificate_error.rb +1 -1
- data/lib/agms/error/unexpected_error.rb +1 -1
- data/lib/agms/error/upgrade_required_error.rb +1 -1
- data/lib/agms/request/hpp_request.rb +11 -11
- data/lib/agms/request/invoicing_request.rb +2 -2
- data/lib/agms/request/request.rb +48 -48
- data/lib/agms/request/safe_request.rb +17 -17
- data/lib/agms/request/transaction_request.rb +69 -69
- data/lib/agms/transaction.rb +15 -15
- data/lib/agms/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjU0NzZkYTY1YzA1ZTgyNGViMTRmZTA2YmFlMWM0N2ZkYmRkZjg2YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTFiODVhZWI3NmYyNDUxODljZmM0YWM2YjRkNmRmM2IyMTk1NWU3Nw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWNiMzZiNGI2OWY2MTIxOGFhMmI5MmU3NzA0OTA3ZWNlZTRjOGNjM2FiY2Rl
|
10
|
+
YjEyZDQ3YjA0ODc0YTgzMjNjYTJmMTk3ODRlZTJhYzY1ZTg3M2M0OTk0ZGVk
|
11
|
+
YzUxYTU2ZjcwNGJmZDAwZTU0Njk1N2YyN2ZmNTIzMmJkZjM3NzA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzdlNDA3MjI1YjdhZjAyN2MwN2ZmNDQwMjk4MzNjMGYxMzQ3YjVmZjQzMmYy
|
14
|
+
NjYzZDk4Zjg0NTQzZDUzZjQxYzc5OTQ5OWRjMzA5OGI1Yjk4Nzc0MDVmMDc5
|
15
|
+
YzIyMTVkMTQyZmRmN2RkZjVkYjE1M2JlYjQ1M2ZkOTliNzY1YzU=
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ Support for Invoicing and Recurring are not yet completed.
|
|
32
32
|
## Documentation
|
33
33
|
|
34
34
|
* [Official documentation](https://www.onlinepaymentprocessing.com/docs/ruby)
|
35
|
-
* [Bug Tracker](http://github.com/
|
35
|
+
* [Bug Tracker](http://github.com/agmscode/agms_ruby/issues)
|
36
36
|
|
37
37
|
Examples can be found as part of this package in example /hpp.rb, example/invoicing.rb, example/recurring.rb, example_report.py, example/safe.rb, example/transaction.rb.
|
38
38
|
|
@@ -41,6 +41,9 @@ Examples can be found as part of this package in example /hpp.rb, example/invoic
|
|
41
41
|
|
42
42
|
See the LICENSE file.
|
43
43
|
|
44
|
+
## Development
|
45
|
+
|
46
|
+
Test cases can be run with: `bundle exec rake test`
|
44
47
|
|
45
48
|
## Contributing
|
46
49
|
|
data/lib/agms/configuration.rb
CHANGED
@@ -52,10 +52,10 @@ module Agms
|
|
52
52
|
|
53
53
|
def self.instantiate()
|
54
54
|
return Configuration.new(
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
Configuration.gateway_username,
|
56
|
+
Configuration.gateway_password,
|
57
|
+
Configuration.gateway_account,
|
58
|
+
Configuration.gateway_api_key,
|
59
59
|
)
|
60
60
|
end
|
61
61
|
|
data/lib/agms/connect.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
module Agms
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
class Connect
|
3
|
+
|
4
|
+
# @param integer status
|
5
|
+
# @return boolean
|
6
|
+
def self.is_exception_status(status)
|
7
|
+
if [200, 201, 422].include?(status)
|
6
8
|
return true
|
7
9
|
else
|
8
|
-
|
10
|
+
return false
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
12
|
-
|
14
|
+
def self.raise_exception_for_status(status, message=nil)
|
13
15
|
case status.to_i
|
14
16
|
when 401
|
15
17
|
raise AuthenticationError
|
@@ -33,36 +35,36 @@ module Agms
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def connect(url, request, request_method, response_object)
|
36
|
-
|
38
|
+
headers = _buildHeaders(request_method)
|
37
39
|
request_body = _buildRequest(request, request_method)
|
38
40
|
response_body = post(url, headers, request_body)
|
39
41
|
return _parseResponse(response_body, request_method)
|
40
|
-
|
42
|
+
end
|
41
43
|
|
42
|
-
|
44
|
+
def post(url, headers = nil, body = nil)
|
43
45
|
return _http_do(Net::HTTP::Post, url, headers, body)
|
44
46
|
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
+
def delete(url, headers = nil, body = nil)
|
49
|
+
return _http_do(Net::HTTP::Delete, url, headers, body)
|
48
50
|
end
|
49
51
|
|
50
52
|
def get(url, headers = nil, body = nil)
|
51
|
-
|
53
|
+
return _http_do Net::HTTP::Get, url, headers, body
|
52
54
|
end
|
53
55
|
|
54
56
|
def put(url, headers = nil, body = nil)
|
55
|
-
|
57
|
+
return _http_do Net::HTTP::Put, url, headers, body
|
56
58
|
end
|
57
59
|
|
58
60
|
def _http_do(http_verb, url, headers = nil, body = nil)
|
59
61
|
connection = Net::HTTP.new(Configuration.server, Configuration.port)
|
60
62
|
connection.open_timeout = 60
|
61
63
|
connection.read_timeout = 60
|
62
|
-
|
63
|
-
|
64
|
+
|
65
|
+
connection.use_ssl = true
|
64
66
|
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
65
|
-
|
67
|
+
|
66
68
|
# connection.ca_file = @config.ca_file
|
67
69
|
connection.verify_callback = proc { |preverify_ok, ssl_context| _verify_ssl_certificate(preverify_ok, ssl_context) }
|
68
70
|
|
@@ -72,12 +74,12 @@ module Agms
|
|
72
74
|
end
|
73
75
|
|
74
76
|
connection.start do |http|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
request = http_verb.new(url)
|
78
|
+
|
79
|
+
if headers
|
80
|
+
headers.each do |key, value|
|
81
|
+
request[key] = value
|
82
|
+
end
|
81
83
|
end
|
82
84
|
if body
|
83
85
|
request.body = body
|
@@ -85,40 +87,40 @@ module Agms
|
|
85
87
|
|
86
88
|
response = http.request(request)
|
87
89
|
if response.code.to_i == 200 || response.code.to_i == 201 || response.code.to_i == 422
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
return response.body
|
91
|
+
else
|
92
|
+
Connect.raise_exception_for_status(response.code)
|
93
|
+
end
|
92
94
|
end
|
93
95
|
rescue OpenSSL::SSL::SSLError
|
94
96
|
raise SSLCertificateError
|
95
97
|
end
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
99
|
+
# Build Header
|
100
|
+
def _buildHeaders(request_method)
|
101
|
+
return {
|
102
|
+
'Accept' => 'application/xml',
|
103
|
+
'Content-type' => 'text/xml; charset=utf-8',
|
104
|
+
'User-Agent' => '(Agms Ruby ' + Agms.getLibraryVersion() + ')',
|
105
|
+
'X-ApiVersion' => Agms.getAPIVersion(),
|
106
|
+
'SOAPAction' => 'https://gateway.agms.com/roxapi/' + request_method
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
# Build Request
|
111
|
+
def _buildRequest(request, request_method)
|
112
|
+
header = '<soap:Envelope
|
111
113
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
112
114
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
113
115
|
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
114
116
|
<soap:Body>'
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
117
|
+
|
118
|
+
header_line = '<' + request_method + ' xmlns="https://gateway.agms.com/roxapi/">'
|
119
|
+
body = _hashToXml(request)
|
120
|
+
footer_line = '</' + request_method + '>'
|
121
|
+
footer = '</soap:Body></soap:Envelope>'
|
122
|
+
return header + header_line + body + footer_line + footer
|
123
|
+
end
|
122
124
|
|
123
125
|
# Build xml from Hash
|
124
126
|
def _hashToXml(request)
|
@@ -140,7 +142,7 @@ module Agms
|
|
140
142
|
return data
|
141
143
|
end
|
142
144
|
|
143
|
-
|
145
|
+
def _verify_ssl_certificate(preverify_ok, ssl_context)
|
144
146
|
if preverify_ok != true || ssl_context.error != 0
|
145
147
|
err_msg = "SSL Verification failed -- Preverify: #{preverify_ok}, Error: #{ssl_context.error_string} (#{ssl_context.error})"
|
146
148
|
@config.logger.error err_msg
|
@@ -150,8 +152,8 @@ module Agms
|
|
150
152
|
end
|
151
153
|
end
|
152
154
|
|
153
|
-
|
154
|
-
|
155
|
+
# Parse the response received from gateway
|
156
|
+
def _parseResponse(xml, request_method)
|
155
157
|
# Parse the response body
|
156
158
|
doc = Nokogiri::XML(xml)
|
157
159
|
# Remove the namespaces
|
@@ -167,10 +169,8 @@ module Agms
|
|
167
169
|
response = node.children.text
|
168
170
|
end
|
169
171
|
end
|
170
|
-
|
171
172
|
return response
|
172
|
-
|
173
|
+
end
|
173
174
|
|
174
|
-
|
175
|
-
end
|
175
|
+
end
|
176
176
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Agms
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
class AgmsError < StandardError
|
3
|
+
attr_accessor :object
|
4
|
+
|
5
|
+
def initialize(message = nil, object = nil)
|
6
|
+
super(message)
|
7
|
+
self.object = object
|
8
8
|
end
|
9
|
+
end
|
9
10
|
end
|
@@ -106,10 +106,10 @@ module Agms
|
|
106
106
|
@required = Array.new
|
107
107
|
|
108
108
|
# All sales and auth require an amount unless donation
|
109
|
-
if (
|
110
|
-
|
109
|
+
if ((@fields[:Donation][:value] != '' or
|
110
|
+
@fields[:Donation][:value] != false) and
|
111
111
|
(@fields[:TransactionType][:value] == 'sale' or
|
112
|
-
|
112
|
+
@fields[:TransactionType][:value] == 'auth'))
|
113
113
|
@required.push(:Amount)
|
114
114
|
end
|
115
115
|
|
@@ -119,25 +119,25 @@ module Agms
|
|
119
119
|
messages = error_array['messages'];
|
120
120
|
|
121
121
|
# ExpDate MMYY
|
122
|
-
if (
|
122
|
+
if (@fields.has_key?(:CCExpDate) and
|
123
123
|
@fields[:CCExpDate][:value] != '' and
|
124
|
-
(
|
125
|
-
not /(0[1-9]|1[0-2])([0-9][0-9])/.match(@fields[:CCExpDate][:value])
|
124
|
+
(@fields[:CCExpDate][:value].length != 4 or
|
125
|
+
not /(0[1-9]|1[0-2])([0-9][0-9])/.match(@fields[:CCExpDate][:value])))
|
126
126
|
errors += 1
|
127
127
|
messages.push('CCExpDate (credit card expiration date) must be MMYY.')
|
128
128
|
end
|
129
129
|
|
130
130
|
# CCNumber length
|
131
|
-
if (
|
132
|
-
@fields[:CCNumber][:value] != ''
|
131
|
+
if (@fields.has_key?(:CCNumber) and
|
132
|
+
@fields[:CCNumber][:value] != '' and
|
133
133
|
@fields[:CCNumber][:value].length != 16 and
|
134
|
-
@fields[:CCNumber][:value].length != 15
|
134
|
+
@fields[:CCNumber][:value].length != 15)
|
135
135
|
errors += 1
|
136
136
|
messages.push('CCNumber (credit card number) must be 15-16 digits long.')
|
137
137
|
end
|
138
138
|
|
139
139
|
# ABA length
|
140
|
-
if
|
140
|
+
if (@fields.has_key?(:CheckABA) and
|
141
141
|
@fields[:CheckABA][:value] != '' and
|
142
142
|
@fields[:CheckABA][:value].length != 9)
|
143
143
|
errors += 1
|
@@ -156,7 +156,7 @@ module Agms
|
|
156
156
|
end
|
157
157
|
|
158
158
|
def getFields
|
159
|
-
fields =
|
159
|
+
fields = getFieldArray
|
160
160
|
if fields.has_key?(:AutoSAFE)
|
161
161
|
if fields[:AutoSAFE] == true
|
162
162
|
fields[:AutoSAFE] = 1
|
data/lib/agms/request/request.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
module Agms
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
2
|
+
class Request
|
3
|
+
def initialize(op)
|
4
|
+
@op = op
|
5
|
+
@validateErrors = 0
|
6
|
+
@validateMessages = nil
|
7
|
+
@fields = nil
|
8
|
+
@required = nil
|
9
|
+
@numeric = nil
|
10
|
+
@optionable = nil
|
11
|
+
@enums = nil
|
12
|
+
@date = nil
|
13
|
+
@time = nil
|
14
|
+
@boolean = nil
|
15
|
+
@digit_2 = nil
|
16
|
+
@amount = nil
|
17
|
+
|
18
|
+
@needs_account = nil
|
19
|
+
@needs_key = nil
|
20
|
+
|
21
|
+
@mapping_alias = nil
|
22
|
+
|
23
|
+
@mapping = {
|
24
24
|
:gateway_username => :GatewayUserName,
|
25
25
|
:gateway_password => :GatewayPassword,
|
26
26
|
:gateway_account => :AccountNumber,
|
@@ -128,17 +128,17 @@ module Agms
|
|
128
128
|
:start_time => :StartTime,
|
129
129
|
:end_time => :EndTime,
|
130
130
|
:suppress_safe_option => :SupressAutoSAFE
|
131
|
-
|
131
|
+
}
|
132
132
|
|
133
|
-
|
134
|
-
|
133
|
+
@states = %w(AL AK AS AZ AR CA CO CT DE DC FM FL GA GU HI ID IL IN IA KS KY LA ME MH MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND MP OH OK OR PW PA PR RI SC SD TN TX UT VT VI VA WA WV WI WY AE AA AP)
|
134
|
+
end
|
135
135
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
136
|
+
def get(username, password, account, api_key)
|
137
|
+
request_body = getFields()
|
138
|
+
request_body[:GatewayUserName] = username
|
139
|
+
request_body[:GatewayPassword] = password
|
140
140
|
|
141
|
-
|
141
|
+
# Adjust for a field name variation in the Reporting API
|
142
142
|
if @op == 'TransactionAPI' or @op == 'QuerySAFE'
|
143
143
|
request_body.delete(:GatewayUserName)
|
144
144
|
request_body[:GatewayUsername] = username
|
@@ -179,13 +179,13 @@ module Agms
|
|
179
179
|
end
|
180
180
|
|
181
181
|
# Check that it is a valid setting
|
182
|
-
if (
|
182
|
+
if (parameter == :setting and
|
183
183
|
value != '' and
|
184
184
|
value != 'required' and
|
185
185
|
value != 'disabled' and
|
186
186
|
value != 'visible' and
|
187
187
|
value != 'excluded' and
|
188
|
-
value != 'hidden'
|
188
|
+
value != 'hidden')
|
189
189
|
raise InvalidParameterError, "Invalid parameter #{parameter} for #{name}."
|
190
190
|
end
|
191
191
|
|
@@ -220,7 +220,7 @@ module Agms
|
|
220
220
|
messages = Array.new
|
221
221
|
|
222
222
|
if @required
|
223
|
-
@required.each do |
|
223
|
+
@required.each do |field_name|
|
224
224
|
if @fields[field_name][:value] == ''
|
225
225
|
errors +=1
|
226
226
|
messages.push("Missing required field #{field_name}.")
|
@@ -230,11 +230,11 @@ module Agms
|
|
230
230
|
|
231
231
|
# Validate enumerated types
|
232
232
|
if @enums
|
233
|
-
@enums.each do |
|
233
|
+
@enums.each do |field_name, valid_values|
|
234
234
|
|
235
235
|
if @fields.has_key?(field_name) and
|
236
236
|
@fields[field_name][:value] != '' and
|
237
|
-
not valid_values.include
|
237
|
+
not valid_values.include? @fields[field_name][:value]
|
238
238
|
errors += 1
|
239
239
|
messages.push("Invalid #{field_name}, value " + @fields[field_name][:value] + ', must be one of ' + valid_values.join(' ') + '.')
|
240
240
|
end
|
@@ -243,7 +243,7 @@ module Agms
|
|
243
243
|
|
244
244
|
# Validate numeric fields
|
245
245
|
if @numeric
|
246
|
-
@numeric.each do |
|
246
|
+
@numeric.each do |field_name|
|
247
247
|
if @fields.has_key?(field_name) and
|
248
248
|
@fields[field_name][:value] != '' and
|
249
249
|
not isNumber(@fields[field_name][:value])
|
@@ -255,14 +255,14 @@ module Agms
|
|
255
255
|
|
256
256
|
# Validate optionable fields
|
257
257
|
if @optionable
|
258
|
-
@optionable.each do |
|
259
|
-
if (
|
258
|
+
@optionable.each do |field_name|
|
259
|
+
if (@fields.has_key?(field_name) and
|
260
260
|
@fields[field_name][:setting] != '' and
|
261
261
|
@fields[field_name][:setting] != :required and
|
262
262
|
@fields[field_name][:setting] != :disabled and
|
263
263
|
@fields[field_name][:setting] != :visible and
|
264
264
|
@fields[field_name][:setting] != :excluded and
|
265
|
-
@fields[field_name][:setting] != :hidden
|
265
|
+
@fields[field_name][:setting] != :hidden)
|
266
266
|
errors += 1
|
267
267
|
messages.push("Field #{field_name} has setting " + @fields[field_name][:value] + ', must be required, disabled, visible, hidden, or empty.')
|
268
268
|
end
|
@@ -271,7 +271,7 @@ module Agms
|
|
271
271
|
|
272
272
|
# Validate date fields
|
273
273
|
if @date
|
274
|
-
@date.each do |
|
274
|
+
@date.each do |field_name|
|
275
275
|
|
276
276
|
if @fields.has_key?(field_name) and
|
277
277
|
@fields[field_name][:value] != '' and
|
@@ -285,7 +285,7 @@ module Agms
|
|
285
285
|
|
286
286
|
# Validate time fields
|
287
287
|
if @time
|
288
|
-
@time.each do |
|
288
|
+
@time.each do |field_name|
|
289
289
|
if not @fields[field_name][:value] != '' and
|
290
290
|
not /([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])/.match(@fields[field_name][:value])
|
291
291
|
errors += 1
|
@@ -297,8 +297,8 @@ module Agms
|
|
297
297
|
|
298
298
|
# Validate boolean fields
|
299
299
|
if @boolean
|
300
|
-
@boolean.each do |
|
301
|
-
if (
|
300
|
+
@boolean.each do |field_name|
|
301
|
+
if (@fields.has_key?(field_name) and
|
302
302
|
not @fields[field_name][:value] != '' and
|
303
303
|
not @fields[field_name][:value] != true and
|
304
304
|
@fields[field_name][:value] != false and
|
@@ -313,10 +313,10 @@ module Agms
|
|
313
313
|
|
314
314
|
# Validate state code fields
|
315
315
|
if @digit_2
|
316
|
-
@digit_2.each do |
|
316
|
+
@digit_2.each do |field_name|
|
317
317
|
if @fields.has_key?(field_name) and
|
318
318
|
@fields[field_name][:value] != '' and
|
319
|
-
not @digit_2.has_key
|
319
|
+
not @digit_2.has_key? @fields[field_name][:value]
|
320
320
|
errors += 1
|
321
321
|
messages.push("Field #{field_name} has setting " + @fields[field_name][:value] + ', must be valid 2 digit US State code.')
|
322
322
|
end
|
@@ -325,7 +325,7 @@ module Agms
|
|
325
325
|
|
326
326
|
# Validate amount fields
|
327
327
|
if @amount
|
328
|
-
@amount.each do |
|
328
|
+
@amount.each do |field_name|
|
329
329
|
if @fields.key?(field_name) and
|
330
330
|
@fields[field_name][:value] != '' and
|
331
331
|
@fields[field_name][:value] > Configuration.max_amount
|
@@ -352,10 +352,10 @@ module Agms
|
|
352
352
|
validate()
|
353
353
|
|
354
354
|
if @validateErrors > 0
|
355
|
-
raise RequestValidationError
|
355
|
+
raise RequestValidationError, 'Request validation failed with ' + ' '.join(@validateMessages) + '.'
|
356
356
|
end
|
357
357
|
|
358
|
-
@fields.each do |
|
358
|
+
@fields.each do |field_name, settings|
|
359
359
|
if settings[:setting] == :required
|
360
360
|
request[field_name] = ''
|
361
361
|
request[field_name + '_Visible'] = true
|
@@ -107,16 +107,16 @@ module Agms
|
|
107
107
|
end
|
108
108
|
|
109
109
|
# All sales and auths require an amount
|
110
|
-
if (
|
111
|
-
@fields[:TransactionType][:value] == 'auth'
|
110
|
+
if (@fields[:TransactionType][:value] == 'sale' or
|
111
|
+
@fields[:TransactionType][:value] == 'auth')
|
112
112
|
@required.push(:Amount)
|
113
113
|
end
|
114
114
|
|
115
115
|
# Captures, refunds, voids, updates, adjustments need a Transaction ID
|
116
|
-
if (
|
116
|
+
if (@fields[:TransactionType][:value] == 'capture' or
|
117
117
|
@fields[:TransactionType][:value] == 'refund' or
|
118
118
|
@fields[:TransactionType][:value] == 'void' or
|
119
|
-
@fields[:TransactionType][:value] == 'adjustment'
|
119
|
+
@fields[:TransactionType][:value] == 'adjustment')
|
120
120
|
@required.push(:TransactionID)
|
121
121
|
end
|
122
122
|
|
@@ -126,8 +126,8 @@ module Agms
|
|
126
126
|
end
|
127
127
|
|
128
128
|
# All safe updates and deletes require a safe id
|
129
|
-
if (
|
130
|
-
@fields[:SAFE_Action][:value] == 'delete'
|
129
|
+
if (@fields[:SAFE_Action][:value] == 'update' or
|
130
|
+
@fields[:SAFE_Action][:value] == 'delete')
|
131
131
|
@required.push(:SAFE_ID)
|
132
132
|
end
|
133
133
|
|
@@ -139,17 +139,17 @@ module Agms
|
|
139
139
|
@required.push(:CheckName)
|
140
140
|
@required.push(:CheckABA)
|
141
141
|
@required.push(:CheckAccount)
|
142
|
-
if (
|
143
|
-
@fields[:TransactionType][:value] == 'auth'
|
142
|
+
if (@fields[:TransactionType][:value] == 'sale' or
|
143
|
+
@fields[:TransactionType][:value] == 'auth')
|
144
144
|
@required.push(:SecCode)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
else
|
148
148
|
# Credit card transaction
|
149
149
|
# If no SAFE ID and its a sale or auth
|
150
|
-
if (
|
151
|
-
(
|
152
|
-
@fields[:TransactionType][:value] == 'auth'
|
150
|
+
if (@fields[:SAFE_ID][:value] == '' and
|
151
|
+
(@fields[:TransactionType][:value] == 'sale' or
|
152
|
+
@fields[:TransactionType][:value] == 'auth'))
|
153
153
|
# If no Safe ID we need the card info
|
154
154
|
# If no MagData then we need keyed info
|
155
155
|
if @fields[:MagData][:value] == ''
|
@@ -167,23 +167,23 @@ module Agms
|
|
167
167
|
messages = error_array['messages'];
|
168
168
|
|
169
169
|
# ExpDate MMYY
|
170
|
-
if (
|
171
|
-
(
|
172
|
-
not /(0[1-9]|1[0-2])([0-9][0-9])/.match(@fields[:CCExpDate][:value])
|
170
|
+
if (@fields[:CCExpDate][:value] != '' and
|
171
|
+
(@fields[:CCExpDate][:value].length != 4 or
|
172
|
+
not /(0[1-9]|1[0-2])([0-9][0-9])/.match(@fields[:CCExpDate][:value])))
|
173
173
|
errors += 1
|
174
174
|
messages.push('CCExpDate (credit card expiration date) must be MMYY.')
|
175
175
|
end
|
176
176
|
|
177
177
|
# CCNumber length
|
178
|
-
if (
|
178
|
+
if (@fields[:CCNumber][:value] != '' and
|
179
179
|
@fields[:CCNumber][:value].length != 16 and
|
180
|
-
@fields[:CCNumber][:value].length != 15
|
180
|
+
@fields[:CCNumber][:value].length != 15)
|
181
181
|
errors += 1
|
182
182
|
messages.push('CCNumber (credit card number) must be 15-16 digits long.')
|
183
183
|
end
|
184
184
|
|
185
185
|
# ABA length
|
186
|
-
if
|
186
|
+
if (@fields[:CheckABA][:value] != '' and
|
187
187
|
@fields[:CheckABA][:value].length != 9)
|
188
188
|
errors += 1
|
189
189
|
messages.push('CheckABA (routing number) must be 9 digits long.')
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Agms
|
2
|
-
|
3
|
-
|
2
|
+
class TransactionRequest < Request
|
3
|
+
# A class representing AGMS Transaction Request objects.
|
4
4
|
|
5
5
|
alias AgmsAutoValidate autoValidate
|
6
6
|
|
7
7
|
def initialize(op)
|
8
|
-
|
9
|
-
|
8
|
+
super(op)
|
9
|
+
@fields = {
|
10
10
|
:TransactionType => {:setting => '', :value => ''},
|
11
11
|
:PaymentType => {:setting => '', :value => 'creditcard'},
|
12
12
|
:Amount => {:setting => '', :value => ''}, # Required for sale or auth
|
@@ -79,14 +79,14 @@ module Agms
|
|
79
79
|
@numeric = %w(Amount Tax Shipping ProcessorID TransactionID CheckABA CheckAccount CCNumber CCExpDate)
|
80
80
|
|
81
81
|
@enums = {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
82
|
+
:TransactionType => %w(sale auth safe\ only capture void refund update adjustment),
|
83
|
+
:SAFE_Action => %w(add_safe update_safe delete_safe),
|
84
|
+
:PaymentType => %w(creditcard check),
|
85
|
+
:SecCode => %w(PPD WEB TEL CCD),
|
86
|
+
:AccountHolderType => %w(business personal),
|
87
|
+
:AccountType => %w(checking savings),
|
88
|
+
:MagHardware => %w(MAGTEK IDTECH),
|
89
|
+
:Shipping_Carrier => %w(ups fedex dhl usps UPS Fedex DHL USPS),
|
90
90
|
}
|
91
91
|
|
92
92
|
@digit_2 = %w(State ShippingState)
|
@@ -97,74 +97,74 @@ module Agms
|
|
97
97
|
@mapping[:shipping_tracking_number] = :Tracking_Number
|
98
98
|
@mapping[:shipping_carrier] = :Shipping_Carrier
|
99
99
|
|
100
|
-
|
100
|
+
end
|
101
101
|
|
102
|
-
|
103
|
-
|
102
|
+
def validate
|
103
|
+
@required = Array.new
|
104
104
|
|
105
105
|
# Unless this is a safe action only request, require a transaction type
|
106
106
|
if @fields[:SAFE_Action][:value] == ''
|
107
|
-
|
107
|
+
@required.push(:TransactionType)
|
108
108
|
end
|
109
109
|
|
110
110
|
# If no transaction type, require a Safe Action
|
111
111
|
if @fields[:TransactionType][:value] == ''
|
112
|
-
|
112
|
+
@required.push(:SAFE_Action)
|
113
113
|
end
|
114
114
|
|
115
115
|
# All sales and auths require an amount
|
116
|
-
if (
|
117
|
-
@fields[:TransactionType][:value] == 'auth'
|
118
|
-
|
116
|
+
if (@fields[:TransactionType][:value] == 'sale' or
|
117
|
+
@fields[:TransactionType][:value] == 'auth')
|
118
|
+
@required.push(:Amount)
|
119
119
|
end
|
120
120
|
|
121
121
|
# Captures, refunds, voids, updates, adjustments need a Transaction ID
|
122
|
-
if (
|
122
|
+
if (@fields[:TransactionType][:value] == 'capture' or
|
123
123
|
@fields[:TransactionType][:value] == 'refund' or
|
124
124
|
@fields[:TransactionType][:value] == 'void' or
|
125
|
-
@fields[:TransactionType][:value] == 'adjustment'
|
126
|
-
|
125
|
+
@fields[:TransactionType][:value] == 'adjustment')
|
126
|
+
@required.push(:TransactionID)
|
127
127
|
end
|
128
128
|
|
129
129
|
# Require TipAmount for Tip Adjustment transactions
|
130
130
|
if @fields[:TransactionType][:value] == 'adjustment'
|
131
|
-
|
131
|
+
@required.push(:TipAmount)
|
132
132
|
end
|
133
133
|
|
134
134
|
# All safe updates and deletes require a safe id
|
135
|
-
if (
|
136
|
-
@fields[:SAFE_Action][:value] == 'delete'
|
137
|
-
|
135
|
+
if (@fields[:SAFE_Action][:value] == 'update' or
|
136
|
+
@fields[:SAFE_Action][:value] == 'delete')
|
137
|
+
@required.push(:SAFE_ID)
|
138
138
|
end
|
139
139
|
|
140
140
|
|
141
141
|
if @fields[:PaymentType][:value] == 'check'
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
end
|
142
|
+
# Cheque transaction
|
143
|
+
if @fields[:SAFE_ID][:value] == ''
|
144
|
+
# If no Safe ID we need all the check info
|
145
|
+
@required.push(:CheckName)
|
146
|
+
@required.push(:CheckABA)
|
147
|
+
@required.push(:CheckAccount)
|
148
|
+
if (@fields[:TransactionType][:value] == 'sale' or
|
149
|
+
@fields[:TransactionType][:value] == 'auth')
|
150
|
+
@required.push(:SecCode)
|
152
151
|
end
|
152
|
+
end
|
153
153
|
else
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
end
|
154
|
+
# Credit card transaction
|
155
|
+
# If no SAFE ID and its a sale or auth
|
156
|
+
if (@fields[:SAFE_ID][:value] == '' and
|
157
|
+
(@fields[:TransactionType][:value] == 'sale' or
|
158
|
+
@fields[:TransactionType][:value] == 'auth'))
|
159
|
+
# If no Safe ID we need the card info
|
160
|
+
# If no MagData then we need keyed info
|
161
|
+
if @fields[:MagData][:value] == ''
|
162
|
+
@required.push(:CCNumber)
|
163
|
+
@required.push(:CCExpDate)
|
164
|
+
else
|
165
|
+
@required.push(:MagHardware)
|
167
166
|
end
|
167
|
+
end
|
168
168
|
end
|
169
169
|
|
170
170
|
error_array = AgmsAutoValidate();
|
@@ -172,23 +172,23 @@ module Agms
|
|
172
172
|
messages = error_array['messages'];
|
173
173
|
|
174
174
|
# ExpDate MMYY
|
175
|
-
if (
|
176
|
-
(
|
177
|
-
|
178
|
-
|
179
|
-
|
175
|
+
if (@fields[:CCExpDate][:value] != '' and
|
176
|
+
(@fields[:CCExpDate][:value].length != 4 or
|
177
|
+
not /(0[1-9]|1[0-2])([0-9][0-9])/.match(@fields[:CCExpDate][:value])))
|
178
|
+
errors += 1
|
179
|
+
messages.push('CCExpDate (credit card expiration date) must be MMYY.')
|
180
180
|
end
|
181
181
|
|
182
182
|
# CCNumber length
|
183
|
-
if (
|
183
|
+
if (@fields[:CCNumber][:value] != '' and
|
184
184
|
@fields[:CCNumber][:value].length != 16 and
|
185
|
-
@fields[:CCNumber][:value].length != 15
|
186
|
-
|
187
|
-
|
185
|
+
@fields[:CCNumber][:value].length != 15)
|
186
|
+
errors += 1
|
187
|
+
messages.push('CCNumber (credit card number) must be 15-16 digits long.')
|
188
188
|
end
|
189
189
|
|
190
190
|
# ABA length
|
191
|
-
if
|
191
|
+
if (@fields[:CheckABA][:value] != '' and
|
192
192
|
@fields[:CheckABA][:value].length != 9)
|
193
193
|
errors += 1
|
194
194
|
messages.push('CheckABA (routing number) must be 9 digits long.')
|
@@ -203,15 +203,15 @@ module Agms
|
|
203
203
|
print "Request validation failed with #{messages.join(' ')}"
|
204
204
|
raise RequestValidationError, "Request validation failed with #{messages.join(' ')}."
|
205
205
|
end
|
206
|
-
|
207
|
-
end
|
208
206
|
|
209
|
-
|
210
|
-
return getFieldArray
|
211
|
-
end
|
207
|
+
end
|
212
208
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
209
|
+
def getFields
|
210
|
+
return getFieldArray
|
211
|
+
end
|
212
|
+
|
213
|
+
def getParams(request)
|
214
|
+
return {:objparameters => request}
|
215
|
+
end
|
216
|
+
end
|
217
217
|
end
|
data/lib/agms/transaction.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
module Agms
|
2
2
|
class Transaction < Agms
|
3
|
-
|
4
|
-
|
5
|
-
alias AgmsResetParameters resetParameters
|
6
|
-
alias AgmsSetParameter setParameter
|
7
|
-
alias AgmsDoConnect doConnect
|
3
|
+
# A class representing AGMS Transaction objects.
|
8
4
|
|
9
|
-
|
10
|
-
|
5
|
+
alias AgmsResetParameters resetParameters
|
6
|
+
alias AgmsSetParameter setParameter
|
7
|
+
alias AgmsDoConnect doConnect
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super()
|
11
11
|
@api_url = 'https://gateway.agms.com/roxapi/agms.asmx'
|
12
12
|
@requestObject = 'TransactionRequest'
|
13
13
|
@responseObject = 'TransactionResponse'
|
14
|
-
|
14
|
+
end
|
15
15
|
|
16
16
|
def process(params)
|
17
17
|
@op = 'ProcessTransaction'
|
18
18
|
AgmsResetParameters()
|
19
19
|
params.each do |param, config|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
AgmsSetParameter(param, config)
|
21
|
+
end
|
22
|
+
self.execute()
|
23
|
+
return @response.toArray()
|
24
|
+
end
|
25
25
|
|
26
|
-
|
26
|
+
protected
|
27
27
|
def execute
|
28
28
|
if @op == 'ProcessTransaction'
|
29
29
|
AgmsDoConnect('ProcessTransaction', @responseObject)
|
@@ -32,5 +32,5 @@ module Agms
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
end
|
36
36
|
end
|
data/lib/agms/version.rb
CHANGED