Skip to content

Carts and checkout

A shop on ObjectsGrid keeps its shoppers' Carts, checks them out into Orders at the current prices, and records each payment as a PayAction. ObjectsGrid takes no payment and stores no card data: your payment provider does that, and your app records the outcome. Product images and videos stay in your own storage too; objects hold their URLs.

Carts

A cart's lines name an Offer and a quantity, at most 100 lines:

curl -X POST https://apis.objectsgrid.com/carts \
  -H 'X-ObjectsGrid-AccessPoint: EU' -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"seller": {"at_id": "https://apis.objectsgrid.com/organizations/<shop>"},
       "cartItem": [{"offer": {"at_id": "https://apis.objectsgrid.com/offers/<offer>"}, "quantity": 2}]}'
  • Prices on read. A read of one cart adds each line's current Offer price and priceCurrency, and totalPrice, the lines summed per currency, less what a discount code takes off. Prices are never stored, so a cart always shows today's prices. Lists of carts carry the lines as stored, without prices.
  • Guests. customer is optional: a guest's cart has none, and the checkout names one.
  • Expiry. A cart expires 30 days after its last change unless expires says otherwise. After it, reads answer 404.
  • From the browser. The default policy of a new Organization Account lets a public API key create carts, and read and change one by its id: keep the id in the visitor's browser. Anonymous callers can't list, delete or check out carts.

Checkout

Your server checks a cart out with its service account. The request adds the Order's fields the cart doesn't have:

curl -X POST https://apis.objectsgrid.com/carts/<id>/checkout \
  -H 'X-ObjectsGrid-AccessPoint: EU' -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"orderNumber": "A-1001",
       "billingAddress": {"streetAddress": "Teststr. 1", "postalCode": "10115", "addressCountry": "DE"}}'
  • The answer is the new Order, 201, its id the cart's. Its orderItem are the cart's lines, and its acceptedOffer the Offers at the version read: <offer>?version=<n>, so the price the shopper saw stays readable.
  • customer, seller and discountCode come from the cart unless the request names them. A code that is a DiscountCode is checked again and counted, and the Order records its discount; the cart's reads show the discount before. billingAddress and orderDelivery are personal data of the customer; see Personal data and erasure.
  • A line whose Offer is gone, past validThrough, OutOfStock, Discontinued or SoldOut, or whose Product's Inventories hold less than the quantity, refuses the checkout with 409. The message names the lines, such as /cartItem/1: only 1 in stock. A product without an Inventory isn't checked.
  • The cart is then checked out (checkedOut, order) and can't change. Checking it out again answers its Order with 200, so a retry is safe.
  • GraphQL: checkoutCart(id, input).

A discount code is passed to the Order, not applied: discounts and promotions are yours to work out for now.

Payments

When your provider tells your server how a payment went, through its webhook, record it as a PayAction:

{"object": {"at_id": "https://apis.objectsgrid.com/orders/<order>"},
 "agent": {"at_id": "https://apis.objectsgrid.com/persons/<customer>"},
 "recipient": {"at_id": "https://apis.objectsgrid.com/organizations/<shop>"},
 "price": 49.90, "priceCurrency": "EUR",
 "actionStatus": "https://schema.org/CompletedActionStatus",
 "providerPaymentId": "pi_3Q0a1b2c3d4e5f",
 "instrument": {"at_type": "PaymentCard", "paymentMethodType": "card", "name": "Visa ending 4242"}}
  • actionStatus: PotentialActionStatus when created, ActiveActionStatus while pending, CompletedActionStatus or FailedActionStatus with error.
  • Find the PayAction a webhook is about by providerPaymentId: GET /payactions?where={"providerPaymentId": {"equals": "pi_..."}}.
  • A refund is a PayAction the other way round, from the shop to the customer, with refundOf naming the payment.
  • No card data: instrument has a type and a name to show. A card number, expiry date, security code or token is refused.
  • The Order and the Invoice list their PayActions in payments (GraphQL). Recording a payment changes nothing else: your app sets the Order's orderStatus and the Invoice's paymentStatus.

Return and shipping policies

Define your return terms and shipping services once, as a MerchantReturnPolicy and ShippingServices, and point to them:

  • Your Organization's hasMerchantReturnPolicy and hasShippingService apply to everything it sells.
  • An Offer's or Product's own hasMerchantReturnPolicy, and an Offer's shippingDetails.hasShippingService, apply where it differs. Apps take an Offer's policy first, then its Product's, then the seller's.
  • A ShippingService's conditions say where it ships and for which order values, weights or item counts, at what rate. Free shipping above an amount is a second condition whose orderValue starts there, with a rate of 0.
  • The JSON-LD documents of your Offers, Products and Organization embed the policies they name, as search engines read them.