iVendNextDevelopers Request a sandbox

A gift card for a big spend, spendable after a hold — the recipe

A shop wants a sale over a set amount to earn the customer the shop's own gift card, which can be spent only after a hold (24 hours is common: the customer cannot buy, earn and spend in one visit). This recipe builds it as an outside app that reads the event feed and keeps every change of value in the shop's own gift card records. It is for an iVendNext developer who has made an outside app before (chapter 5).

Reference implementation: samples/s25_gift_on_spend/ — Gift card on spend.

When to use it. Any reward of stored value that the shop's own gift cards can carry: a card for a spend over a threshold, one per full threshold, held for a while before it spends. The card is not on that sale's receipt: it is made after the sale books. If the shop wants the card in the sale itself (a promotion that gives a gift card), that is the shop's promotion; today iVendNext POS shows such a reward as earned, complete at the register rather than issuing it.

Steps

  1. Read the sales from the feed (recipe): the shop's feed registration follows POS Invoice; your service acts on sale.booked, return.booked and sale.cancelled, reads each sale over the API, and marks the event done. Every other event is marked done unread.
  2. Name each card before you make it. Your manifest's own record type <PREFIX> Card is named by the sale and the card's position ("autoname": "field:card_key", the key S1:1). Write it first, holding the card's number, value, item and hold. The shop refuses a second record with that name, so a replayed event or a crash never earns a second card.
  3. Make the shop's own gift card at a balance of 0. Insert the engine's Gift Card with your number (16 digits, from a secure random source, never one the shop holds), the shop's gift card item, its total = the card's value, its balance = 0. The till and the engine refuse a card with nothing on it, so nobody can spend it during the hold.
  4. Release it after the hold with a Gift Card Balance. Submit the engine's Gift Card Balance for the card with its value: on submit it sets the card's balance and writes a comment on the card, and the shop's Gift Card Ledger report lists it. ⚠ It sets the balance; it does not add. Release only a card that has no submitted Gift Card Balance yet and a balance of exactly 0; anything else goes to the shop to decide.
  5. Read the sale again before every release. Cancelled since? Returned below what earned this card? Then void it instead. Decide from the sale and every return booked against it now, never from the order the events arrived in: a failed event is retried after later ones.
  6. Void what a cancellation or return no longer earns. A held card is simply never released. A released card still at its full value, and never used at the till (the till's own redeemed test, ivendnext_pos.api.pos_invoice.get_gift_card_status), is set to 0 by a Gift Card Balance of 0. A card already used keeps its balance and goes to the shop to decide: never take back what a customer has spent.
  7. Refuse a gift card item that could turn into money. A rechargeable card would let a void take money the customer paid in; a cash-back card pays the promotion out as cash; a store-credit card is the returns' own. Check the item's flags before you issue.
  8. Tell staff. List each card under the customer and the sale (Connections links in the manifest). The kit has no way yet to send the number to the customer: an e-mail needs the product to give the framework's e-mail call an iVendNext name, and a message needs a gateway.

Settings

One record of your own type <PREFIX> Settings, named Default, edited by the shop in Desk and read at every pass (chapter 7, a single-record type is refused): enabled, the currency, the threshold, each card's value, the gift card item, the cards per sale, the hold in hours, and the walk-in customers and customer groups that never earn.

Earned gift cards

One record per card, listed under the customer and the sale: its state (Issuing, Held, Released, Voided, Review), its number and gift card, its value, the threshold and hold it was earned under, when it can be spent (the shop's time), the Gift Card Balance that released it and the one that set it to 0, and a note when the shop must decide.

What the shop needs from you

When your service is down, and when the till is offline

Nothing at the till waits for your service: the sale books as before. The feed keeps the events, so the cards are issued when your service is back, and the hold runs from then. A sale rung offline reaches the feed when the till syncs.

Technical notes

What was proven where

Needs this serves

This page in the kit