Special offers verification
If your game doesn't have a server-side's code then you might skip this section.
Using of Game of Whales you can also execute the verification of special offers on the server-side. To do this you are just enough of using a value from specialOffer.payload property.
The Payload is an encrypted special offer data using a secret key. The key can be taken from Special Offer Payload Key field on Game Settings page. Game of Whales uses AES-256-CTR encryption algorithm with "hex" output encoding.
WARNING!!! You mustn't allow the secret key to be used by your client-side code.
Payload structure
The payload has the following attributes:
Attribute
|
Description |
Type |
---|---|---|
camp |
special offer's identifier |
string |
custom |
the data about a special offer's custom fields. It's included to the payload only if the custom fields are defined. |
object |
products |
list of special offer's products (SKUs for in-app purchases or game items). |
array of strings |
priceFactor |
price's multiplier (except in-app purchases). |
float |
countFactor |
count's multiplier (the multiplier is for the count of coins, for example). |
float |
finishedAt |
special offer's expiration time (in ticks). |
integer |
user |
player's identifier. |
string |
activatedAt |
the date of the special offer's activation by the player (in ticks). |
integer |
redeemable |
how many times the offer can be redeemed (only once or multiple times). |
boolean |
now |
time (in ticks) of response sending. |
integer |
Example:
{ "camp": "camp42", "custom": { "str": "abc", "num": 123, "flag": true }, "products": ["item_01", "item_100500"], "priceFactor": 2, "countFactor": 1, "finishedAt": 1550264340000, "redeemable": true, "activatedAt": 1550219230037, "user": "1234-5678-....-4321", "now": 1550219230037 }
Use case
The use case of using specialOffer.payload is as follows:
1. A client (your game’s code) receives a special offer from SDK and shows the offer in the game’s shop.
2. When a player tries to use the special offer, the client sends a request to the server (your game server) for applying this action on server-side and passes the specialOffer.payload.
3. The server decrypts the specialOffer.payload by using the secret key. The secret key can be taken in your game settings page on Game Of Whales service.
4. Server-side validation is processing.
4.1 It’s checked that purchased product is included in the list of the products from the specialOffer.payload.products.
4.2 It's checked the expiration date. You can compare specialOffer.payload.finishedAt and server time.
5. If point 4 is successful, the special offer can be applied to the player.
This case can be applied only if you have a game's server-side and you want the validation process to be made on server-side.
Example of decryption on the server-side (for nodejs)
decrypt = (encrypted, secretKey) => { const crypto = require('crypto'), decipher = crypto.createDecipher("AES-256-CTR", secretKey); let decrypted = decipher.update(encrypted, 'hex', 'utf8'); decrypted += decipher.final('utf8'); return decrypted; };