Stripe API client for OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Linter fixes: auth refactor, github-oauth merge, respond cleanup

+24 -6
+8 -2
lib/stripe.ml
··· 325 325 c.status) 326 326 |> Jsont.Object.finish 327 327 328 - let create cfg ~customer ~price ~success_url ~cancel_url () = 328 + let create cfg ?customer ?customer_email ~price ~success_url ~cancel_url () = 329 329 let body = 330 330 [ 331 - ("customer", customer); 332 331 ("mode", "subscription"); 333 332 ("line_items[0][price]", price); 334 333 ("line_items[0][quantity]", "1"); 335 334 ("success_url", success_url); 336 335 ("cancel_url", cancel_url); 337 336 ] 337 + @ (match customer with Some c -> [ ("customer", c) ] | None -> []) 338 + @ 339 + match customer_email with 340 + | Some e -> [ ("customer_email", e) ] 341 + | None -> [] 338 342 in 339 343 post cfg "/checkout/sessions" body |> decode jsont 344 + 345 + let retrieve cfg id = get cfg ("/checkout/sessions/" ^ id) [] |> decode jsont 340 346 end 341 347 342 348 (* {1 Billing Portal} *)
+16 -4
lib/stripe.mli
··· 148 148 module Checkout : sig 149 149 type t = { 150 150 id : string; 151 - url : string; (** URL to redirect customer to. *) 151 + url : string; (** URL to redirect customer to (empty after completion). *) 152 152 customer : string; 153 153 subscription : string; 154 - status : string; 154 + status : string; (** "open", "complete", or "expired". *) 155 155 } 156 156 157 157 val pp : t Fmt.t ··· 162 162 163 163 val create : 164 164 config -> 165 - customer:string -> 165 + ?customer:string -> 166 + ?customer_email:string -> 166 167 price:string -> 167 168 success_url:string -> 168 169 cancel_url:string -> 169 170 unit -> 170 171 t 171 - (** Create a checkout session for a subscription. *) 172 + (** Create a checkout session for a subscription. 173 + 174 + Pass [~customer] for existing customers or [~customer_email] for new 175 + signups. If neither is provided, Stripe collects the email during 176 + checkout. The [success_url] may contain [{CHECKOUT_SESSION_ID}] which 177 + Stripe replaces with the session ID on redirect. *) 178 + 179 + val retrieve : config -> string -> t 180 + (** [retrieve config session_id] fetches a checkout session. 181 + 182 + Use this on the success redirect to verify [status = "complete"] before 183 + granting access. Never trust the redirect URL alone. *) 172 184 end 173 185 174 186 (** {1 Billing Portal} *)