Module: NakoPay::Subscription
- Defined in:
- lib/nakopay/resources.rb
Class Method Summary collapse
- .auto_paging_each(limit: nil, status: nil) ⇒ Object
- .cancel(id, at_period_end: true, idempotency_key: nil) ⇒ Object
- .list(limit: nil, starting_after: nil, status: nil) ⇒ Object
- .pause(id, token: nil, idempotency_key: nil) ⇒ Object
- .portal(id, idempotency_key: nil) ⇒ Object
- .resume(id, token: nil, idempotency_key: nil) ⇒ Object
- .retrieve(id) ⇒ Object
Class Method Details
.auto_paging_each(limit: nil, status: nil) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/nakopay/resources.rb', line 196 def auto_paging_each(limit: nil, status: nil) return enum_for(:auto_paging_each, limit: limit, status: status) unless block_given? cursor = nil loop do page = list(limit: limit, starting_after: cursor, status: status) page["data"].each { |s| yield s } break unless page["has_more"] cursor = page["next_cursor"] || page["data"].last&.id break unless cursor end end |
.cancel(id, at_period_end: true, idempotency_key: nil) ⇒ Object
176 177 178 |
# File 'lib/nakopay/resources.rb', line 176 def cancel(id, at_period_end: true, idempotency_key: nil) Resource.new(NakoPay.client.request(:post, "/subscriptions-cancel", body: { subscription_id: id, at_period_end: at_period_end }, idempotency_key: idempotency_key)) end |
.list(limit: nil, starting_after: nil, status: nil) ⇒ Object
170 171 172 173 174 |
# File 'lib/nakopay/resources.rb', line 170 def list(limit: nil, starting_after: nil, status: nil) page = NakoPay.client.request(:get, "/subscriptions-list", query: { limit: limit, starting_after: starting_after, status: status }) page["data"] = (page["data"] || []).map { |r| Resource.new(r) } page end |
.pause(id, token: nil, idempotency_key: nil) ⇒ Object
180 181 182 183 184 |
# File 'lib/nakopay/resources.rb', line 180 def pause(id, token: nil, idempotency_key: nil) body = { subscription_id: id } body[:token] = token if token Resource.new(NakoPay.client.request(:post, "/subscriptions-pause", body: body, idempotency_key: idempotency_key)) end |
.portal(id, idempotency_key: nil) ⇒ Object
192 193 194 |
# File 'lib/nakopay/resources.rb', line 192 def portal(id, idempotency_key: nil) Resource.new(NakoPay.client.request(:post, "/subscriptions-portal", body: { subscription_id: id }, idempotency_key: idempotency_key)) end |
.resume(id, token: nil, idempotency_key: nil) ⇒ Object
186 187 188 189 190 |
# File 'lib/nakopay/resources.rb', line 186 def resume(id, token: nil, idempotency_key: nil) body = { subscription_id: id } body[:token] = token if token Resource.new(NakoPay.client.request(:post, "/subscriptions-resume", body: body, idempotency_key: idempotency_key)) end |