Skip to main content
fn refund(env: Env, sub_id: u64, amount: i128)
Refunds a subscriber by transferring tokens from the merchant’s wallet to the subscriber’s wallet. The refund is a direct transfer call - the merchant pays from their own balance, not from the contract.

Parameters

NameTypeDescription
sub_idu64The subscription ID to refund.
amounti128The refund amount in stroops.

Authorization

merchant.require_auth();
The merchant address on the subscription’s plan must sign the transaction. The merchant’s auth covers both the refund() call and the nested token.transfer().

Return value

None (void).

Events emitted

EventTopicsData
refundsubscriber, sub_id, amountRefund details

Error cases

CodeNameDescription
8SubNotFoundNo subscription exists with the given sub_id.

Examples

import { VowenaClient, NETWORKS, toStroops } from "vowena";

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

// Merchant refunds 5.00 USDC to the subscriber
const tx = await client.buildRefund(
  subscriptionId,          // Subscription ID
  toStroops("5.00")        // 50000000n stroops
);

const signedXdr = await signTransaction(tx);
await client.submitTransaction(signedXdr);
The refund amount is not validated against previous charges. The merchant can refund any amount they choose, including partial refunds. The merchant must have sufficient token balance to cover the refund.