examples/storefront Public
// A Payments stand-in that records what checkout asked for. Set `failNext` to make the next// createIntent throw, as when the provider times out, and add an intent to `uncancellable` to// play one that was paid at the last moment.import type { Charge, Intent, Payments } from "../../src/payments.ts";export class FakePayments implements Payments { readonly charges: Charge[] = []; readonly cancelled: string[] = []; readonly uncancellable = new Set<string>(); // intents that already succeeded at Stripe failNext = false; async createIntent(c: Charge): Promise<Intent> { if (this.failNext) { this.failNext = false; throw new Error("connect ETIMEDOUT"); } this.charges.push(c); return { id: `pi_${c.order_id}`, client_secret: `pi_${c.order_id}_secret` }; } async cancelIntent(intentId: string): Promise<boolean> { if (this.uncancellable.has(intentId)) return false; this.cancelled.push(intentId); return true; }}