vantiv_lite 0.1.1 → 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/README.md +24 -22
- data/lib/vantiv_lite.rb +4 -3
- data/lib/vantiv_lite/config.rb +8 -2
- data/lib/vantiv_lite/request.rb +14 -22
- data/lib/vantiv_lite/response.rb +2 -7
- data/lib/vantiv_lite/version.rb +1 -1
- data/lib/vantiv_lite/xml.rb +0 -7
- data/lib/vantiv_lite/xml/serializer.rb +3 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8080d049a1f8aca2371ce07c68fbc083ee47428b
|
4
|
+
data.tar.gz: adc5095ae85b88ebd911e78e7e8ed3757d812f90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f166190f82ed119ed98d2be5a61fd78af51694b93f39c28b55e8f2caf1ae5513bd47e07cf43b7acafb3d9704076f3bb64d6bd1a76a763dc45e324a52e82bc72
|
7
|
+
data.tar.gz: 1b19fa30722127f0b2b5350730b0b59bde2b20829d717840e2778c9d45a87445157291f265dc6bc906fc4b18ec82b4bb62762b7c769d498fc0cb2cf17185ca51
|
data/README.md
CHANGED
@@ -19,9 +19,9 @@ Pretty standard gem stuff.
|
|
19
19
|
|
20
20
|
$ gem install vantiv_lite
|
21
21
|
|
22
|
-
When using [Bundler](https://bundler.io) or requiring this library in general, it's important to note that
|
22
|
+
When using [Bundler](https://bundler.io) or requiring this library in general, it's important to note that this gem will attempt to load its XML add-ons by default if `Ox` or `Nokogiri` is already defined, it will use them in that order. Otherwise, it will use the default of `REXML`. The only consideration is that `REXML` will get required if neither optional library is already required.
|
23
23
|
|
24
|
-
So, ensure
|
24
|
+
So, ensure you load your project's XML libs (if you're using them) first.
|
25
25
|
|
26
26
|
## Configuration
|
27
27
|
|
@@ -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) # => #
|
|
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
|
-
For many simple transactions the `*_request` and `*_response` keys get a little tedious. So, this can be
|
113
|
+
For many simple transactions the `*_request` and `*_response` keys get a little tedious. So, this can be abbreviated 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) # => # |
|
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
|
```
|
@@ -197,11 +195,15 @@ Valid environments are:
|
|
197
195
|
|
198
196
|
This configures the API url. At the moment, that's really all it does.
|
199
197
|
|
198
|
+
## Reports
|
199
|
+
|
200
|
+
Need access to reports? Turns out, there's a [separate gem for that](https://github.com/binarypaladin/vantiv_sftp_reports).
|
201
|
+
|
200
202
|
## Contributing
|
201
203
|
|
202
204
|
### Issue Guidelines
|
203
205
|
|
204
|
-
GitHub issues are for bugs, not support. As of right now, there is no official support for this gem. You can try reaching out to the author, [Joshua Hansen](mailto:joshua@epicbanality.com?subject=
|
206
|
+
GitHub issues are for bugs, not support. As of right now, there is no official support for this gem. You can try reaching out to the author, [Joshua Hansen](mailto:joshua@epicbanality.com?subject=VantivLite) if you're really stuck, but there's a pretty high chance that won't go anywhere at the moment or you'll get a response like this:
|
205
207
|
|
206
208
|
> Hi. I'm super busy. It's nothing personal. Check the README first if you haven't already. If you don 't find your answer there, it's time to start reading the source. Have fun! Let me know if I screwed something up.
|
207
209
|
|
data/lib/vantiv_lite.rb
CHANGED
@@ -8,15 +8,16 @@ module VantivLite
|
|
8
8
|
attr_reader :default_config, :default_request
|
9
9
|
|
10
10
|
def configure(config = env_config, &blk)
|
11
|
-
@default_config = block_given? ? Config.build(&blk) : Config.
|
11
|
+
@default_config = block_given? ? Config.build(&blk) : Config.with_obj(config)
|
12
12
|
@default_request = Request.new(@default_config)
|
13
13
|
end
|
14
14
|
|
15
15
|
def env_config
|
16
|
-
Config::OPTS.each_with_object({}) do |k, h|
|
17
|
-
env_key = "
|
16
|
+
opts = Config::OPTS.each_with_object({}) do |k, h|
|
17
|
+
env_key = "vantiv_#{k}"
|
18
18
|
h[k] = ENV[env_key] if ENV.key?(env_key)
|
19
19
|
end
|
20
|
+
Config.new(opts)
|
20
21
|
end
|
21
22
|
|
22
23
|
def request(request_hash)
|
data/lib/vantiv_lite/config.rb
CHANGED
@@ -32,8 +32,14 @@ module VantivLite
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
class << self
|
36
|
+
def build(&blk)
|
37
|
+
Config::Builder.(&blk)
|
38
|
+
end
|
39
|
+
|
40
|
+
def with_obj(config)
|
41
|
+
config.is_a?(self) ? config : new(config)
|
42
|
+
end
|
37
43
|
end
|
38
44
|
|
39
45
|
attr_reader :proxy_uri, :sandbox, :uri
|
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
|
@@ -34,11 +34,13 @@ module VantivLite
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def post(xml)
|
37
|
-
http.start { |h| h.request(post_request(xml)) }
|
37
|
+
http.dup.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
|
@@ -50,7 +52,7 @@ module VantivLite
|
|
50
52
|
end
|
51
53
|
|
52
54
|
def default_attributes_with(hash)
|
53
|
-
hash['id'] ||=
|
55
|
+
hash['id'] ||= '0'
|
54
56
|
hash['reportGroup'] ||= config.report_group
|
55
57
|
hash
|
56
58
|
end
|
@@ -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
|
@@ -3,13 +3,15 @@
|
|
3
3
|
module VantivLite
|
4
4
|
module XML
|
5
5
|
module Serializer
|
6
|
-
ATTRIBUTES = %w[id merchantId reportGroup version xmlns].freeze
|
6
|
+
ATTRIBUTES = %w[customerId id merchantId reportGroup version xmlns].freeze
|
7
7
|
|
8
8
|
@@type_coercions = {}
|
9
9
|
def self.coerce(type, obj = nil, &blk)
|
10
10
|
raise TypeError, '`type` must be a `Class`' unless type.is_a?(Class)
|
11
|
+
|
11
12
|
obj ||= blk
|
12
13
|
raise TypeError, '`obj` must respond to `call`' unless obj.respond_to?(:call)
|
14
|
+
|
13
15
|
@@type_coercions[type] = obj
|
14
16
|
end
|
15
17
|
|
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.6
|
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:
|
12
|
+
date: 2020-07-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -31,56 +31,56 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '5
|
34
|
+
version: '5'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '5
|
41
|
+
version: '5'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: nokogiri
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '1
|
48
|
+
version: '1'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '1
|
55
|
+
version: '1'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: ox
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '2
|
62
|
+
version: '2'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '2
|
69
|
+
version: '2'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rake
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
76
|
+
version: '12.3'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
83
|
+
version: '12.3'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: rubocop
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.6.14
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: A Simplified Vanitiv/WorldPay (LitleOnline) API Library
|