Soroban smart contracts for recurring subscription payments on Stellar — Stripe Billing, native to Stellar.
A subscriber authorizes a spending cap and a billing interval once. A merchant can then pull a fixed amount each interval, but never more than authorized and never after the subscriber cancels.
- Try it in ten minutes
- The security model
- Contracts
- Quick start
- Testnet
- Layout
- Deployments
- FAQ
- Sister repositories
- Contributing
- Clone and test:
git clone https://github.com/stellar-sub/stellar-subscriptions-contracts
cd stellar-subscriptions-contracts
make test-
Read an invariant test: Open
contracts/subscription/src/test/invariant_cap.rsto see how the contract enforces "never charge more than authorized." -
Verify on Testnet:
make testnet-deploy
make testnet-integrationNext: See CONTRIBUTING.md to add features without weakening the invariants.
The subscriber grants a bounded, revocable authorization; the merchant pulls within it. Three invariants must always hold, and each has tests that prove it:
- CAP — the total ever charged never exceeds the authorized
total_cap. - INTERVAL — at most one charge per billing interval, even for the right merchant.
- REVOCATION — once the subscriber cancels, no charge succeeds, ever.
Those tests were written before the implementation. A property-based fuzz test also checks all three after every step of random charge, pause, resume and cancel sequences. See docs/subscription.md for how each one is enforced.
| Contract | Path | Role |
|---|---|---|
| Subscription | contracts/subscription |
Authorization, charging, pause / resume / cancel. Enforces the invariants. Docs |
| Plan | contracts/plan |
Merchants' reusable billing terms. Docs |
| Registry | contracts/registry |
Index of plans and subscriptions with aggregate stats. Docs |
flowchart LR
S[Subscriber] -- subscribe / pause / resume / cancel --> SUB[Subscription]
M[Merchant] -- create_plan --> PLAN[Plan]
M -- charge --> SUB
SUB -- get_plan at subscribe --> PLAN
SUB -- transfer_from --> T[(Token)]
SUB -- register / update --> REG[Registry]
PLAN -- register_plan --> REG
Only the subscriber can pause, resume or cancel. Only the merchant can charge. The admin can link the three contracts once, before first use, and nothing else.
# Prerequisites: Rust (pinned by rust-toolchain.toml) and the stellar CLI
make test # every contract's test suite, including the invariant tests
make build # wasm via stellar contract build
make check # everything CI runs: test, clippy, fmt, wasm build
make deploy # deploy + initialize + link on Testnet
make testnet-deploy # deploy on Testnet with DEMO=1 defaults
make testnet-integration # source examples/env.sh and verify invariants on TestnetTwo convenience make targets wrap the end-to-end Testnet deployment and live
invariant verification workflow:
-
make testnet-deploy— runsscripts/deploy.shwith sensible Testnet defaults (NETWORK=testnet,IDENTITY=subs-deployer,DEMO=1). It builds the contracts, deploys and initializesplan,registry, andsubscription, performs the one-shot contract linking, seeds the demo identities/plan/subscription, and writes the deployment variables to.deployments/testnet.env.make testnet-deploy # Override defaults if needed: make testnet-deploy NETWORK=testnet IDENTITY=my-deployer DEMO=1 -
make testnet-integration— sourcesexamples/env.shto load and validate the deployed contract IDs and demo identities from.deployments/<network>.env, then invokesscripts/verify-testnet.shto prove theCAP,INTERVAL, andREVOCATIONinvariants on-chain against the live Testnet deployment.make testnet-integration
contracts/
subscription/ core subscription + authorization logic
plan/ merchant billing plans
registry/ index of plans and subscriptions
docs/ per-contract reference
subscription.md contract reference and charge() walkthrough
plan.md plan contract reference
registry.md registry contract reference
errors.md how to read a failed transaction and map it to an error code
scripts/deploy.sh deploy, initialize and link all three
DEPLOYMENTS.md live contract ids
Testnet contract ids are in DEPLOYMENTS.md.
Symptoms. The merchant's charge call fails with TransferFailed (see
docs/errors.md for how to read the failed transaction).
Cause. The subscriber's token allowance has expired. charge pulls funds
via transfer_from, which requires a live allowance from the subscriber to
the subscription contract. Allowances are time-bounded, so once the allowance
lapses every subsequent charge fails with TransferFailed — even though the
subscription itself is still active and within its total_cap.
Fix. The subscriber calls refresh_allowance on the subscription contract
to re-grant the token allowance. The next charge then succeeds as normal.
Nothing is lost. A failed charge makes no state changes: no balance moves, the charged total is unchanged, and the billing interval is not consumed. Once the allowance is refreshed, the merchant can charge again on the normal schedule — no back-charges or manual reconciliation are needed.
Issue #239 (re-calling initialize with the same admin is rejected) is already
covered on main. initialize returns AlreadyInitialized whenever an admin is
stored, and initialize_twice_is_rejected in
contracts/subscription/src/test/validation.rs (also in the subscription test
for a different admin), contracts/plan/src/test.rs and
contracts/registry/src/test.rs calls try_initialize(&s.admin) with the
original admin. No code change is needed.
- Web app: https://github.com/stellar-sub/stellar-subscriptions-web
- API + Docs: https://github.com/stellar-sub/stellar-subscriptions-api-docs
See CONTRIBUTING.md, in particular the section on adding features without weakening the invariants.
- #238: Test: initialize called twice on registry and plan contracts returns AlreadyInitialized
The subscription contract's RegistryInterface::register_subscription
(contracts/subscription/src/interfaces.rs) and the registry's
register_subscription (contracts/registry/src/lib.rs) both take
subscription_id, subscriber, merchant, token, so the signatures are aligned
on main. The end-to-end subscribe-with-registry path is covered by
the_registry_mirrors_the_full_lifecycle in
contracts/subscription/src/test/integration.rs. The only change made is
removing duplicated subscriber/merchant fields in the registry's
SubscriptionRecord literal inside register_subscription.