Skip to content

Latest commit

 

History

History
97 lines (71 loc) · 2.49 KB

File metadata and controls

97 lines (71 loc) · 2.49 KB
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.


Parameters

Name Type Description
sub_id u64 The subscription ID to refund.
amount i128 The 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

Event Topics Data
refund subscriber, sub_id, amount Refund details

Error cases

Code Name Description
8 SubNotFound No subscription exists with the given sub_id.

Examples

```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);
```
```bash soroban contract invoke \ --id CONTRACT_ID \ --network testnet \ --source MERCHANT_SECRET \ -- \ refund \ --sub_id 1 \ --amount 50000000 ``` 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.