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.
let customer = leal
.customers
.create(
store_id,
&CreateCustomersRequest {
customer: CreateCustomersRequestCustomer {
first_name: "Ada".to_string(),
email: Some("ada@example.com".to_string()),
..Default::default()
},
card_id: Some(card_id),
..Default::default()
},
None,
)
.await?; Add a stamp
The call most integrations need. Leal records the stamp, updates the wallet pass and sends the notification.
let card = leal
.customer_cards
.stamp(
store_id,
customer_id,
customer_card_id,
&StampCustomerCardsRequest {
stamps: 1,
skip_notifications: None,
},
None,
)
.await?; Redeem a reward
Spend the stamps a customer has earned. Leal checks the reward is available before recording the redemption.
leal.customer_cards
.redeem(
store_id,
customer_id,
customer_card_id,
&RedeemCustomerCardsRequest { reward_id },
None,
)
.await?; Handle a failure
Failures come back as an ApiError you can match on, so a rate limit is a distinct arm rather than a string to parse.
match leal.customer_cards.stamp(store_id, customer_id, customer_card_id, &request, None).await {
Ok(card) => println!("{} stamps to the next reward", card.stamps_remaining),
Err(ApiError::HTTP { status: 429, .. }) => {
// Wait for the seconds in the Retry-After header, then try again.
}
Err(error) => return Err(error.into()),
}