In-Store Loyalty
NOTE: we use the term stamps in this document, Slerp can display stamps or points and so we use the terms inter-changeably.
NOTE: These mutations and queries will only work when used with a valid customer ID and apiKey which should be received during user authentication.
EMAIL all queries that use:
where: {customer: {id: {_eq: "[customer id]"}
can also use:
where: {customer: {email: {_eq: "[customer email]"}
Collecting Stamps
Stamps can be awarded simply with an API call specifying the number of stamps to award, the user to award them to and the store they are being awarded from using the steps below:
mutation MyMutation {
stampCustomerLoyaltyCard(customerId: "2094c04e-a9b7-4cd0-b75f-f25b1cfabc1d", stampsPerScan: 1, storeId: "f9f16886-75f1-43f0-9a7a-1316e84259d2", code: "e05ba37613e72877746ef896eb9a4db4") {
earnedRewardsCount
earnedRewardMessages
}
}
A note on the variables:
- customer ID is obtained from the QR scan
- StampsPerScan is how many stamps we're giving the user, this needs to be calculated by before the mutation is sent. To calculate Stamps Per Scan you need to know the loyalty programmes being run and their details, an API call for that is below.
- Store ID and Code will be provided by slerp.
Success returns:
{
"data": {
"stampCustomerLoyaltyCard": {
"earnedRewardMessages": [
"Thanks, this Dragon Roll is free",
"Thanks, this Dragon Roll is free",
"Thanks, this Dragon Roll is free",
"Thanks, this Dragon Roll is free"
],
"earnedRewardsCount": 4
}
}
}
The earnedRewardCount is the number of new rewards earned and the earned reward messages is an array of messages for each reward earned.
Redeeming Rewards
To redeem a reward in-store we first have to get the details of the rewards the current user has. A way to do that is with this query:
Get Rewards
You can get all rewards for a customer in isolation with a query like this:
query GetRewards {
customer_rewards(where: {customer: {id: {_eq: "[customer id]"}, merchant: {id: {_eq: "[merchant ID]"}}}, archived_at: {_is_null: true}, reward: {archived_at: {_is_null: true}}, redeemed_at: {_is_null: true}}) {
id
redeemed_at
required_quantity
reward {
description
name
required_quantity
loyalty_card_id
loyalty_card {
code
name
image
description
ends_at
}
reward_value
reward_value_type
product_ids
product_limit
redeem_reward_message
reward_type
}
}
}
A response will look like:
{
"data": {
"customer_rewards": [
{
"id": "78365907-19ae-46f9-a93f-130a5e889f72",
"redeemed_at": null,
"required_quantity": 15,
"reward": {
"description": "claim any pastry free. Excludes the really big ones.",
"name": "1 Free pastry",
"required_quantity": 15,
"loyalty_card_id": null,
"loyalty_card": null,
"reward_value": 100,
"reward_value_type": "percentage",
"product_ids": [
"cbf43771-e13b-465f-b59d-51888e121f2e",
"662c0ebd-5872-4ba7-89a2-fab57ae55f59",
"8296e828-94a1-4bf3-94e2-c905006e635a",
"59bdfdef-b00f-44b7-aa24-3c3ff06c8db6"
],
"product_limit": 1,
"redeem_reward_message": null,
"reward_type": "product"
}
},
{
"id": "ad646e18-a2e6-43ce-bc7f-a4208d4d6a51",
"redeemed_at": "2022-04-19T10:20:30.499848",
"required_quantity": 9,
"reward": {
"description": "Claim any coffee Free, excludes cold drinks. and make this longer",
"name": "1 Free Coffee let's make this a bit long",
"required_quantity": 9,
"loyalty_card_id": "74c7479b-9051-4de9-bc25-baa242acfb1d",
"loyalty_card": {
"code": "3e826732039150d2f9c0014d26815597",
"name": "Origin Loyalty Card",
"image": "origin.png?63806270389",
"description": "Collect stamps and earn rewards just making this longer for testing Lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem",
"ends_at": null
},
"reward_value": 100,
"reward_value_type": "percentage",
"product_ids": [
"5bd53ab3-7098-4a7f-b82e-da83272b6aa4",
"1c17533f-dc05-4a44-9d7e-c372ac704b1a",
"1b517808-7164-4a10-8ac5-73a88a4016a0",
"190478eb-9be2-4a5a-8759-2c85d9998b64",
"1f38ee0f-5f6f-49e3-8664-b3f4ff5cae34",
"fe7e1cad-90d5-4136-a9af-318af22c2c92",
"7f6ed8c5-1500-4c23-a68f-6e0f60c3c2b4",
"d0c3816a-3d63-44ec-bed6-1cc671b51ffc",
"076fb68f-42ad-4837-8678-4e2ea0e07a2c",
"8cb159d9-dc76-4159-af0e-5fc6a7fef54b"
],
"product_limit": 1,
"redeem_reward_message": "REWARD, REDEEMED. Congratulations you've redeemed a free coffee!",
"reward_type": "product"
}
}
]
}
}
Or be empty if no rewards are available.
Or you can get a customer's loyalty cards and the associated rewards like this:
query CustomerCards {
customer_loyalty_cards(
where: {customer: {id: {_eq: "a01ae086-dc25-4ae3-851f-01a4c6edd915"}, merchant: {id: {_eq: "2ba090b2-d4dc-4fd1-ba5c-9e0b73586673"}}}}
) {
id
stamps_aggregate(where: {forfeited_at: {_is_null: true}}) {
aggregate {
count
}
}
loyalty_card_id
customer_rewards {
archived_at
redeemed_at
id
reward_id
}
}
}
Response:
{
"data": {
"customer_loyalty_cards": [
{
"id": "ebdf1c03-9271-4946-b421-826091ea8528",
"stamps_aggregate": {
"aggregate": {
"count": 18
}
},
"loyalty_card_id": "74c7479b-9051-4de9-bc25-baa242acfb1d",
"customer_rewards": [
{
"archived_at": null,
"redeemed_at": "2022-04-28T07:32:26.617895",
"id": "d0fc8ba1-4f82-4fad-856d-601be3569c4d",
"reward_id": "20b383b7-b541-4b89-a779-c4c79e2f7e7d"
},
{
"archived_at": null,
"redeemed_at": null,
"id": "c005af63-84af-4bb5-b5a8-37aa3c42c13d",
"reward_id": "a250a0fc-9f4a-4859-a612-66866bc87537"
},
{
"archived_at": null,
"redeemed_at": "2022-05-10T13:32:49.367303",
"id": "e3aa4d12-ca29-4c82-a7f3-0d85765c555f",
"reward_id": "dd92e510-de1f-4ae8-9dae-04b59efe52a7"
}
]
},
{
"id": "71d70dc5-e6b9-4ed4-8b47-5e9642d5eee2",
"stamps_aggregate": {
"aggregate": {
"count": 2
}
},
"loyalty_card_id": "720ab7fa-27da-452a-b4d3-38d572601754",
"customer_rewards": []
}
]
}
}
Redeem the reward
Once a reward has been accepted it can be redeemed using this mutation:
mutation {
redeemCustomerReward(code: "loyalty-card-code", customerRewardId: "customer-reward-id") {
id
}
}
The loyalty-card-code can be found in sample variables above eg: fb5967a812482eb67dece2271d01e10a. The customer reward ID must be taken from the customer reward queried above in GetRewards.
Success returns:
{
"data": {
"redeemCustomerReward": {
"id": "2dbc0192-e638-44a7-8997-7d64c284ed8e"
}
}
}
Fail returns:
{
"data": {
"redeemCustomerReward": null
},
"errors": [
{
"locations": [
{
"column": 0,
"line": 2
}
],
"message": "Loyalty card not found",
"path": [
"redeemCustomerReward"
]
}
]
}