Enrol a customer
Create the customer and put them straight onto a card. The response carries the Apple Wallet and Google Wallet links, so you can send them yourself.
customer, err := leal.Customers.Create(ctx, &api.CreateCustomersRequest{
AccountID: storeID,
Customer: &api.CreateCustomersRequestCustomer{
FirstName: "Ada",
Email: api.String("ada@example.com"),
},
CardID: api.Int(cardID),
}) Add a stamp
The call most integrations need. Leal records the stamp, updates the wallet pass and sends the notification.
card, err := leal.CustomerCards.Stamp(ctx, &api.StampCustomerCardsRequest{
AccountID: storeID,
CustomerID: customerID,
ID: customerCardID,
Stamps: 1,
}) Redeem a reward
Spend the stamps a customer has earned. Leal checks the reward is available before recording the redemption.
_, err := leal.CustomerCards.Redeem(ctx, &api.RedeemCustomerCardsRequest{
AccountID: storeID,
CustomerID: customerID,
ID: customerCardID,
RewardID: rewardID,
}) Handle a failure
Errors work with errors.As and carry the status code, so you can tell a missing record from a rate limit without reading strings.
if err != nil {
var apiError *core.APIError
if errors.As(err, &apiError) && apiError.StatusCode == 429 {
// Wait for the seconds in the Retry-After header, then try again.
}
return err
}