This example continues the rewards page tutorial. It uses the same loyalty request function. Adapt the calls to your theme’s button, confirmation step and receipt display.
4. Confirm the price
Show the signed-in shopper the reward they selected and its price. For our eligible shopper, the selection is Birthday blanket · 100 points. Ask them to confirm before spending their points.
5. Spend the points
Use the selected reward from Configuration and the price the shopper confirmed, as a string. For a fixed-price reward, the request looks like this:
const selection = {
customer_id: document.querySelector('[data-shopper-id]').dataset.shopperId,
rule_id: reward.rule_id,
points: price,
terms_version: reward.terms_version,
idempotency_key: crypto.randomUUID()
};
const { redemption, points_balance } = await loyalty('/redemptions', {
method: 'POST',
body: selection
});
document.querySelector('[data-points-balance]').textContent = points_balance;
Create the selection once for that confirmation. Our shopper now sees 450 points. Keep the receipt ID from redemption.id to check when the blanket code is ready. Recover a lost response
Give the shopper feedback
After confirmation, disable the spend button and show “Redeeming your reward…” with an indeterminate progress indicator. Keep the original selection and key before sending the request. A timeout or unexpected response is not permission to start another spend: offer recovery with the same key.
An accepted receipt can still be waiting for issuance. Show “Preparing your reward” until it succeeds. You can check the receipt a few times with a delay, then offer a manual status check. These are receipt reads, not new spend requests. Respect rate-limit responses.
When issuance succeeds, show “Your reward is ready”, the available code or store credit result, and the balance returned by the spend. Offer a link to the shopper’s wallet. If issuance fails, show the receipt’s final outcome rather than a success message. These presentation choices belong to your theme; the API does not supply a progress percentage.
6. Show the code and reward history
When the shopper checks the reward, read its receipt. In this example, codeOutput is the element in your theme where the shopper looks for their code.
const { redemption: receipt } = await loyalty('/redemptions/' + redemption.id);
codeOutput.textContent = '';
if (receipt.status === 'succeeded' && receipt.code_status === 'available' && receipt.reward_code) {
codeOutput.textContent = receipt.reward_code;
}
Once the blanket code is ready, the shopper can see it. Store credit has no discount code.
To show reward history, read GET /v1/redemptions. Use an element such as <ul data-reward-history></ul> for the list in your page.
const { redemptions } = await loyalty('/redemptions');
const history = document.querySelector('[data-reward-history]');
history.replaceChildren();
for (const reward of redemptions) {
const item = document.createElement('li');
item.textContent = (reward.title || 'Reward') + ' · ' + reward.points + ' points';
history.append(item);
}
After the reward succeeds, the history shows Birthday blanket · 100 points. The shopper can return to the page later and find the same reward.