Class: Pago::V2026_04::Services::Orders

Inherits:
Service
  • Object
show all
Defined in:
lib/pago/v2026_04/services/orders.rb,
sig/pago/v2026_04/generated.rbs

Instance Attribute Summary

Attributes inherited from Service

#client

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from Pago::Service

Instance Method Details

#create(body: {}) ⇒ Models::Order

Create a draft order for an off-session charge against a saved payment method. The order is created with status=draft and no invoice number; call POST /v1/orders/{id}/finalize to attempt the charge.

The organization must have the off_session_charges_enabled feature flag.

Scopes: orders:write

Parameters:

  • body (Hash, Models::OrderCreate) (defaults to: {})

    the request body.

  • body: (Object) (defaults to: {})

Returns:

Raises:



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pago/v2026_04/services/orders.rb', line 61

def create(body: {})
  data = client.request(
    http_method: "POST",
    path: "/v1/orders/",
    path_params: {},
    query: {},
    body: body,
    response_type: :json,
    errors: { 422 => Errors::HTTPValidationError }
  )
  Models::Order.from_json(data)
end

#export(organization_id: nil, product_id: nil) ⇒ String

Export orders as a CSV file.

Scopes: orders:read

Parameters:

  • organization_id (String, Array<String>, nil) (defaults to: nil)

    Filter by organization ID.

  • product_id (String, Array<String>, nil) (defaults to: nil)

    Filter by product ID.

  • organization_id: (Object) (defaults to: nil)
  • product_id: (Object) (defaults to: nil)

Returns:

  • (String)

Raises:



83
84
85
86
87
88
89
90
91
92
# File 'lib/pago/v2026_04/services/orders.rb', line 83

def export(organization_id: nil, product_id: nil)
  client.request(
    http_method: "GET",
    path: "/v1/orders/export",
    path_params: {},
    query: { "organization_id" => organization_id, "product_id" => product_id },
    response_type: :text,
    errors: { 422 => Errors::HTTPValidationError }
  )
end

#finalize(id, body: {}) ⇒ Models::Order

Finalize a draft order and synchronously attempt an off-session charge.

On success, the order transitions to paid and benefit grants fire before the response returns. On failure (decline, missing payment method, SCA challenge), the order stays in draft and a 4xx error is returned.

The request fails with 412 if the order is not in draft status.

Scopes: orders:write

Parameters:

  • id (String)

    The order ID.

  • body (Hash, Models::OrderFinalize) (defaults to: {})

    the request body.

  • body: (Object) (defaults to: {})

Returns:

Raises:



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/pago/v2026_04/services/orders.rb', line 157

def finalize(id, body: {})
  data = client.request(
    http_method: "POST",
    path: "/v1/orders/{id}/finalize",
    path_params: { "id" => id },
    query: {},
    body: body,
    response_type: :json,
    errors: { 402 => Errors::Finalize402Error, 403 => Errors::Finalize403Error, 404 => Errors::ResourceNotFound, 412 => Errors::OrderNotDraft, 422 => Errors::HTTPValidationError }
  )
  Models::Order.from_json(data)
end

#generate_invoice(id) ⇒ Object

Trigger generation of an order's invoice.

Scopes: orders:read

Parameters:

  • id (String)

    The order ID.

Returns:

  • (Object)

Raises:



201
202
203
204
205
206
207
208
209
210
211
# File 'lib/pago/v2026_04/services/orders.rb', line 201

def generate_invoice(id)
  data = client.request(
    http_method: "POST",
    path: "/v1/orders/{id}/invoice",
    path_params: { "id" => id },
    query: {},
    response_type: :json,
    errors: { 404 => Errors::ResourceNotFound, 409 => Errors::OrderNotEligibleForInvoice, 422 => Errors::MissingInvoiceBillingDetails }
  )
  data
end

#get(id) ⇒ Models::Order

Get an order by ID.

Scopes: orders:read

Parameters:

  • id (String)

    The order ID.

Returns:

Raises:



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/pago/v2026_04/services/orders.rb', line 103

def get(id)
  data = client.request(
    http_method: "GET",
    path: "/v1/orders/{id}",
    path_params: { "id" => id },
    query: {},
    response_type: :json,
    errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
  )
  Models::Order.from_json(data)
end

#invoice(id) ⇒ Models::OrderInvoice

Get an order's invoice data.

Scopes: orders:read

Parameters:

  • id (String)

    The order ID.

Returns:

Raises:



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/pago/v2026_04/services/orders.rb', line 179

def invoice(id)
  data = client.request(
    http_method: "GET",
    path: "/v1/orders/{id}/invoice",
    path_params: { "id" => id },
    query: {},
    response_type: :json,
    errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
  )
  Models::OrderInvoice.from_json(data)
end

#list(organization_id: nil, product_id: nil, product_billing_type: nil, discount_id: nil, customer_id: nil, external_customer_id: nil, checkout_id: nil, subscription_id: nil, page: 1, limit: 10, sorting: ["-created_at"], metadata: nil) ⇒ Models::ListResourceOrder

List orders.

Scopes: orders:read

Parameters:

  • organization_id (String, Array<String>, nil) (defaults to: nil)

    Filter by organization ID.

  • product_id (String, Array<String>, nil) (defaults to: nil)

    Filter by product ID.

  • product_billing_type (String, Array<String>, nil) (defaults to: nil)

    Filter by product billing type. recurring will filter data corresponding to subscriptions creations or renewals. one_time will filter data corresponding to one-time purchases.

  • discount_id (String, Array<String>, nil) (defaults to: nil)

    Filter by discount ID.

  • customer_id (String, Array<String>, nil) (defaults to: nil)

    Filter by customer ID.

  • external_customer_id (String, Array<String>, nil) (defaults to: nil)

    Filter by customer external ID.

  • checkout_id (String, Array<String>, nil) (defaults to: nil)

    Filter by checkout ID.

  • subscription_id (String, Array<String>, nil) (defaults to: nil)

    Filter by subscription ID.

  • page (Integer) (defaults to: 1)

    Page number, defaults to 1.

  • limit (Integer) (defaults to: 10)

    Size of a page, defaults to 10. Maximum is 100.

  • sorting (Array<String>, nil) (defaults to: ["-created_at"])

    Sorting criterion. Several criteria can be used simultaneously and will be applied in order. Add a minus sign - before the criteria name to sort by descending order.

  • metadata (Object) (defaults to: nil)

    Filter by metadata key-value pairs. It uses the deepObject style, e.g. ?metadata[key]=value.

  • organization_id: (Object) (defaults to: nil)
  • product_id: (Object) (defaults to: nil)
  • product_billing_type: (Object) (defaults to: nil)
  • discount_id: (Object) (defaults to: nil)
  • customer_id: (Object) (defaults to: nil)
  • external_customer_id: (Object) (defaults to: nil)
  • checkout_id: (Object) (defaults to: nil)
  • subscription_id: (Object) (defaults to: nil)
  • page: (Integer, nil) (defaults to: 1)
  • limit: (Integer, nil) (defaults to: 10)
  • sorting: (Array[String], nil) (defaults to: ["-created_at"])
  • metadata: (Object) (defaults to: nil)

Returns:

Raises:



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pago/v2026_04/services/orders.rb', line 26

def list(organization_id: nil, product_id: nil, product_billing_type: nil, discount_id: nil, customer_id: nil, external_customer_id: nil, checkout_id: nil, subscription_id: nil, page: 1, limit: 10, sorting: ["-created_at"], metadata: nil)
  data = client.request(
    http_method: "GET",
    path: "/v1/orders/",
    path_params: {},
    query: { "organization_id" => organization_id, "product_id" => product_id, "product_billing_type" => product_billing_type, "discount_id" => discount_id, "customer_id" => customer_id, "external_customer_id" => external_customer_id, "checkout_id" => checkout_id, "subscription_id" => subscription_id, "page" => page, "limit" => limit, "sorting" => sorting, "metadata" =>  },
    response_type: :json,
    errors: { 422 => Errors::HTTPValidationError }
  )
  Models::ListResourceOrder.from_json(data)
end

#list_each(organization_id: nil, product_id: nil, product_billing_type: nil, discount_id: nil, customer_id: nil, external_customer_id: nil, checkout_id: nil, subscription_id: nil, limit: 10, sorting: ["-created_at"], metadata: nil) {|item| ... } ⇒ Pago::Paginator

Enumerate every item of list, fetching pages on demand.

Parameters:

  • organization_id: (Object) (defaults to: nil)
  • product_id: (Object) (defaults to: nil)
  • product_billing_type: (Object) (defaults to: nil)
  • discount_id: (Object) (defaults to: nil)
  • customer_id: (Object) (defaults to: nil)
  • external_customer_id: (Object) (defaults to: nil)
  • checkout_id: (Object) (defaults to: nil)
  • subscription_id: (Object) (defaults to: nil)
  • limit: (Integer, nil) (defaults to: 10)
  • sorting: (Array[String], nil) (defaults to: ["-created_at"])
  • metadata: (Object) (defaults to: nil)

Yield Parameters:

Returns:



42
43
44
45
46
47
# File 'lib/pago/v2026_04/services/orders.rb', line 42

def list_each(organization_id: nil, product_id: nil, product_billing_type: nil, discount_id: nil, customer_id: nil, external_customer_id: nil, checkout_id: nil, subscription_id: nil, limit: 10, sorting: ["-created_at"], metadata: nil, &block)
  paginator = ::Pago::Paginator.new do |page_number|
    list(organization_id: organization_id, product_id: product_id, product_billing_type: product_billing_type, discount_id: discount_id, customer_id: customer_id, external_customer_id: external_customer_id, checkout_id: checkout_id, subscription_id: subscription_id, page: page_number, limit: limit, sorting: sorting, metadata: )
  end
  block ? paginator.each(&block) : paginator
end

#receipt(id) ⇒ Models::OrderReceipt

Get a presigned URL to download an order's receipt PDF.

Scopes: orders:read

Parameters:

  • id (String)

    The order ID.

Returns:

Raises:



222
223
224
225
226
227
228
229
230
231
232
# File 'lib/pago/v2026_04/services/orders.rb', line 222

def receipt(id)
  data = client.request(
    http_method: "GET",
    path: "/v1/orders/{id}/receipt",
    path_params: { "id" => id },
    query: {},
    response_type: :json,
    errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
  )
  Models::OrderReceipt.from_json(data)
end

#update(id, body: {}) ⇒ Models::Order

Update an order.

Scopes: orders:write

Parameters:

  • id (String)

    The order ID.

  • body (Hash, Models::OrderUpdate) (defaults to: {})

    the request body.

  • body: (Object) (defaults to: {})

Returns:

Raises:



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/pago/v2026_04/services/orders.rb', line 125

def update(id, body: {})
  data = client.request(
    http_method: "PATCH",
    path: "/v1/orders/{id}",
    path_params: { "id" => id },
    query: {},
    body: body,
    response_type: :json,
    errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
  )
  Models::Order.from_json(data)
end