···325325 c.status)
326326 |> Jsont.Object.finish
327327328328- let create cfg ~customer ~price ~success_url ~cancel_url () =
328328+ let create cfg ?customer ?customer_email ~price ~success_url ~cancel_url () =
329329 let body =
330330 [
331331- ("customer", customer);
332331 ("mode", "subscription");
333332 ("line_items[0][price]", price);
334333 ("line_items[0][quantity]", "1");
335334 ("success_url", success_url);
336335 ("cancel_url", cancel_url);
337336 ]
337337+ @ (match customer with Some c -> [ ("customer", c) ] | None -> [])
338338+ @
339339+ match customer_email with
340340+ | Some e -> [ ("customer_email", e) ]
341341+ | None -> []
338342 in
339343 post cfg "/checkout/sessions" body |> decode jsont
344344+345345+ let retrieve cfg id = get cfg ("/checkout/sessions/" ^ id) [] |> decode jsont
340346end
341347342348(* {1 Billing Portal} *)
+16-4
lib/stripe.mli
···148148module Checkout : sig
149149 type t = {
150150 id : string;
151151- url : string; (** URL to redirect customer to. *)
151151+ url : string; (** URL to redirect customer to (empty after completion). *)
152152 customer : string;
153153 subscription : string;
154154- status : string;
154154+ status : string; (** "open", "complete", or "expired". *)
155155 }
156156157157 val pp : t Fmt.t
···162162163163 val create :
164164 config ->
165165- customer:string ->
165165+ ?customer:string ->
166166+ ?customer_email:string ->
166167 price:string ->
167168 success_url:string ->
168169 cancel_url:string ->
169170 unit ->
170171 t
171171- (** Create a checkout session for a subscription. *)
172172+ (** Create a checkout session for a subscription.
173173+174174+ Pass [~customer] for existing customers or [~customer_email] for new
175175+ signups. If neither is provided, Stripe collects the email during
176176+ checkout. The [success_url] may contain [{CHECKOUT_SESSION_ID}] which
177177+ Stripe replaces with the session ID on redirect. *)
178178+179179+ val retrieve : config -> string -> t
180180+ (** [retrieve config session_id] fetches a checkout session.
181181+182182+ Use this on the success redirect to verify [status = "complete"] before
183183+ granting access. Never trust the redirect URL alone. *)
172184end
173185174186(** {1 Billing Portal} *)