Stripe API client for OCaml
0
fork

Configure Feed

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

OCaml 93.4%
Dune 2.1%
Other 4.4%
23 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-stripe https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-stripe
git@git.recoil.org:gazagnaire.org/ocaml-stripe git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-stripe

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

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 session
  • Customer -- create, retrieve, list
  • Product -- create, retrieve
  • Price -- create (one-time or recurring)
  • Subscription -- create, retrieve, cancel
  • Checkout -- create checkout sessions
  • Portal -- create billing portal sessions
  • Webhook -- verify_signature (HMAC-SHA256 with timestamp tolerance)
  • exception Stripe_error -- Raised on 4xx/5xx API errors

License#

MIT