Skip to main content
Subscribes a user to an existing plan. This function creates the subscription record and sets the SEP-41 token allowance in a single transaction. The subscriber signs once and both operations are authorized. Returns the auto-incremented sub_id.

Parameters


Authorization

The subscriber’s single signature covers both the subscribe() contract call and the nested token.approve() call. Soroban’s auth tree bundles both operations into one authorization.
The subscriber signs once. Their wallet will display exactly what is being authorized: the Vowena contract call and the token allowance (amount = price_ceiling * periods, spender = Vowena contract). No hidden permissions. Full transparency.

Allowance calculation

The contract calculates the token allowance as:
  • If max_periods > 0: periods_for_approval = max_periods
  • If max_periods = 0 (unlimited): periods_for_approval = 120
  • Allowance expiry is capped at 6,000,000 ledgers (~347 days)
The allowance is set against the plan’s price_ceiling, not the current amount. This means the merchant can adjust pricing within the ceiling without requiring re-authorization.

Return value

u64 - the newly created subscription ID.

Events emitted


Error cases


Examples

If the plan has trial periods, the subscription starts immediately but billing begins after the trial ends. The next_billing_time is set to now + (period * (trial_periods + 1)) so the first real charge happens after the trial.