Skip to main content
fn cancel(env: Env, caller: Address, sub_id: u64)
Cancels a subscription. Cancellation is immediate and irreversible. The subscription status is set to Cancelled and no further charges can be processed. Either the subscriber or the merchant who owns the plan can cancel.

Parameters

NameTypeDescription
callerAddressThe address initiating the cancellation. Must be the subscriber or the merchant.
sub_idu64The subscription ID to cancel.

Authorization

caller.require_auth();
The caller must be either:
  • The subscriber on the subscription, or
  • The merchant on the plan the subscription belongs to.
Any other caller will fail with Unauthorized.

Return value

None (void).

Events emitted

EventTopicsData
sub_cancelsubscriber, sub_idcancelled_at timestamp

Error cases

CodeNameDescription
8SubNotFoundNo subscription exists with the given sub_id.
9UnauthorizedCaller is neither the subscriber nor the merchant.

Examples

import { VowenaClient, NETWORKS } from "vowena";

const client = new VowenaClient({
  contractId: NETWORKS.testnet.contractId,
  rpcUrl: NETWORKS.testnet.rpcUrl,
  networkPassphrase: NETWORKS.testnet.networkPassphrase,
});

// Subscriber cancels their own subscription
const tx = await client.buildCancel(
  "GSUBSCRIBER...ADDR",   // Subscriber or merchant address
  subscriptionId           // Subscription ID
);

const signedXdr = await signTransaction(tx);
await client.submitTransaction(signedXdr);
Cancellation does not issue a refund. If the merchant wants to refund remaining time, they should call refund() separately. The token allowance remains on-chain but becomes irrelevant since the contract will never call transfer_from on a cancelled subscription.