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.
from leal.customers import CreateCustomersRequestCustomer
customer = leal.customers.create(
account_id=store_id,
customer=CreateCustomersRequestCustomer(
first_name="Ada",
email="ada@example.com",
),
card_id=card_id,
)
card = customer.customer_cards[0]
print(card.apple_wallet_url, card.google_wallet_url) Add a stamp
The call most integrations need. Leal records the stamp, updates the wallet pass and sends the notification.
card = leal.customer_cards.stamp(
account_id=store_id,
customer_id=customer_id,
id=customer_card_id,
stamps=1,
)
print(card.stamps_remaining, "stamps to the next reward") Redeem a reward
Spend the stamps a customer has earned. Leal checks the reward is available before recording the redemption.
leal.customer_cards.redeem(
account_id=store_id,
customer_id=customer_id,
id=customer_card_id,
reward_id=reward_id,
) Handle a failure
Every failure raises a typed exception carrying the status code, so you can tell a missing record from a rate limit without reading strings.
from leal.core.api_error import ApiError
try:
leal.customer_cards.stamp(
account_id=store_id, customer_id=customer_id, id=customer_card_id, stamps=1
)
except ApiError as error:
if error.status_code == 429:
pass # Wait for the seconds in the Retry-After header, then try again.
raise