vantiv_lite 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -18
- data/lib/vantiv_lite/request.rb +12 -20
- data/lib/vantiv_lite/response.rb +2 -7
- data/lib/vantiv_lite/version.rb +1 -1
- data/lib/vantiv_lite/xml.rb +0 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c91c1fa1527e5eaa1e94d100c3e3bf4e56b806c
|
4
|
+
data.tar.gz: 1bd58157041ce8fb7a6215587f8129bf9f07d9e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1e0c35fb1d8cdd08f16da4ae9ff1a12db86344ec6ecb0f5b431897fd65674f02523e3bb9bb41c2d7aeb233303ee2b99e5bab2ca7178802e36f35af732631e56
|
7
|
+
data.tar.gz: f6ba9b13570f4395d3fb40c3f69025d94a5ec75bfc550cc86eaf9daa3641266e3df4e80d3233d9517f32eb7de2d74d690fd85e83a03a26d5f32bb43d1e07a5da
|
data/README.md
CHANGED
@@ -95,9 +95,9 @@ A basic request can be made using `VantivLite.request`. This uses the global con
|
|
95
95
|
|
96
96
|
```ruby
|
97
97
|
params = {
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
'registerTokenRequest' => {
|
99
|
+
'orderId' => '50',
|
100
|
+
'accountNumber' => '4457119922390123'
|
101
101
|
}
|
102
102
|
}
|
103
103
|
|
@@ -107,18 +107,18 @@ response = VantivLite.request(params) # => #<VantivLite::Response>
|
|
107
107
|
This will return a `VantivLite::Response` which itself operates much like a hash:
|
108
108
|
|
109
109
|
```ruby
|
110
|
-
response.dig(
|
110
|
+
response.dig('registerTokenResponse', 'litleToken') # => "1111222233330123"
|
111
111
|
```
|
112
112
|
|
113
113
|
For many simple transactions the `*_request` and `*_response` keys get a little tedious. So, this can be abreviated to the following:
|
114
114
|
|
115
115
|
```ruby
|
116
116
|
params = {
|
117
|
-
|
118
|
-
|
117
|
+
'orderId' => '50',
|
118
|
+
'accountNumber' => '4457119922390123'
|
119
119
|
}
|
120
120
|
|
121
|
-
response = VantivLite.register_token(params).dig(
|
121
|
+
response = VantivLite.register_token(params).dig('litleToken') # => "1111222233330123"
|
122
122
|
```
|
123
123
|
|
124
124
|
There are shortcuts for the requests:
|
@@ -131,17 +131,15 @@ There are shortcuts for the requests:
|
|
131
131
|
* `sale`
|
132
132
|
* `void`
|
133
133
|
|
134
|
-
Note that the only transformation that is done is underscoring and symbolizing keys. No other mapping is done.
|
135
|
-
|
136
134
|
### Requests With Multiple Configurations
|
137
135
|
|
138
136
|
`VantiveLite.request` (and the various convenience versions) simply uses `Vantiv.default_request` which is just an instance of `VantivLite::Request`. The request object itself can be used similarly with the methods by invoking `#call`:
|
139
137
|
|
140
138
|
```ruby
|
141
139
|
params = {
|
142
|
-
|
143
|
-
|
144
|
-
|
140
|
+
'registerTokenRequest' => {
|
141
|
+
'orderId' => '50',
|
142
|
+
'accountNumber' => '4457119922390123'
|
145
143
|
}
|
146
144
|
}
|
147
145
|
|
@@ -150,8 +148,8 @@ response = VantivLite::Request.new(custom_config).(params) # => #<VantivLite::Re
|
|
150
148
|
# Shortcut methods also work:
|
151
149
|
|
152
150
|
params = {
|
153
|
-
|
154
|
-
|
151
|
+
'orderId' => '50',
|
152
|
+
'accountNumber' => '4457119922390123'
|
155
153
|
}
|
156
154
|
|
157
155
|
response = VantivLite::Request.new(custom_config).register_token(params)
|
@@ -163,10 +161,10 @@ Obviously, XML doesn't map nice and neat to a hash and vice-versa. However, Vant
|
|
163
161
|
|
164
162
|
```ruby
|
165
163
|
params = {
|
166
|
-
|
167
|
-
id
|
168
|
-
|
169
|
-
|
164
|
+
'registerTokenRequest' => {
|
165
|
+
'id' => 'abcdef',
|
166
|
+
'orderId' => '50',
|
167
|
+
'accountNumber' => '4457119922390123'
|
170
168
|
}
|
171
169
|
}
|
172
170
|
```
|
data/lib/vantiv_lite/request.rb
CHANGED
@@ -6,13 +6,13 @@ require 'vantiv_lite/xml'
|
|
6
6
|
|
7
7
|
module VantivLite
|
8
8
|
TRANSACTIONS = {
|
9
|
-
auth_reversal:
|
10
|
-
authorization:
|
11
|
-
capture:
|
12
|
-
credit:
|
13
|
-
register_token:
|
14
|
-
sale:
|
15
|
-
void:
|
9
|
+
auth_reversal: 'authReversal',
|
10
|
+
authorization: 'authorization',
|
11
|
+
capture: 'capture',
|
12
|
+
credit: 'credit',
|
13
|
+
register_token: 'registerTokenRequest',
|
14
|
+
sale: 'sale',
|
15
|
+
void: 'void'
|
16
16
|
}.freeze
|
17
17
|
|
18
18
|
class Request
|
@@ -37,8 +37,10 @@ module VantivLite
|
|
37
37
|
http.start { |h| h.request(post_request(xml)) }
|
38
38
|
end
|
39
39
|
|
40
|
-
TRANSACTIONS.each do |name,
|
41
|
-
define_method(name)
|
40
|
+
TRANSACTIONS.each do |name, request_key|
|
41
|
+
define_method(name) do |hash|
|
42
|
+
call({ request_key => hash }, "#{request_key.sub(/Request$/, '')}Response")
|
43
|
+
end
|
42
44
|
end
|
43
45
|
|
44
46
|
private
|
@@ -62,7 +64,7 @@ module VantivLite
|
|
62
64
|
'version' => config.version,
|
63
65
|
'merchantId' => config.merchant_id,
|
64
66
|
'authentication' => { 'user' => config.username, 'password' => config.password }
|
65
|
-
}.merge(insert_default_attributes(
|
67
|
+
}.merge(insert_default_attributes(request_hash))
|
66
68
|
}
|
67
69
|
end
|
68
70
|
|
@@ -72,16 +74,6 @@ module VantivLite
|
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
75
|
-
def lower_camelize_keys(hash)
|
76
|
-
XML.transform_keys(hash) do |k|
|
77
|
-
if k.is_a?(String)
|
78
|
-
k
|
79
|
-
else
|
80
|
-
k.to_s.gsub(/_[a-z]/i) { |m| m[1].upcase }.tap { |s| s[0] = s[0].downcase }
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
77
|
def post_request(xml)
|
86
78
|
Net::HTTP::Post.new(config.uri.path).tap do |r|
|
87
79
|
r['Content-Type'] ||= 'text/xml; charset=UTF-8'
|
data/lib/vantiv_lite/response.rb
CHANGED
@@ -5,7 +5,7 @@ require 'vantiv_lite/xml'
|
|
5
5
|
module VantivLite
|
6
6
|
class Response
|
7
7
|
ServerError = Class.new(StandardError)
|
8
|
-
ROOT_KEY =
|
8
|
+
ROOT_KEY = 'litleOnlineResponse'.freeze
|
9
9
|
|
10
10
|
module Refinements
|
11
11
|
[Array, Hash].each do |klass|
|
@@ -59,14 +59,9 @@ module VantivLite
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def response_hash_with(response_hash, dig_keys)
|
62
|
-
response_hash = underscore_symbolize_keys(response_hash)
|
63
62
|
raise ServerError, "missing root :#{ROOT_KEY}" unless (root_hash = response_hash[ROOT_KEY])
|
64
|
-
raise ServerError, root_hash[
|
63
|
+
raise ServerError, root_hash['message'] unless root_hash['response'] == '0'
|
65
64
|
dig_keys.any? ? root_hash.dig(*dig_keys) : root_hash
|
66
65
|
end
|
67
|
-
|
68
|
-
def underscore_symbolize_keys(hash)
|
69
|
-
XML.transform_keys(hash) { |k| k.gsub(/[A-Z]/) { |m| "_#{m.downcase}" }.to_sym }
|
70
|
-
end
|
71
66
|
end
|
72
67
|
end
|
data/lib/vantiv_lite/version.rb
CHANGED
data/lib/vantiv_lite/xml.rb
CHANGED
@@ -24,13 +24,6 @@ module VantivLite
|
|
24
24
|
def serializer_with(name, attributes: Serializer::ATTRIBUTES)
|
25
25
|
const_get(name)::Serializer.new(attributes: attributes)
|
26
26
|
end
|
27
|
-
|
28
|
-
def transform_keys(hash, &blk)
|
29
|
-
return hash unless hash.is_a?(Hash)
|
30
|
-
hash.each_with_object({}) do |(k, obj), h|
|
31
|
-
h[yield(k)] = XML.hash_or_array(obj) { |o| transform_keys(o, &blk) }
|
32
|
-
end
|
33
|
-
end
|
34
27
|
end
|
35
28
|
end
|
36
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vantiv_lite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-05-
|
12
|
+
date: 2018-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|