Initial call by customer. Bundles approval + first payment + subscription creation.
duration is in seconds (e.g. 86400 = 1 day, 3600 = 1 hour for custom periods).
fn start(
env: soroban_sdk::Env,
customer: soroban_sdk::Address,
merchant: soroban_sdk::Address,
token: soroban_sdk::Address,
product_id: soroban_sdk::String,
amount: i128,
duration: u64,
caller: soroban_sdk::Address,
)
Called by backend/cron when the billing period ends.
amount is computed off-chain from current fiat/crypto rates each cycle.
Panics on insufficient funds — period_end is NOT advanced on failure.
fn charge(
env: soroban_sdk::Env,
customer: soroban_sdk::Address,
product_id: soroban_sdk::String,
amount: i128,
)
fn pause(
env: soroban_sdk::Env,
customer: soroban_sdk::Address,
product_id: soroban_sdk::String,
caller: soroban_sdk::Address,
)
Resume a paused subscription. If the paused period already expired, resets period_end from now so the customer gets a full cycle without immediately triggering charge.
fn resume(
env: soroban_sdk::Env,
customer: soroban_sdk::Address,
product_id: soroban_sdk::String,
caller: soroban_sdk::Address,
)
fn cancel(
env: soroban_sdk::Env,
customer: soroban_sdk::Address,
product_id: soroban_sdk::String,
caller: soroban_sdk::Address,
)
Admin / backend override. Validates status and guards against zero duration.
fn update(
env: soroban_sdk::Env,
customer: soroban_sdk::Address,
product_id: soroban_sdk::String,
status: soroban_sdk::String,
period_duration: u64,
period_end: u64,
caller: soroban_sdk::Address,
)
fn get_subscription(
env: soroban_sdk::Env,
customer: soroban_sdk::Address,
product_id: soroban_sdk::String,
) -> Subscription