Skip to content

Subscription and recurring billing logic#158

Merged
codebestia merged 7 commits intoShadeProtocol:mainfrom
Ogstevyn:Subscription-and-Recurring-Billing-Logic
Feb 27, 2026
Merged

Subscription and recurring billing logic#158
codebestia merged 7 commits intoShadeProtocol:mainfrom
Ogstevyn:Subscription-and-Recurring-Billing-Logic

Conversation

@Ogstevyn
Copy link
Contributor

Subscription Engine — Recurring Billing for Merchants

Summary

Implements a Stripe-like recurring billing system on Soroban using a pull model. Merchants can create billing plans, customers can subscribe, and an authorized caller (merchant or bot) triggers charges once the billing interval has elapsed.

New Files

  • contracts/shade/src/components/subscription.rs — full subscription engine implementation

Modified Files

  • types.rs — added SubscriptionPlan, Subscription, SubscriptionStatus structs and SubscriptionPlan(u64), Subscription(u64), PlanCount, SubscriptionCount DataKey variants
  • events.rs — fixed existing conflicts/incomplete sections; added SubscriptionPlanCreated, Subscribed, SubscriptionCharged, SubscriptionCancelled events
  • interface.rs — added 6 new methods to ShadeTrait: create_subscription_plan, get_subscription_plan, subscribe, get_subscription, charge_subscription, cancel_subscription
  • errors.rs — added 8 new error variants: NotFound, InvalidAmount, InvalidInterval, PlanNotActive, SubscriptionNotActive, IntervalNotElapsed, MerchantNotFound, MerchantAccountNotFound
  • shade.rs — wired subscription functions into the contract impl block
  • components/mod.rs — registered new subscription module

How It Works

Function Who Calls It What It Does
create_subscription_plan Merchant Creates a billing plan with token, amount, and interval
subscribe Customer Subscribes to a plan; customer must pre-approve token allowance
charge_subscription Anyone (merchant/bot) Pulls funds via transfer_from if interval has elapsed
cancel_subscription Customer or Merchant Cancels the recurring billing

Fee Model

Mirrors the existing invoice fee logic — fee is read in basis points from FeeInBasisPoints(token), deducted from the charge amount, and sent to the Shade contract. The net amount goes to the merchant's account contract.

Closes

closes #87

@codebestia codebestia merged commit d6ec238 into ShadeProtocol:main Feb 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Subscription and Recurring Billing Logic

2 participants