用户输入券码后在浏览器调用 redeemCoupon。不可用时返回 reason,如 outside_window、limit_reached、sold_out。
import { createLongplay } from "@tinkerlandai/longplay-sdk"; const longplay = createLongplay({ baseUrl: "https://api.longplayai.com", scope: { projectId: "<APP_UUID>", environment: "sandbox" },}); type UUID = ReturnType<typeof crypto.randomUUID>; export async function redeem(customerToken: string, code: string, requestId: UUID) { longplay.identify(customerToken); const { offer, reason } = await longplay.redeemCoupon(code, requestId); if (!offer) return { ok: false as const, reason }; const offers = await longplay.listOffers(); return { ok: true as const, offers };}