Module: NakoPay::Invoice

Defined in:
lib/nakopay/resources.rb

Class Method Summary collapse

Class Method Details

.auto_paging_each(limit: nil, status: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nakopay/resources.rb', line 23

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 { |inv| yield inv }
    break unless page["has_more"]

    cursor = page["next_cursor"] || page["data"].last&.id
    break unless cursor
  end
end

.cancel(id, idempotency_key: nil) ⇒ Object



19
20
21
# File 'lib/nakopay/resources.rb', line 19

def cancel(id, idempotency_key: nil)
  Resource.new(NakoPay.client.request(:post, "/invoices-cancel", body: { id: id }, idempotency_key: idempotency_key))
end

.create(idempotency_key: nil, **params) ⇒ Object



5
6
7
# File 'lib/nakopay/resources.rb', line 5

def create(idempotency_key: nil, **params)
  Resource.new(NakoPay.client.request(:post, "/invoices-create", body: params, idempotency_key: idempotency_key))
end

.list(limit: nil, starting_after: nil, status: nil) ⇒ Object



13
14
15
16
17
# File 'lib/nakopay/resources.rb', line 13

def list(limit: nil, starting_after: nil, status: nil)
  page = NakoPay.client.request(:get, "/invoices-list", query: { limit: limit, starting_after: starting_after, status: status })
  page["data"] = (page["data"] || []).map { |r| Resource.new(r) }
  page
end

.retrieve(id) ⇒ Object



9
10
11
# File 'lib/nakopay/resources.rb', line 9

def retrieve(id)
  Resource.new(NakoPay.client.request(:get, "/invoices-get", query: { id: id }))
end