Reward Players with Points PRO
Your store has loyalty points. With the API, your game can give them too: win a round, earn 10 points, spend them at your store.
You'll need: a key with points:write, and points turned on in your store.
Give points
One request:
curl -X POST "https://api.fastyvendor.com/api/v1/customers/a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d/points" \
-H "Authorization: Bearer $FASTY_KEY" \
-H "Idempotency-Key: round-42-a1b2c3d4" \
-H "Content-Type: application/json" \
-d '{"delta": 10, "note": "Won round 42"}'The answer has the new balance:
{ "avatar_key": "a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d", "delta": 10, "balance": 20 }To take points, send a negative delta. If the avatar has less than that, the balance stops at zero and delta in the answer says what really changed.
In Second Life
This script gives points when your game tells it who won. Your game sends a link_message with the winner's key.
string API = "https://api.fastyvendor.com/api/v1";
string KEY = "fsk_…"; // your key, with points:write
integer POINTS = 10;
integer gRound; // goes up every round
key gRequest = NULL_KEY;
key gWinner;
give(key winner)
{
gWinner = winner;
string body = llList2Json(JSON_OBJECT, ["delta", POINTS, "note", "Won a round"]);
gRequest = llHTTPRequest(API + "/customers/" + (string)winner + "/points",
[HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/json",
HTTP_CUSTOM_HEADER, "Authorization", "Bearer " + KEY,
HTTP_CUSTOM_HEADER, "Idempotency-Key", (string)llGetKey() + "-" + (string)gRound],
body);
}
default
{
link_message(integer sender, integer num, string msg, key winner)
{
if (num != 7000) return; // your game: llMessageLinked(LINK_SET, 7000, "", winner);
++gRound;
give(winner);
}
http_response(key id, integer status, list meta, string body)
{
if (id != gRequest) return;
gRequest = NULL_KEY;
if (status == 200)
llRegionSayTo(gWinner, 0, "You won " + (string)POINTS + " points! You now have "
+ llJsonGetValue(body, ["balance"]) + ".");
else
llOwnerSay("Fasty: " + llJsonGetValue(body, ["error", "message"]));
}
}Why the Idempotency-Key matters here
If the region lags and your game retries, the same key means the round pays once. Build it from something that identifies the round, as above. See Safe retries.
Show the balance
Read it with a key that has points:read:
llHTTPRequest(API + "/customers/" + (string)who + "/points",
[HTTP_CUSTOM_HEADER, "Authorization", "Bearer " + KEY], "");
// in http_response:
llRegionSayTo(who, 0, "You have " + llJsonGetValue(body, ["balance"]) + " points.");Good to know
- The note shows in the customer's history in the panel, so write something clear.
- Avatars don't need to have bought anything to receive points.
- Points are for your store's rewards. They aren't L$ and can't be cashed out.
Full details: Points reference.