Class: Inttegro::Resources::Orders
- Inherits:
-
Object
- Object
- Inttegro::Resources::Orders
- Defined in:
- lib/inttegro/resources/orders.rb
Overview
Orders resource for creating orders, processing payments, and managing order lifecycle.
Orders are the central transaction object in Inttegro. They represent a purchase with line items, customer information, and payment details. Use this resource to create orders, charge customers, handle confirmations, and process refunds.
Instance Method Summary collapse
-
#cancel(order_id:, request_meta: nil) ⇒ Inttegro::Order
Cancel an order, stopping payment execution and preventing further processing.
-
#complete(payload) ⇒ Inttegro::Order
Mark an order as completed, indicating fulfillment is done.
-
#confirm_payment(payload) ⇒ Inttegro::Order
Confirm a pending payment using a verification token (e.g., OTP sent to customer's phone).
-
#create(payload) ⇒ Inttegro::Order
Create a new order with line items, customer, and payment details.
-
#finalize(order_id:, request_meta: nil) ⇒ Inttegro::Order
Finalize an order to make it immutable and ready for payment or fulfillment.
-
#initialize(http) ⇒ Orders
constructor
A new instance of Orders.
-
#lookup(order_id:, **options) ⇒ Inttegro::Order
Retrieve an existing order by its ID.
- #new(payload) ⇒ Object
-
#page(payload = {}) ⇒ Inttegro::OrderPage
Retrieve a paginated list of orders.
-
#pay(payload) ⇒ Inttegro::Order
Initiate payment for an existing order.
-
#refund(payload) ⇒ Inttegro::Refund
Create a refund through the /orders/refund compatibility alias.
-
#request_confirmation(order_id:, request_meta: nil) ⇒ Inttegro::Order
Request a new confirmation token to be sent to the customer (e.g., resend OTP).
-
#send_invoice(order_id:) ⇒ Inttegro::OrderDocumentDeliveryResult
Send the hosted invoice link for an existing order.
-
#send_receipt(order_id:) ⇒ Inttegro::OrderDocumentDeliveryResult
Send the hosted receipt link for a paid order.
- #update(payload) ⇒ Object
Constructor Details
#initialize(http) ⇒ Orders
Returns a new instance of Orders.
14 15 16 |
# File 'lib/inttegro/resources/orders.rb', line 14 def initialize(http) @http = T.let(http, Inttegro::HTTPClient) end |
Instance Method Details
#cancel(order_id:, request_meta: nil) ⇒ Inttegro::Order
Cancel an order, stopping payment execution and preventing further processing.
Canceling an order is irreversible and should be done when the customer requests cancellation or the order cannot be fulfilled. If payment was already captured, you'll need to refund it separately.
349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/inttegro/resources/orders.rb', line 349 def cancel(order_id:, request_meta: nil) @http.post_resource( "/orders/cancel", Inttegro::Order, :order, { order_id: order_id, request_meta: || ("cancel", order_id) } ) end |
#complete(payload) ⇒ Inttegro::Order
Mark an order as completed, indicating fulfillment is done.
Call this after you've shipped physical goods or delivered digital products to the customer. Completing an order transitions it to its final state and can optionally mark payment as received offline (out-of-band) if paid_out_of_band is set to true.
327 328 329 |
# File 'lib/inttegro/resources/orders.rb', line 327 def complete(payload) @http.post_resource("/orders/complete", Inttegro::Order, :order, payload) end |
#confirm_payment(payload) ⇒ Inttegro::Order
Confirm a pending payment using a verification token (e.g., OTP sent to customer's phone).
Call this method when a payment requires customer confirmation and you've collected the verification token from the customer. The token is typically a 6-digit OTP sent via SMS or email.
211 212 213 |
# File 'lib/inttegro/resources/orders.rb', line 211 def confirm_payment(payload) @http.post_resource("/orders/confirm_payment", Inttegro::Order, :order, payload) end |
#create(payload) ⇒ Inttegro::Order
Create a new order with line items, customer, and payment details.
Creates an order representing a purchase. You can create an order for a new or existing customer, include multiple line items, and optionally execute payment immediately. Orders must have at least one line item and billing details.
102 103 104 |
# File 'lib/inttegro/resources/orders.rb', line 102 def create(payload) @http.post_resource("/orders/create", Inttegro::Order, :order, payload) end |
#finalize(order_id:, request_meta: nil) ⇒ Inttegro::Order
Finalize an order to make it immutable and ready for payment or fulfillment.
Finalizing (sealing) an order locks its line items and totals, making it ready for payment execution or order completion. Most orders are finalized automatically, but you can explicitly finalize if needed.
263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/inttegro/resources/orders.rb', line 263 def finalize(order_id:, request_meta: nil) @http.post_resource( "/orders/finalize", Inttegro::Order, :order, { order_id: order_id, request_meta: || ("finalize", order_id) } ) end |
#lookup(order_id:, **options) ⇒ Inttegro::Order
Retrieve an existing order by its ID.
Returns full order details including customer, line items, payment state, and invoice information. Use this to check order status, retrieve payment details, or display order confirmation to customers.
128 129 130 131 |
# File 'lib/inttegro/resources/orders.rb', line 128 def lookup(order_id:, **) body = { order_id: order_id }.merge() @http.post_resource("/orders/lookup", Inttegro::Order, :order, body) end |
#new(payload) ⇒ Object
106 107 108 |
# File 'lib/inttegro/resources/orders.rb', line 106 def new(payload) @http.post_resource("/orders/new", Inttegro::Order, :order, payload) end |
#page(payload = {}) ⇒ Inttegro::OrderPage
Retrieve a paginated list of orders.
Returns orders in reverse chronological order (most recent first).
414 415 416 |
# File 'lib/inttegro/resources/orders.rb', line 414 def page(payload = {}) @http.post_resource("/orders/page", Inttegro::OrderPage, :page, payload || {}) end |
#pay(payload) ⇒ Inttegro::Order
Initiate payment for an existing order.
Supports three payment flows:
- Saved payment method: Provide only order_id to charge a previously saved payment method
- New payment method: Include payment_method_data with inline payment details
- Offline payment: Set paid_out_of_band to true for cash, bank transfer, or check payments
When payment requires customer confirmation (e.g., OTP), the returned order includes a next_action field.
185 186 187 |
# File 'lib/inttegro/resources/orders.rb', line 185 def pay(payload) @http.post_resource("/orders/pay", Inttegro::Order, :order, payload) end |
#refund(payload) ⇒ Inttegro::Refund
Create a refund through the /orders/refund compatibility alias.
This accepts the same line-item payload as client.refunds.create and returns the created Refund directly. New integrations should use that canonical method.
383 384 385 |
# File 'lib/inttegro/resources/orders.rb', line 383 def refund(payload) @http.post_resource("/orders/refund", Inttegro::Refund, :refund, payload) end |
#request_confirmation(order_id:, request_meta: nil) ⇒ Inttegro::Order
Request a new confirmation token to be sent to the customer (e.g., resend OTP).
Use this when the customer didn't receive the original OTP or the token expired. A fresh verification token will be sent via SMS or email to the customer's registered contact information.
233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/inttegro/resources/orders.rb', line 233 def request_confirmation(order_id:, request_meta: nil) @http.post_resource( "/orders/request_confirmation", Inttegro::Order, :order, { order_id: order_id, request_meta: || ("request_confirmation", order_id) } ) end |
#send_invoice(order_id:) ⇒ Inttegro::OrderDocumentDeliveryResult
Send the hosted invoice link for an existing order.
280 281 282 283 284 285 286 |
# File 'lib/inttegro/resources/orders.rb', line 280 def send_invoice(order_id:) @http.post_model( "/orders/send_invoice", Inttegro::OrderDocumentDeliveryResult, { order_id: order_id } ) end |
#send_receipt(order_id:) ⇒ Inttegro::OrderDocumentDeliveryResult
Send the hosted receipt link for a paid order.
293 294 295 296 297 298 299 |
# File 'lib/inttegro/resources/orders.rb', line 293 def send_receipt(order_id:) @http.post_model( "/orders/send_receipt", Inttegro::OrderDocumentDeliveryResult, { order_id: order_id } ) end |