This article shares a possible use case your app or site could support, as well as a sample flow that could support it. This can be a helpful jumping-off point as you plan your app's implementation.
This flow creates a rewards program for new members at a gym.
This flow implements the following functionality.
This flow has the following prerequisites.
Note: This article only specifies parameters required for this flow. For each API call, refer to the API reference to see the full list of parameters.
First, create a program definition, to which you'll add a pool definition in Step 2. This program definition serves as a template for each new member's program, created in Step 4.
To create a program definition, call Create Program Definition, specifying the following parameters:
namespace
: Your benefit programs' namespace.externalProgramId
: This can be whatever you want, but it must be unique in your app or site.Save the program definition's ID included in the response.
Note: This step could be omitted for this flow, and in Step 4 the program could be created from the pool definition created in Step 2. However, we are creating a program definition so that more pool definitions could be added to the program definition in future.
Next, create a pool definition, which serves as a template for the pool in each new member's program, which you'll create in Step 4.
You need to specify an array of benefits and credit configuration in substep 3 of this step. In this flow, we have broken it out into different substeps, but you may skip straight to substep 3 and define the benefits array and credit configuration in the API call.
To create a pool definition:
benefitKey
: We can define each however we want. Let's call them gym10
, gym20
, and gym30
.price
: 10
, 20
, and 30
.providerAppId
: The Wix Stores app ID: 215238eb-22a5-4c36-9e7b-e7c08025e04e
creditConfiguration
object. Specify the following fields:
amount
: 0
. Indicates that new members start with 0 tokens.rolloverConfiguration.enabled
: true
. Indicates that members can roll over tokens.rolloverConfiguration.balanceCap
: 5
. Indicates that members can roll over up to 5 tokens.unitDisplayName
: Tokens
. Defines the display unit for the credits.poolDefinition
parameters:
programDefinitionIds
: An array containing the ID of the program definition created in Step 1.details.benefits
: The benefits
array defined earlier in this step.details.creditConfiguration
: The creditConfiguration
object defined earlier in this step.namespace
: Your benefit programs' namespace.
Save each benefit's itemSetId
included in the response.Next, create benefit items and assign them to benefits in the pool definition created in the previous step. The gym merchandise already exists as products. This step associates each product with a specific benefit in the pool definition.
To create benefit items and add them to the benefits created in Step 2:
items
array for each piece of gym merchandise:
externalId
: The product ID retrieved from Wix Stores.itemSetId
: Use the itemSetId
from the relevant benefit, saved in Step 2.providerAppId
: The Wix Stores app ID: 215238eb-22a5-4c36-9e7b-e7c08025e04e
namespace
: Your benefit programs' namespace.Next, write code that runs each time a new member joins the gym. The code should:
When a new member joins the gym:
poolDefinitionLookupId.programDefinitionId
: The ID of the program definition created in Step 1.beneficiary.memberId
: The new member's site member ID.namespace
: Your benefit programs' namespace.externalProgramId
: This can be whatever you want, but it must be unique in your app or site. To ensure uniqueness, use a combination of the programDefinitionID
and memberId
. For example, <programDefinitionID>_<memberId>
.
Save the program's ID included in the response.Next, write code that runs each time a new member visits the gym. The code should retrieve the member's pool's ID, checking whether there is an active pool when doing so. If an active pool exists, the member is a new member. Then, use the pool ID to update the pool's associated balance.
When a member visits the gym, use their site member ID to issue a token:
beneficiary.memberId
, namespace
, and whether status
is ACTIVE
. poolId
: The ID of the pool retrieved earlier in this step.idempotencyKey
: Generate a GUID. Use the same string if you repeat the call due to an error.adjustOptions.value
: 1
. Increases the pool's balance by 1 token.
In this step, you've added code to issue a token to each member every time they visit the gym.Next, write code that displays to members all the benefits they can redeem. To check this, you need to retrieve:
When a member logs in to the site:
beneficiary.memberId
, namespace
, and whether status
is ACTIVE
. details.benefits
.namespace
: Your benefit programs' namespace.benefitSelectors
: An array of objects representing the items created in Step 3. For each object, specify the following parameters:
poolId
: ID of the pool retrieved earlier in this step.itemReference.externalId
: The product ID retrieved from Wix Stores. You can use Query Products to retrieve the products.itemReference.providerAppId
: The Wix Stores app ID: 215238eb-22a5-4c36-9e7b-e7c08025e04e
results.result.eligibleOptions.eligibleBenefits
is an array of items that can be redeemed.
externalId
of each redeemable item, retrieve the redeemable gym merchandise products from Wix Stores using Query Products. Display the items in a way that allows the site member to select one.Next, handle the flow if a site member selects an item to redeem.
If the site member selects an item to redeem:
externalId
and the Wix Stores providerAppId
, 215238eb-22a5-4c36-9e7b-e7c08025e04e
. There should be 1 item in the response. Save this item's itemSetId
.itemSetId
as the selected item. Save this benefit's benefitKey
and price
.poolId
: ID of the pool retrieved in Step 6.itemReference.externalId
: Item's externalId
retrieved in Step 6.itemReference.providerAppId
: The Wix Stores app ID: 215238eb-22a5-4c36-9e7b-e7c08025e04e
benefitKey
: Benefit key retrieved earlier in this step.idempotencyKey
: Generate a GUID. Use the same string if you repeat the call due to an error.namespace
: Your benefit programs' namespace.Note: Redeeming a benefit automatically deducts the benefit's price from the pool's associated balance.