Checkout API with rewards

How can we add rewards to checkout-api. There are ‘Read-only’ fields (reward, reward-tier-id) (POST /v2/locations/{location_id}/checkouts - Square API Reference - order attributes. I found some hint in How can I generate the Checkout URL for existing Order where it asks you to use calculate (where you can propose rewards) and copy the order into the checkout-api
Another hint is to create the order , add the rewards using qttps://developer.squareup.com/reference/square/loyalty-api/create-loyalty-reward with the order_id, then retrieve the order, and include the order (as a new order) into checkout.
Both of these seem difficult and awkward, and may not work.
Is there an easier way?
Thanks
-Vasan

:wave: With the Checkout API you will need to use CalculateOrder first then create the checkout with that calculated order. :slightly_smiling_face:

1 Like

Not sure this works. Calculate order does create an order with rewards, but cannot put that into the checkout API (POST /v2/locations/{location_id}/checkouts - Square API Reference) because many ‘read-only’ fields are in there which cannot be specified. If you remove them, then the rewards are not appiled. It looks like the checkout-api wants to recalculate the order, but is missing the ‘proposed_rewards’ parameter (which is there in calculate order). It looks like there may be some other way or…

Ignore my previous comment…Am still working on this. Will post results (hopefully successful)

Hooray… Got it to work after deleteing read-only fields, and ‘redundant info’ (like name if catalog_object_id is there) and responded to all error messages, and it did work (Thx)

New problem: On the checkout page, it applies the discount(or reward), but does no indicate clearly that it did:
image
In that image note that 3.95 for the Baklava is not added to the total, but the display is not clear that it happened.

What is the order_id for that checkout?

Sorry for the late reply. I have a more recent one:
“order_id”: “JjkAfEamSIo1oU5SkQItvcHGAhaZY”
The entire order sent to checkout is:
{
“idempotency_key”: “e255bf15-302c-4777-b237-e1c83736c2f4”,
“order”: {
“idempotency_key”: “e255bf15-302c-4777-b237-e1c83736c2f4”,
“order”: {
“location_id”: “LQ6P723BZTYYR”,
“reference_id”: “e255bf15-302c-4777-b237-e1c83736c2f4”,
“customer_id”: “6P1EH8SGACSKN1166XMA7MEHXW”,
“line_items”: [
{
“catalog_object_id”: “VVYXH63ULGL67SXPY4G2VO24”,
“quantity”: “1”
},
{
“catalog_object_id”: “DCUQIWODU5IUYPM4CADARZLX”,
“quantity”: “1”,
“applied_discounts”: [
{
“uid”: “1eBMKPKqMK0Igzr7odtUK”,
“discount_uid”: “JgIEoOF9OONgCZXEwh7d8”
}
]
}
],
“metadata”: {
“xid”: “e255bf15-302c-4777-b237-e1c83736c2f4”,
“cxFNm”: “NA”,
“cxLNm”: “NA”,
“orderType”: “pickup”,
“cxPhNo”: “+15624482878”
},
“fullfillments”: [
{
“uid”: “e255bf15-302c-4777-b237-e1c83736c2f4”,
“type”: “pickup”,
“state”: “PROPOSED”,
“metadata”: {
“customer”: 15624482878
}
}
],
“discounts”: [
{
“uid”: “JgIEoOF9OONgCZXEwh7d8”,
“catalog_object_id”: “EVZULUT7GGK667CFU4UKXN2G”,
“catalog_version”: 1636297483097,
“percentage”: “100.0”,
“applied_money”: {
“amount”: 395,
“currency”: “USD”
},
“scope”: “LINE_ITEM”
}
]
}
},
“redirect_url”: “https://xxxx/squareapi/cart/paid
}