Skip to main content
A value code gives the player more of a bonus at the full price, for example +20% coins on any offer. It never changes the price. The player enters the code at the Stash checkout, pays, and Stash sends the code and the extra it grants in the optional valueCode block of ConfirmPayment. Your backend grants the extra on top of bonusItems. A value code is not a promo code. A promo code discounts the price; a value code adds to the bonus and leaves the price as it is.

Before you start

  • A Real-time Catalog integration. The code reaches your backend only in ConfirmPayment. The purchase webhooks and the payment webhooks carry no code, so a shop that grants from PURCHASE_SUCCEEDED cannot grant the extra.
  • The bonus in bonusItems. A code adds to an in-game currency bonus that your catalog lists in bonusItems (see Web Store Bonuses). A percent code applies to the bonus’s quantity in the ConfirmPayment bonusItems, which includes web store bonus rows with a guid. Any other amount in contents gets no extra.
  • Value codes on for your shop. Stash turns value codes on for your shop and agrees the rounding rule with you (see Rounding).

How a purchase with a code works

The code and its rewards are frozen into the payment when it is authorized. An edit to the code, or to your shop’s rounding rule, after that point does not change what ConfirmPayment sends for that payment.

The valueCode block

valueCode is present only when the player applied a code to the purchase. Without one, the request has no valueCode field.
ConfirmPayment request (excerpt)
The block has no total field. The total for a bonus is its bonusItems quantity plus the extra in valueCode.

Grant the extra

1

Grant bonusItems as usual

The bonusItems quantities are the offer’s own bonus. The extra is never inside them, so nothing counts twice.
2

Grant each reward on top

For each entry in valueCode.rewards, grant more units of the bonus in bonusId:extraQuantity is absent only when the extra does not fit in 32 bits. In that case, compute the extra from multiplierPermille and the bonusItems quantity, under the rule agreed for your shop. Otherwise grant extraQuantity as sent. Under the default rule, an extra that you compute from multiplierPermille and the bonusItems quantity matches it, so you can log a difference. Under another rule, for example one that rounds the new total, it can differ, and the request does not say which rule applied.
3

Grant once per transactionId

A retry of the same payment carries the same valueCode block. If you already granted this transactionId, return the same results and grant nothing again.
Do not decline a purchase because of the valueCode block. Stash has already checked the code before the charge. A decline or an error from ConfirmPayment means Stash does not capture the payment, so the player is not charged and receives nothing. See Payment Flow.

Rounding

A percent reward rarely lands on a whole number: 20% of 333 coins is 66.6. Stash rounds it under the rule agreed for your shop and sends the result as extraQuantity, so your backend does no rounding. With the default, 20% of 333 is 67 and 20% of 33 is 7. When your rule rounds the new total, extraQuantity is the rounded total minus the bonusItems quantity, or 0 when the rounded total is not above that quantity.

Code settings

Each code is configured for your shop with:

At checkout

  • Signed-in players only. A code belongs to the player’s account, so the code field shows only to a signed-in player.
  • One code at a time. The account holds one code per shop. A new code replaces the one held, and the player can remove it.
  • The code stays on the account. An applied code also applies to the player’s next checkouts, until it ends, is paused or stopped, the player’s limit is used, or the player applies another code. Stash can set a shorter hold for your shop.
  • Attempts are limited. A player can try 10 codes a minute in a shop. Each try counts, also one that applies a code.
The checkout refuses a code it cannot apply and tells the player why. The player can always pay without the code. Your backend never receives a refused code: the purchase either has no valueCode block, or stops before the player is charged and you receive no ConfirmPayment.

Limits

  • A use counts when Stash asks your ConfirmPayment to grant the purchase. If your ConfirmPayment declines with an HTTP 4xx status and no results, the use does not count. After a 5xx or a timeout it stays counted, because the items may have been granted.
  • The total limit can go slightly over. A player who applied the code in the current checkout keeps it at payment, even if other players used the last uses in the meantime. A player who applies it after the limit is reached is refused.
  • A payment already authorized with a code completes with it, even if the code is paused, stopped or edited after that.

Where else the code shows

  • Receipt. The player’s email receipt lists the code and its rewards.
  • Webhooks. PURCHASE_SUCCEEDED, PURCHASE_FAILED and the payment webhooks carry no code. Store what you need from ConfirmPayment, keyed on transactionId.

Next Steps

ConfirmPayment API Reference

The full request schema, with the valueCode block.

Payment Flow

Where the money is at each step, and what a decline does.

Catalog Items and Prices

Bonus items and web store bonuses in your catalog.