stripe#
Stripe API client for OCaml.
Minimal Stripe API client for SaaS billing: customers, products, prices, subscriptions, checkout sessions, billing portal, and webhook verification. Uses requests for HTTP and jsont for JSON codecs.
Installation#
Install with opam:
$ opam install stripe
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install stripe
Usage#
let create_subscription ~session =
let cfg = Stripe.config ~secret_key:"sk_test_..." session in
let customer = Stripe.Customer.create cfg ~email:"user@example.com" () in
let sub =
Stripe.Subscription.create cfg ~customer:customer.id ~price:"price_..." ()
in
Fmt.pr "Subscription %s: %s@." sub.id sub.status
let handle_webhook ~secret ~payload ~signature =
match Stripe.Webhook.verify_signature ~secret ~payload ~signature with
| Ok event -> Fmt.pr "Event: %s@." event.event_type
| Error msg -> Fmt.epr "Invalid: %s@." msg
API Overview#
config-- Create API configuration with secret key + HTTP sessionCustomer--create,retrieve,listProduct--create,retrievePrice--create(one-time or recurring)Subscription--create,retrieve,cancelCheckout--createcheckout sessionsPortal--createbilling portal sessionsWebhook--verify_signature(HMAC-SHA256 with timestamp tolerance)exception Stripe_error-- Raised on 4xx/5xx API errors
License#
MIT