1import type {
2 CheckoutSession,
3 CreateCheckoutSessionError,
4 CreateCheckoutSessionRequest,
5} from "@distilled.cloud/stripe/stripe";
6import type * as Effect from "effect/Effect";
7import * as Binding from "../Binding.ts";
8import type { RuntimeContext } from "../RuntimeContext.ts";
9
10/**
11 * Create a Stripe Checkout Session over HTTP. This is how a Worker starts
12 * a purchase: create the session for a Price, then redirect the buyer to
13 * `session.url`. Stripe hosts the payment page and sends
14 * `checkout.session.completed` when it succeeds.
15 *
16 * Account-scoped — binds the API key onto the host, not a specific
17 * resource.
18 *
19 * ### Starting a subscription checkout
20 * **Example:** Redirect a buyer to hosted Checkout
21 * ```typescript
22 * const createCheckout = yield* Stripe.CreateCheckoutSession();
23 *
24 * // inside a Worker route
25 * const session = yield* createCheckout({
26 * mode: "subscription",
27 * line_items: [{ price: price.id, quantity: 1 }],
28 * customer: customerId,
29 * success_url: `${origin}/welcome`,
30 * cancel_url: `${origin}/pricing`,
31 * });
32 * // redirect to session.url
33 * ```
34 *
35 * @binding
36 * @product Checkout
37 */
38export interface CreateCheckoutSession extends Binding.Service<
39 CreateCheckoutSession,
40 "Stripe.CreateCheckoutSession",
41 () => Effect.Effect<
42 (
43 request: CreateCheckoutSessionRequest,
44 ) => Effect.Effect<
45 CheckoutSession,
46 CreateCheckoutSessionError,
47 RuntimeContext
48 >
49 >
50> {}
51
52export const CreateCheckoutSession = Binding.Service<CreateCheckoutSession>(
53 "Stripe.CreateCheckoutSession",
54);