nihaopay-ruby 0.1.1 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 793d37f1e49e2b37efecb06a13c62cac1e2ddacf
4
- data.tar.gz: 7cbd9cde59ba17ce779fc907e640d9181fa40372
3
+ metadata.gz: 6e27c0c50ef8f7cec23c8f238997b05a684e3112
4
+ data.tar.gz: 49ae05f6f7d2c446ff854fe3bd038ea7f6546568
5
5
  SHA512:
6
- metadata.gz: 21b972bb2b50c3c762318dddc4031c8e86fb37bfa9047f0e8a2682b3fff02c9c2af597634fde833e1dda50cde933a0bea9bc84014759006633b02ffec195adce
7
- data.tar.gz: 00947d8dbe1f6277928fc7b3ffcc40b00dd8af5222d3ae9f3cdade7aeb1db4ece12485b729e34015a5dfde2d1d7b00c3e52fa636af589c2c14263a5a6869cfa3
6
+ metadata.gz: e2db81aac7112fa455519986ff3abb16ada295a9029468d6279be5de21b83b963721c0da77bcc4de26e6d6f0f60e57458ba789ab7656a828ae6fa550c473b66f
7
+ data.tar.gz: 1d178cb769e8462af6f0d4ccd7b85f6287e0608e480c18d099925f5823a017508a22e4a36e399fd562d86772504c2e48ce88049a8d89ad37e90074a33f9e5cec
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.0
4
+
5
+ * API Change: Time should be returned as a Ruby time object (@JagdeepSingh)
6
+
3
7
  ## 0.1.1
4
8
 
5
9
  * Bug Fix: Add time to Nihaopay response if not present (@JagdeepSingh)
data/README.md CHANGED
@@ -146,7 +146,7 @@ express_pay.reference # => "3461fcc31aec471780ad1a4dc6111947"
146
146
  express_pay.currency # => "JPY"
147
147
  express_pay.amount # => 1000
148
148
  express_pay.captured # => false
149
- express_pay.time # => "2017-01-17T17:51:00+0900"
149
+ express_pay.time # => 2017-01-18 12:08:42 +0900
150
150
  ```
151
151
 
152
152
  Other methods available are `note` and `time`.
@@ -180,7 +180,7 @@ captured.transaction_id # => "20160718111604002633"
180
180
  captured.status # => "success"
181
181
  captured.captured # => true
182
182
  captured.capture_transaction_id # => "20160718111529002632" (id of the transaction that was captured)
183
- captured.time # => "2017-01-17T17:51:00+0900"
183
+ captured.time # => 2017-01-18 12:08:42 +0900
184
184
  ```
185
185
 
186
186
  If you want to capture a partial amount, you can do:
@@ -201,7 +201,7 @@ released.transaction_id # => "20160718111604002633"
201
201
  released.status # => "success"
202
202
  released.released # => true
203
203
  released.release_transaction_id # => "20160718111529002632" (id of the transaction that was released)
204
- released.time # => "2017-01-17T17:51:00+0900"
204
+ released.time # => 2017-01-18 12:08:42 +0900
205
205
  ```
206
206
 
207
207
  #### Cancel a transaction
@@ -212,7 +212,7 @@ cancelled.transaction_id # => "20160718111604002633"
212
212
  cancelled.status # => "success"
213
213
  cancelled.cancelled # => true
214
214
  cancelled.cancel_transaction_id # => "20160718111529002632" (id of the transaction that was cancelled)
215
- cancelled.time # => "2017-01-17T17:51:00+0900"
215
+ cancelled.time # => 2017-01-18 12:08:42 +0900
216
216
  ```
217
217
 
218
218
  Transactions can only be cancelled before the daily settlement deadline. Transactions cannot be cancelled if a partial or full refund on the transaction has already been issued.
@@ -234,23 +234,27 @@ By default, only 10 transactions are returned at a time. This can be adjusted by
234
234
  transactions = Nihaopay::Transactions::Base.limit(5).fetch
235
235
  ```
236
236
 
237
- To retrieve transactions that were processed after the specified time, you can all `after` with time in *yyyy-mm-ddThh:mm:ssZ* format.
237
+ To retrieve transactions that were processed after the specified time, you can all `after` with `Time` object.
238
238
 
239
239
  ``` ruby
240
- transactions = Nihaopay::Transactions::Base.after('2016-06-01T01:00:00Z').fetch
240
+ yesterday = Time.now - 24 * 60 * 60
241
+ transactions = Nihaopay::Transactions::Base.after(yesterday).fetch
241
242
  ```
242
243
 
243
244
  Similarly, you can fetch the transactions that were processed before the specified time.
244
245
 
245
246
  ``` ruby
246
- transactions = Nihaopay::Transactions::Base.before('2016-06-01T01:00:00Z').fetch
247
+ yesterday = Time.now - 24 * 60 * 60
248
+ transactions = Nihaopay::Transactions::Base.before(yesterday).fetch
247
249
  ```
248
250
 
249
251
  You can chain methods to use multiple options:
250
252
 
251
253
  ``` ruby
252
- transactions = Nihaopay::Transactions::Base.before('2016-07-01T01:00:00Z')
253
- .after('2016-06-01T01:00:00Z')
254
+ yesterday = Time.now - 24 * 60 * 60
255
+ week_ago = Time.now - 7 * 24 * 60 * 60
256
+ transactions = Nihaopay::Transactions::Base.before(yesterday)
257
+ .after(week_ago)
254
258
  .limit(5).fetch
255
259
  ```
256
260
 
@@ -259,8 +263,10 @@ OR
259
263
  you can pass the options to `fetch`:
260
264
 
261
265
  ``` ruby
262
- transactions = Nihaopay::Transactions::Base.fetch(before: '2016-07-01T01:00:00Z',
263
- after: '2016-06-01T01:00:00Z',
266
+ yesterday = Time.now - 24 * 60 * 60
267
+ week_ago = Time.now - 7 * 24 * 60 * 60
268
+ transactions = Nihaopay::Transactions::Base.fetch(before: yesterday,
269
+ after: week_ago,
264
270
  limit: 5)
265
271
  ```
266
272
 
@@ -289,7 +295,7 @@ refunded.transaction_id # => "20160718111604002633"
289
295
  refunded.status # => "success"
290
296
  refunded.refunded # => true
291
297
  refunded.refund_transaction_id # => "20160718111529002632" (id of the transaction that was refunded)
292
- refunded.time # => "2017-01-17T17:51:00+0900"
298
+ refunded.time # => 2017-01-18 12:08:42 +0900
293
299
  ```
294
300
 
295
301
  You can pass a `reason` when refunding a transaction:
@@ -1,5 +1,7 @@
1
1
  module Nihaopay
2
2
  module Queryable
3
+ TIME_FORMAT = '%Y-%m-%dT%H:%M:%S%z'.freeze
4
+
3
5
  def self.included(base)
4
6
  base.extend(ClassMethods)
5
7
  end
@@ -14,8 +16,8 @@ module Nihaopay
14
16
  end
15
17
 
16
18
  def fetch(options = {})
17
- options[:starting_after] = options.delete(:after) if options[:after]
18
- options[:ending_before] = options.delete(:before) if options[:before]
19
+ options[:starting_after] = options.delete(:after).strftime(TIME_FORMAT) if options[:after]
20
+ options[:ending_before] = options.delete(:before).strftime(TIME_FORMAT) if options[:before]
19
21
  q.fetch(options)
20
22
  end
21
23
 
@@ -24,11 +26,11 @@ module Nihaopay
24
26
  end
25
27
 
26
28
  def before(time)
27
- q.before(time)
29
+ q.before(time.strftime(TIME_FORMAT))
28
30
  end
29
31
 
30
32
  def after(time)
31
- q.after(time)
33
+ q.after(time.strftime(TIME_FORMAT))
32
34
  end
33
35
 
34
36
  private
@@ -4,8 +4,6 @@ module Nihaopay
4
4
  include ::Nihaopay::Api
5
5
  include ::Nihaopay::Queryable
6
6
 
7
- TIME_FORMAT = '%Y-%m-%dT%H:%M:%S%z'.freeze
8
-
9
7
  attr_accessor :token, :transaction_id, :type, :status
10
8
  attr_accessor :captured, :reference, :currency, :amount, :note, :time
11
9
 
@@ -57,7 +55,7 @@ module Nihaopay
57
55
  options = Nihaopay::HashUtil.symbolize_keys(options)
58
56
  attributes = Nihaopay::HashUtil.slice(options, *valid_attributes)
59
57
  attributes[:token] ||= merchant_token
60
- attributes[:time] ||= Time.now.strftime(TIME_FORMAT)
58
+ attributes[:time] = attributes[:time] ? Time.parse(attributes[:time]) : Time.now
61
59
  response_keys_map.each { |k, v| attributes[v] = options[k] }
62
60
  new(attributes)
63
61
  end
@@ -1,3 +1,3 @@
1
1
  module Nihaopay
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -65,14 +65,14 @@ describe Nihaopay::Queryable do
65
65
  let(:q) { Nihaopay::Query.new }
66
66
 
67
67
  context 'when :after present in options' do
68
- let(:options) { { after: '2016-06-01T01:00:00Z', limit: 5 } }
69
- it { expect(q).to receive(:fetch).with(starting_after: '2016-06-01T01:00:00Z', limit: 5) }
68
+ let(:options) { { after: Time.parse('2016-06-01T01:00:00Z'), limit: 5 } }
69
+ it { expect(q).to receive(:fetch).with(starting_after: '2016-06-01T01:00:00+0000', limit: 5) }
70
70
  after { Nihaopay::Transactions::Base.fetch(options) }
71
71
  end
72
72
 
73
73
  context 'when :before present in options' do
74
- let(:options) { { before: '2016-06-01T01:00:00Z', limit: 5 } }
75
- it { expect(q).to receive(:fetch).with(ending_before: '2016-06-01T01:00:00Z', limit: 5) }
74
+ let(:options) { { before: Time.parse('2016-06-01T01:00:00Z'), limit: 5 } }
75
+ it { expect(q).to receive(:fetch).with(ending_before: '2016-06-01T01:00:00+0000', limit: 5) }
76
76
  after { Nihaopay::Transactions::Base.fetch(options) }
77
77
  end
78
78
 
@@ -142,7 +142,7 @@ describe Nihaopay::Transactions::Base do
142
142
  it { expect(subject.transaction_id).to eq '123456' }
143
143
  it { expect(subject.token).to eq 'merchanttoken2' }
144
144
  it { expect(subject.captured).to be true }
145
- it { expect(subject.time).to eq '2016-06-01T01:00:00Z' }
145
+ it { expect(subject.time).to eq Time.parse('2016-06-01T01:00:00Z') }
146
146
  end
147
147
 
148
148
  context 'with options with string keys' do
@@ -176,9 +176,10 @@ describe Nihaopay::Transactions::Base do
176
176
  opts.delete(:time)
177
177
  opts
178
178
  end
179
- before { allow(Time).to receive_message_chain(:now, :strftime) { '2017-01-17T16:00:00+0900' } }
179
+ let!(:now) { Time.now }
180
+ before { allow(Time).to receive(:now) { now } }
180
181
  subject { described_class.build(options) }
181
- it { expect(subject.time).to eq '2017-01-17T16:00:00+0900' }
182
+ it { expect(subject.time).to eq now }
182
183
  end
183
184
  end
184
185
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nihaopay-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JagdeepSingh
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-17 00:00:00.000000000 Z
12
+ date: 2017-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty