Class: Cryptopay::Invoices

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptopay/api/invoices.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Invoices

Returns a new instance of Invoices.



8
9
10
# File 'lib/cryptopay/api/invoices.rb', line 8

def initialize(connection)
  @connection = connection
end

Instance Method Details

#commit_recalculation(invoice_id, recalculation_id, _opts = {}) ⇒ InvoiceRecalculationResult

Commit invoice recalculation This endpoint allows you to commit invoice recalculation.

Parameters:

  • invoice_id (String)

    Invoice ID

  • recalculation_id (String)

    Recalculation ID

  • opts (Hash)

    the optional parameters

Returns:



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cryptopay/api/invoices.rb', line 18

def commit_recalculation(invoice_id, recalculation_id, _opts = {})
  path = '/api/invoices/{invoice_id}/recalculations/{recalculation_id}/commit'
  path = path.sub('{invoice_id}', CGI.escape(invoice_id.to_s))
  path = path.sub('{recalculation_id}', CGI.escape(recalculation_id.to_s))

  req = Request.new(
    method: :post,
    path: path
  )

  connection.call(req, return_type: InvoiceRecalculationResult)
end

#create(invoice_params, _opts = {}) ⇒ InvoiceResult

Create an invoice This endpoint allows you to create invoices.

Parameters:

  • invoice_params (InvoiceParams)
  • opts (Hash)

    the optional parameters

Returns:



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cryptopay/api/invoices.rb', line 36

def create(invoice_params, _opts = {})
  path = '/api/invoices'

  req = Request.new(
    method: :post,
    path: path,
    body_params: invoice_params
  )

  connection.call(req, return_type: InvoiceResult)
end

#create_recalculation(invoice_id, invoice_recalculation_params, _opts = {}) ⇒ InvoiceRecalculationResult

Create invoice recalculation This endpoint allows you to recalculate invoices.

Parameters:

  • invoice_id (String)

    Invoice ID

  • invoice_recalculation_params (InvoiceRecalculationParams)
  • opts (Hash)

    the optional parameters

Returns:



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cryptopay/api/invoices.rb', line 54

def create_recalculation(invoice_id, invoice_recalculation_params, _opts = {})
  path = '/api/invoices/{invoice_id}/recalculations'
  path = path.sub('{invoice_id}', CGI.escape(invoice_id.to_s))

  req = Request.new(
    method: :post,
    path: path,
    body_params: invoice_recalculation_params
  )

  connection.call(req, return_type: InvoiceRecalculationResult)
end

#create_refund(invoice_id, invoice_refund_params, _opts = {}) ⇒ InvoiceRefundResult

Create invoice refund This endpoint allows you to create invoice refunds.

Parameters:

  • invoice_id (String)

    Invoice ID

  • invoice_refund_params (InvoiceRefundParams)
  • opts (Hash)

    the optional parameters

Returns:



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cryptopay/api/invoices.rb', line 73

def create_refund(invoice_id, invoice_refund_params, _opts = {})
  path = '/api/invoices/{invoice_id}/refunds'
  path = path.sub('{invoice_id}', CGI.escape(invoice_id.to_s))

  req = Request.new(
    method: :post,
    path: path,
    body_params: invoice_refund_params
  )

  connection.call(req, return_type: InvoiceRefundResult)
end

#list(opts = {}) ⇒ InvoiceListResult

List invoices This endpoint allows you to retrieve a list of all invoices.

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :customer_id (String)

    The internal ID of your customer that the transaction relates to

  • :starting_after (String)

    Pagination parameter. ID to start after

  • :subscription_id (String)

Returns:



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/cryptopay/api/invoices.rb', line 93

def list(opts = {})
  path = '/api/invoices'

  query_params = {}
  query_params[:customer_id] = opts[:customer_id] unless opts[:customer_id].nil?
  query_params[:starting_after] = opts[:starting_after] unless opts[:starting_after].nil?
  query_params[:subscription_id] = opts[:subscription_id] unless opts[:subscription_id].nil?

  req = Request.new(
    method: :get,
    path: path,
    query_params: query_params
  )

  connection.call(req, return_type: InvoiceListResult)
end

#list_refunds(invoice_id, _opts = {}) ⇒ InvoiceRefundListResult

List invoice refunds This endpoint allows you to retrieve a list of a particular invoice refunds.

Parameters:

  • invoice_id (String)

    Invoice ID

  • opts (Hash)

    the optional parameters

Returns:



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/cryptopay/api/invoices.rb', line 115

def list_refunds(invoice_id, _opts = {})
  path = '/api/invoices/{invoice_id}/refunds'
  path = path.sub('{invoice_id}', CGI.escape(invoice_id.to_s))

  req = Request.new(
    method: :get,
    path: path
  )

  connection.call(req, return_type: InvoiceRefundListResult)
end

#retrieve(invoice_id, _opts = {}) ⇒ InvoiceResult

Retrieve an invoice This endpoint allows you to retrieve the invoice details.

Parameters:

  • invoice_id (String)

    Invoice ID

  • opts (Hash)

    the optional parameters

Returns:



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/cryptopay/api/invoices.rb', line 132

def retrieve(invoice_id, _opts = {})
  path = '/api/invoices/{invoice_id}'
  path = path.sub('{invoice_id}', CGI.escape(invoice_id.to_s))

  req = Request.new(
    method: :get,
    path: path
  )

  connection.call(req, return_type: InvoiceResult)
end

#retrieve_by_custom_id(custom_id, _opts = {}) ⇒ InvoiceResult

Retrieve an invoice by custom_id This endpoint allows you to retrieve invoice details by its custom_id.

Parameters:

  • custom_id (String)
  • opts (Hash)

    the optional parameters

Returns:



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/cryptopay/api/invoices.rb', line 149

def retrieve_by_custom_id(custom_id, _opts = {})
  path = '/api/invoices/custom_id/{custom_id}'
  path = path.sub('{custom_id}', CGI.escape(custom_id.to_s))

  req = Request.new(
    method: :get,
    path: path
  )

  connection.call(req, return_type: InvoiceResult)
end