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 = leal.customers.create(
account_id: store_id,
customer: { first_name: "Ada", email: "ada@example.com" },
card_id: card_id
)
card = customer.customer_cards.first
puts 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
)
puts "#{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
Failures raise typed errors you can rescue one at a time, so a rate limit does not look like a missing record.
begin
leal.customer_cards.stamp(
account_id: store_id, customer_id: customer_id, id: customer_card_id, stamps: 1
)
rescue Leal::Errors::ResponseError => error
# Wait for the seconds in the Retry-After header, then try again.
raise unless error.code == 429
end