paymos 1.5.2 → 1.6.1

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.
data/lib/paymos/client.rb CHANGED
@@ -37,7 +37,6 @@ module Paymos
37
37
  @timeout = timeout
38
38
  @max_retries = max_retries
39
39
  @base_delay = base_delay
40
- @refund_transport_is_default = !transport
41
40
  @transport = transport || method(:default_transport)
42
41
  @clock = clock
43
42
  @sleeper = sleeper
@@ -53,7 +52,6 @@ module Paymos
53
52
 
54
53
  def request(method, path, payload: nil, query: '')
55
54
  method = method.to_s.upcase
56
- refund_transport = checked_refund_transport(method, path)
57
55
  body = payload.nil? ? '' : JSON.generate(payload)
58
56
  attempts = 0
59
57
 
@@ -67,9 +65,7 @@ module Paymos
67
65
  'Accept' => 'application/json',
68
66
  'User-Agent' => "paymos-ruby/#{VERSION}"
69
67
  }
70
- response = (refund_transport || @transport).call(
71
- method, "#{@base_url}#{path}#{query}", headers, body.empty? ? nil : body, @timeout
72
- )
68
+ response = @transport.call(method, "#{@base_url}#{path}#{query}", headers, body.empty? ? nil : body, @timeout)
73
69
  rescue IOError, SystemCallError, Timeout::Error, SocketError => e
74
70
  if attempts < @max_retries && SAFE_METHODS.include?(method)
75
71
  wait(attempts, nil)
@@ -83,7 +79,7 @@ module Paymos
83
79
  raise Error, 'Paymos transport returned an invalid response'
84
80
  end
85
81
 
86
- if attempts < @max_retries && retryable_request?(method, path, response.status)
82
+ if attempts < @max_retries && retryable?(method, response.status)
87
83
  wait(attempts, header(response.headers, 'retry-after'))
88
84
  attempts += 1
89
85
  next
@@ -140,24 +136,6 @@ module Paymos
140
136
  headers: response.to_hash.transform_values(&:first))
141
137
  end
142
138
 
143
- def refund_create?(method, path)
144
- method == 'POST' && path == '/v1/refunds'
145
- end
146
-
147
- def checked_refund_transport(method, path)
148
- return nil unless refund_create?(method, path)
149
-
150
- transport = @transport
151
- trusted = Paymos::Client.instance_method(:default_transport).bind(self)
152
- return transport if @refund_transport_is_default && trusted == transport
153
-
154
- raise ConfigurationError, 'Refund creation requires the standard Net::HTTP transport'
155
- end
156
-
157
- def retryable_request?(method, path, status)
158
- !refund_create?(method, path) && retryable?(method, status)
159
- end
160
-
161
139
  def retryable?(method, status)
162
140
  status == 429 || (status >= 500 && SAFE_METHODS.include?(method))
163
141
  end
@@ -466,16 +444,19 @@ module Paymos
466
444
  raise ArgumentError, 'max_pages must be a positive integer' unless max_pages.is_a?(Integer) && max_pages.positive?
467
445
 
468
446
  filters = filters.dup
469
- cursor = filters[:cursor]
447
+ # Every cursor this walk has requested, not only the previous one: a cycle A -> B -> A
448
+ # repeats a position without two equal cursors in a row.
449
+ used = {}
450
+ used[filters[:cursor]] = true unless filters[:cursor].nil?
470
451
  max_pages.times do
471
452
  page = fetch.call(**filters)
472
453
  page.items.each(&block)
473
454
  next_cursor = page.next_cursor
474
455
  return if next_cursor.nil? || next_cursor.to_s.empty?
475
- raise Error, 'Paymos API returned the same pagination cursor twice' if next_cursor == cursor
456
+ raise Error, 'Paymos API returned a pagination cursor this walk already used' if used.key?(next_cursor)
476
457
 
477
- cursor = next_cursor
478
- filters[:cursor] = cursor
458
+ used[next_cursor] = true
459
+ filters[:cursor] = next_cursor
479
460
  end
480
461
  end
481
462
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Paymos
4
- VERSION = '1.5.2'
4
+ VERSION = '1.6.1'
5
5
  end
data/sig/paymos.rbs CHANGED
@@ -31,6 +31,8 @@ module Paymos
31
31
  end
32
32
  class AuthenticationError < ApiError
33
33
  end
34
+ class PermissionError < AuthenticationError
35
+ end
34
36
  class NotFoundError < ApiError
35
37
  end
36
38
  class ConflictError < ApiError
@@ -44,6 +46,28 @@ module Paymos
44
46
  class UnavailableError < ServerError
45
47
  end
46
48
 
49
+ module InvoiceStatus
50
+ AWAITING_CLIENT: "awaiting_client"
51
+ AWAITING_PAYMENT: "awaiting_payment"
52
+ CONFIRMING: "confirming"
53
+ UNDERPAID_WAITING: "underpaid_waiting"
54
+ PAID: "paid"
55
+ PAID_OVER: "paid_over"
56
+ UNDERPAID: "underpaid"
57
+ EXPIRED: "expired"
58
+ CANCELLED: "cancelled"
59
+ end
60
+
61
+ module WithdrawalStatus
62
+ CREATED: "created"
63
+ PENDING_REVIEW: "pending_review"
64
+ SIGNED: "signed"
65
+ CANCELLING: "cancelling"
66
+ COMPLETED: "completed"
67
+ FAILED: "failed"
68
+ CANCELLED: "cancelled"
69
+ end
70
+
47
71
  class Model
48
72
  def []: (String | Symbol name) -> untyped
49
73
  def to_h: () -> Hash[Symbol, untyped]
@@ -96,6 +120,7 @@ module Paymos
96
120
  attr_reader updated_at: Integer
97
121
  attr_reader expires_at: Integer?
98
122
  attr_reader completed_at: Integer?
123
+ attr_reader paid_late_at: Integer?
99
124
  end
100
125
 
101
126
  class InvoiceListItem < Model
@@ -112,6 +137,7 @@ module Paymos
112
137
  attr_reader created_at: Integer
113
138
  attr_reader expires_at: Integer?
114
139
  attr_reader completed_at: Integer?
140
+ attr_reader paid_late_at: Integer?
115
141
  end
116
142
 
117
143
  class Withdrawal < Model
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymos
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paymos Labs
@@ -33,6 +33,7 @@ files:
33
33
  - CHANGELOG.md
34
34
  - LICENSE
35
35
  - README.md
36
+ - conformance/contract.json
36
37
  - lib/paymos.rb
37
38
  - lib/paymos/client.rb
38
39
  - lib/paymos/errors.rb