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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4782fb49b793badc095bdf9acdaa35986031dabc
4
- data.tar.gz: ee000b2ae92a4a05b5e346ec6fcf3a83c06f1f07
3
+ metadata.gz: 8080d049a1f8aca2371ce07c68fbc083ee47428b
4
+ data.tar.gz: adc5095ae85b88ebd911e78e7e8ed3757d812f90
5
5
  SHA512:
6
- metadata.gz: fa12d86c48824f7eda942471835f5d7694e94d89c9a6587b1bc759309aa04ae481175df1fd2e575fd8f62b1573c234e139632aa2219a05ec0804cc2eb4ffd9bd
7
- data.tar.gz: 29f88adb3311a7c7ee1f7401a095457fbaed8b9b3c77f9f481ead4e1e4e4914ab02a0109fd4418188cabfd0c788a7736f32d7550cb43226dbcab78762baf507d
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 it will attempt to load it's XML add-ons by default If Nokogiri or Ox 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.
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 your XML libs load first or just manually load it after the fact.
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
- register_token_request: {
99
- order_id: '50',
100
- account_number: '4457119922390123'
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(:register_token_response, :litle_token) # => "1111222233330123"
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 abreviated to the following:
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
- order_id: '50',
118
- account_number: '4457119922390123'
117
+ 'orderId' => '50',
118
+ 'accountNumber' => '4457119922390123'
119
119
  }
120
120
 
121
- response = VantivLite.register_token(params).dig(:litle_token) # => "1111222233330123"
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
- register_token_request: {
143
- order_id: '50',
144
- account_number: '4457119922390123'
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
- order_id: '50',
154
- account_number: '4457119922390123'
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
- register_token_request: {
167
- id: 'abcdef',
168
- order_id: '50',
169
- account_number: '4457119922390123'
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=VantiveLite) 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:
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
 
@@ -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.new(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 = "vaniv_#{k}"
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)
@@ -32,8 +32,14 @@ module VantivLite
32
32
  end
33
33
  end
34
34
 
35
- def self.build(&blk)
36
- Config::Builder.(&blk)
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
@@ -6,13 +6,13 @@ require 'vantiv_lite/xml'
6
6
 
7
7
  module VantivLite
8
8
  TRANSACTIONS = {
9
- auth_reversal: :auth_reversal,
10
- authorization: :authorization,
11
- capture: :capture,
12
- credit: :credit,
13
- register_token: :register_token_request,
14
- sale: :sale,
15
- void: :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, request_name|
41
- define_method(name) { |hash| call({ request_name => hash }, :"#{name}_response") }
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'] ||= SecureRandom.hex(12)
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(lower_camelize_keys(request_hash)))
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'
@@ -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 = :litle_online_response
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[:message] unless root_hash[:response] == '0'
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
@@ -3,7 +3,7 @@
3
3
  module VantivLite
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 1
6
+ TINY = 6
7
7
  VERSION = [MAJOR, MINOR, TINY].join('.').freeze
8
8
 
9
9
  def self.version
@@ -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.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: 2018-05-16 00:00:00.000000000 Z
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.0'
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.0'
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.8'
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.8'
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.9'
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.9'
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: '10.0'
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: '10.0'
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.4.5.4
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