OpheliaDocs
Search docs⌘K
DashboardCreate an account
v3 · Guide

Order from a store

Buy a product from an online store: say which item, how many, which choices, where to ship it and the most it may cost. Rehearse to the payment step first, then place the order.

What an order does

An order is a booking that buys goods. You make it with POST /v3/bookings, like any other booking. Ophelia opens the item's page, makes your choices, adds it to the bag and walks the store's checkout.

StepWhat you do
1. Find the item
Search the store (Find something) and keep the item's entity_id. A product has no availability to read: go straight to the booking.
2. Rehearse
Send the order with authorize.max_commitment: "begin". Ophelia stops at the payment step with no card typed and answers the store's total.
3. Ask the person
Show the total and the lines. Get their yes.
4. Place it
Send the same order at commit (the default) with a way to pay. Ophelia checks the total against your ceiling and presses the order button.
An order at commit buys the item. The store charges the card and v3 cannot cancel the order. Only the store can. Rehearse at begin first.

The request

FieldWhat it says
entity_id
The item, from search. Or send its booking_url as url.
quantity
How many, 1 to 20. Leave it out for one.
selections
The item's choices by name, such as {"size": "M", "color": "Olive"}. At most 8, each name and value up to 80 characters. Names are lower-cased. Ophelia makes each choice on the page before it adds the item.
customer
The buyer's name, email and phone.
customer.address
Where the order ships: street, line2, city, state, zip_code, country. The billing address goes in the card (Pay).
authorize.fill_identity
true lets Ophelia type the email and phone. Without it they are not typed.
authorize.max_total
The most the order may cost, shipping and tax included, in the currency's own units: 128 means $128.00. Above 0. Required at commit.
authorize.currency
The three-letter code max_total is in, such as USD. A total in another currency is refused.
authorize.max_commitment
"begin" to rehearse. Absent means commit.
idempotency_key
Send one on every order. See Book or buy.

The ceiling rule: an order at commit needs authorize.max_total and authorize.currency. On a shopping site, or a site whose kind is not known, a booking counts as an order when it names a quantity or selections or carries a way to pay. A booking on a site that may charge a fee needs the ceiling too. Without it you get 422 max_total_required and nothing is attempted. Paying with the person's account (account_on_file) needs the ceiling on any kind of booking, and without it the request is refused with 400 naming the field.

Rehearse: the quote

At begin, Ophelia adds the item, walks the checkout to the payment step and stops. No card is typed. The answer is succeeded with no confirmation_number, and it carries the store's total in booking.purchase.quote.

curl
curl -X POST https://api.opheliaos.com/v3/bookings \
-H "Authorization: Bearer YOUR_TEST_KEY" \
-H "Content-Type: application/json" \
-d '{
"entity_id": "ent_a8b29e41565ff90b71620e08",
"idempotency_key": "docs-order-begin",
"quantity": 2,
"customer": {
"name": "Jane Smith",
"email": "jane.smith.diner@gmail.com",
"phone": "+12124567890",
"address": { "street": "350 5th Ave", "line2": "Suite 4100", "city": "New York", "state": "NY", "zip_code": "10118", "country": "US" }
},
"authorize": {
"max_commitment": "begin",
"fill_identity": true,
"max_total": 200,
"currency": "USD"
}
}'
json
{
"status": "succeeded",
"booking_id": "bk_10f28ba7e3aa1066f3b1ab24",
"booking": {
"action": "Add to cart",
"form_reached": true,
"purchase": {
"quote": {
"breakdown": { "currency": "USD", "shipping": 0, "subtotal": 128, "tax": 0, "total": 128 },
"currency": "USD",
"final": true,
"lines": [
{ "line_total": 128, "name": "Practice Day Pack", "quantity": 2, "unit_price": 64 }
],
"total": "Total $128.00",
"total_amount": 128
},
"stage": "payment"
},
"screen": "payment",
"why": "reached the payment screen under a begin bound — a card is only typed under 'commit'"
},
"drive_id": "drv_d814ec37120be5ae0af5c4a2",
"cancellable": false,
"cancel_via": "contact the venue directly using the confirmation on this booking"
}
quote fieldWhat it says
total
The total as the store wrote it
total_amount
The same total as a number, in currency
lines
What is in the bag: name, quantity, unit_price, line_total
breakdown
subtotal, shipping, tax and total, where the store showed them
final
false when the store's words say the total is not final yet

Show the person the total and the lines before you place the order. Set max_total to the amount they agreed to.

Place the order

Send the same request at commit: leave out max_commitment, add a way to pay (Pay) and use a new idempotency_key. Before the order button, Ophelia checks that the bag holds exactly the item and quantity you asked for, and that the total is in your currency and within max_total. If any check fails, the button is not pressed.

curl
curl -X POST https://api.opheliaos.com/v3/bookings \
-H "Authorization: Bearer YOUR_TEST_KEY" \
-H "Content-Type: application/json" \
-d '{
"entity_id": "ent_a8b29e41565ff90b71620e08",
"idempotency_key": "docs-order-commit",
"quantity": 2,
"customer": {
"name": "Jane Smith",
"email": "jane.smith.diner@gmail.com",
"phone": "+12124567890",
"address": { "street": "350 5th Ave", "line2": "Suite 4100", "city": "New York", "state": "NY", "zip_code": "10118", "country": "US" }
},
"card": {
"number": "4242424242424242",
"exp": "12/28",
"cvv": "123",
"name": "Jane Smith",
"postal_code": "10001",
"street_address": "350 5th Ave",
"city": "New York",
"state": "NY",
"country": "US"
},
"authorize": { "fill_identity": true, "max_total": 200, "currency": "USD" }
}'
json
{
"status": "succeeded",
"booking_id": "bk_2fd46d3b4c709779e1af1723",
"confirmation_number": "PX-834126",
"confirmation": {
"currency": "USD",
"items": [
{ "name": "Practice Day Pack (Olive)", "price": "$64.00", "quantity": 2 }
],
"order_number": "PX-834126",
"quantity": 2,
"reference": "PX-834126",
"screen": "confirmed",
"total": "$128.00",
"total_amount": 128,
"url": "https://opheliapractice.com/shop/practice-day-pack"
},
"amount_cents": 12800,
"currency": "USD",
"drive_id": "drv_85a48dd94a97e6ab950a6efb",
"cancellable": false,
"cancel_via": "contact the venue directly using the confirmation on this booking"
}
FieldWhat it says
confirmation_number
The store’s order number
confirmation.order_number
The same order number, read from the receipt
confirmation.total
The total as the receipt wrote it
confirmation.total_amount
The total as a number, in confirmation.currency
confirmation.items
Each line: name, price, quantity
amount_cents
What the order cost, in the currency's smallest unit (12800 is $128.00). Absent when the receipt showed no total.
currency
Its three-letter code

An order's confirmation uses the keys above for what the receipt showed. Any of them may be absent when the receipt did not show it. Other keys in it, such as screen and url, vary by store.

Buy Now

On the person's own account, authorize.buy_now: true presses the item's own "Buy Now" button in place of adding it to the bag. It needs max_commitment: "commit" sent in the request (the default does not count) and authorize.payment: "account_on_file". Anything else is 400, field authorize.buy_now. How to pay from the account is on Pay.

What can go wrong

Every answer in this table means nothing was bought. Fix what it names and try again with a new idempotency_key.

json
{
"status": "failed",
"booking_id": "bk_aafe3c1f0a2824ae1f3db689",
"failure_class": "terminal",
"error_code": "over_max_total",
"error": "the checkout's total reads \"Total $128.00\" (128.00), over the max_total of 5.00 — the press that would complete it was NOT made. Nothing was submitted and no booking was created."
}
AnswerWhat it means and what to do
400 field quantity
Not a whole number from 1 to 20. Fix it.
400 field selections
More than 8, or a name or value over 80 characters. Fix it.
400 field authorize.currency
Not a three-letter ISO 4217 code such as USD. Fix it.
422 max_total_required
No ceiling at commit. Add authorize.max_total and authorize.currency.
422 needs_input
At commit, the item has a choice you did not name. Its missing item names the choice and the values on offer. Ask the person and add it to selections. See When a drive pauses.
409 over_max_total
The total is over your ceiling. Show the person the new total. Raise the ceiling only with their yes.
409 total_unreadable
No total could be read, so the order was not placed blind.
409 currency_mismatch
The total is in another currency than authorize.currency.
409 cart_mismatch
The bag or the review did not hold exactly the item and quantity you asked for.
409 variant_unavailable
The choice you asked for is sold out or cannot be chosen. No other choice is made for you. The answer names the values on offer.
409 selection_unconfirmed
A choice was pressed and the page did not show it as made. Nothing was added to the bag.
409 out_of_stock
The page says the item cannot be bought now.
409 not_bookable_here
The item cannot be bought on this site, such as an in-store-only item.
409 address_rejected
The store would not take the shipping address as given.
409 payment_method_unavailable
The checkout takes no card, only other ways to pay.
409 order_refused
The order button was pressed and the store refused the order as filled in, saying why. error carries its words. Nothing was bought.
409 card_declined
The store declined the card. No order was placed. Ask the person for another card.

Some answers are different. not_confirmed_after_otp, transaction_status_unknown and booked_a_different_entity mean it may have bought: do not send the order again, tell the person, and check with the store. For any other code at commit, read GET /v3/bookings/{booking_id} and check with the store before you order again. See Handle errors.

Next: Use a person's own account.