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 = try await leal.customers.create(
accountId: storeId,
request: .init(
customer: CreateCustomersRequestCustomer(
firstName: "Ada",
email: "ada@example.com"
),
cardId: cardId
)
) Add a stamp
The call most integrations need. Leal records the stamp, updates the wallet pass and sends the notification.
let card = try await leal.customerCards.stamp(
accountId: storeId,
customerId: customerId,
id: customerCardId,
request: .init(stamps: 1)
) Redeem a reward
Spend the stamps a customer has earned. Leal checks the reward is available before recording the redemption.
_ = try await leal.customerCards.redeem(
accountId: storeId,
customerId: customerId,
id: customerCardId,
request: .init(rewardId: rewardId)
) Handle a failure
One error enum covers everything. A non-success response arrives as an HTTP error carrying the status code, separate from encoding and network cases.
do {
_ = try await leal.customerCards.stamp(
accountId: storeId, customerId: customerId, id: customerCardId,
request: .init(stamps: 1)
)
} catch let error as LealError {
if case .httpError(let httpError) = error, httpError.statusCode == 429 {
// Wait for the seconds in the Retry-After header, then try again.
}
throw error
}