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.
-
#create_with_response(payload) ⇒ Inttegro::APIResponse
Create a new order and keep HTTP response metadata with the decoded order.
-
#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.
-
#page(payload = {}) ⇒ Inttegro::Order::Page
Retrieve a paginated list of orders.
-
#pay(payload) ⇒ Inttegro::Order
Initiate payment for an existing order.
-
#request_confirmation(order_id:, request_meta: nil) ⇒ Inttegro::Order
Request a new confirmation token to be sent to the customer (e.g., resend OTP).
-
#search(payload) ⇒ Inttegro::Search::Page
Search orders using indexed fields and full-text matching.
-
#send_invoice(order_id:) ⇒ Inttegro::Order::DocumentDeliveryResult
Send the hosted invoice link for an existing order.
-
#send_receipt(order_id:) ⇒ Inttegro::Order::DocumentDeliveryResult
Send the hosted receipt link for a paid order.
-
#update(payload) ⇒ Inttegro::Order
Update mutable fields on an order.
Constructor Details
#initialize(http) ⇒ Orders
Returns a new instance of Orders.
15 16 17 |
# File 'lib/inttegro/resources/orders.rb', line 15 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.
358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/inttegro/resources/orders.rb', line 358 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.
336 337 338 |
# File 'lib/inttegro/resources/orders.rb', line 336 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.
220 221 222 |
# File 'lib/inttegro/resources/orders.rb', line 220 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.
103 104 105 |
# File 'lib/inttegro/resources/orders.rb', line 103 def create(payload) @http.post_resource("/orders/create", Inttegro::Order, :order, payload) end |
#create_with_response(payload) ⇒ Inttegro::APIResponse
Create a new order and keep HTTP response metadata with the decoded order.
111 112 113 |
# File 'lib/inttegro/resources/orders.rb', line 111 def create_with_response(payload) @http.post_resource_with_response("/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.
272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/inttegro/resources/orders.rb', line 272 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.
133 134 135 136 |
# File 'lib/inttegro/resources/orders.rb', line 133 def lookup(order_id:, **) body = { order_id: order_id }.merge() @http.post_resource("/orders/lookup", Inttegro::Order, :order, body) end |
#page(payload = {}) ⇒ Inttegro::Order::Page
Retrieve a paginated list of orders.
Returns orders in reverse chronological order (most recent first).
397 398 399 |
# File 'lib/inttegro/resources/orders.rb', line 397 def page(payload = {}) @http.post_resource("/orders/page", Inttegro::Order::Page, :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.
194 195 196 |
# File 'lib/inttegro/resources/orders.rb', line 194 def pay(payload) @http.post_resource("/orders/pay", Inttegro::Order, :order, 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.
242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/inttegro/resources/orders.rb', line 242 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 |
#search(payload) ⇒ Inttegro::Search::Page
Search orders using indexed fields and full-text matching.
405 406 407 |
# File 'lib/inttegro/resources/orders.rb', line 405 def search(payload) @http.post_resource("/orders/search", Inttegro::Search::Page, :search, payload) end |
#send_invoice(order_id:) ⇒ Inttegro::Order::DocumentDeliveryResult
Send the hosted invoice link for an existing order.
289 290 291 292 293 294 295 |
# File 'lib/inttegro/resources/orders.rb', line 289 def send_invoice(order_id:) @http.post_model( "/orders/send_invoice", Inttegro::Order::DocumentDeliveryResult, { order_id: order_id } ) end |
#send_receipt(order_id:) ⇒ Inttegro::Order::DocumentDeliveryResult
Send the hosted receipt link for a paid order.
302 303 304 305 306 307 308 |
# File 'lib/inttegro/resources/orders.rb', line 302 def send_receipt(order_id:) @http.post_model( "/orders/send_receipt", Inttegro::Order::DocumentDeliveryResult, { order_id: order_id } ) end |
#update(payload) ⇒ Inttegro::Order
Update mutable fields on an order.
142 143 144 |
# File 'lib/inttegro/resources/orders.rb', line 142 def update(payload) @http.post_resource("/orders/update", Inttegro::Order, :order, payload) end |