sub_id.
Parameters
Authorization
subscribe() contract call and the nested token.approve() call. Soroban’s auth tree bundles both operations into one authorization.
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)
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
- SDK
- Soroban CLI
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.