| title | refund |
|---|---|
| description | Issues a partial or full refund to a subscriber. The merchant authorizes a transfer from their own wallet, recorded on-chain as a verifiable receipt. |
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.
| Name | Type | Description |
|---|---|---|
sub_id |
u64 |
The subscription ID to refund. |
amount |
i128 |
The refund amount in stroops. |
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().
None (void).
| Event | Topics | Data |
|---|---|---|
refund |
subscriber, sub_id, amount |
Refund details |
| Code | Name | Description |
|---|---|---|
| 8 | SubNotFound |
No subscription exists with the given sub_id. |
```typescript import { VowenaClient, NETWORKS, toStroops } from "@vowena/sdk";
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);
```