Class: Pago::V2026_04::Services::Orders
- Defined in:
- lib/pago/v2026_04/services/orders.rb,
sig/pago/v2026_04/generated.rbs
Instance Attribute Summary
Attributes inherited from Service
Instance Method Summary collapse
-
#create(body: {}) ⇒ Models::Order
Create a draft order for an off-session charge against a saved payment method.
-
#export(organization_id: nil, product_id: nil) ⇒ String
Export orders as a CSV file.
-
#finalize(id, body: {}) ⇒ Models::Order
Finalize a draft order and synchronously attempt an off-session charge.
-
#generate_invoice(id) ⇒ Object
Trigger generation of an order's invoice.
-
#get(id) ⇒ Models::Order
Get an order by ID.
-
#invoice(id) ⇒ Models::OrderInvoice
Get an order's invoice data.
-
#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.
-
#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. -
#receipt(id) ⇒ Models::OrderReceipt
Get a presigned URL to download an order's receipt PDF.
-
#update(id, body: {}) ⇒ Models::Order
Update an order.
Methods inherited from Service
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
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
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
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
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
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
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
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.
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
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
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 |