Manage Wallets with Go
Wallets hold balances for an account and currency. Meterry also exposes a realtime virtual wallet snapshot that includes cash, voucher, credit-limit, and usage-limit state.
Create a Wallet
Section titled “Create a Wallet”wallet, err := client.Manager.CreateWalletForProject(ctx, "proj_gateway", types.CreateWalletRequest{ AccountID: "acct_001", Currency: "USD", CreditLimit: decimal.RequireFromString("50"),})if err != nil { return err}
fmt.Println(wallet.ID, wallet.AvailableBalance)List Wallets
Section titled “List Wallets”List by account:
wallets, err := client.Manager.ListWallets(ctx, sdk.ListWalletsRequest{ ProjectID: "proj_gateway", AccountID: "acct_001",})List by subject route:
wallets, err := client.Manager.ListWallets(ctx, sdk.ListWalletsRequest{ ProjectID: "proj_gateway", SubjectType: "org", SubjectID: "org_001",})Read Realtime Wallet Amount
Section titled “Read Realtime Wallet Amount”snapshot, err := client.Manager.ReadVirtualWalletAmountForProject(ctx, "proj_gateway", types.ReadVirtualWalletRequest{ AccountID: "acct_001", Currency: "USD",})if err != nil { return err}
fmt.Println(snapshot.AvailableBalance, snapshot.CashAvailable, snapshot.VoucherAvailable)You can read by subject when a subject route exists:
snapshot, err := client.Manager.ReadVirtualWalletAmountForProject(ctx, "proj_gateway", types.ReadVirtualWalletRequest{ SubjectType: "org", SubjectID: "org_001", Currency: "USD",})Credit and Debit Wallets
Section titled “Credit and Debit Wallets”Use decimal values for money-sensitive amounts.
credit, err := client.Manager.CreditWalletForProject(ctx, "proj_gateway", types.CreditWalletRequest{ AccountID: "acct_001", Currency: "USD", Amount: decimal.RequireFromString("100"), SourceType: "manual_top_up", IdempotencyKey: "topup_001",})debit, err := client.Manager.DebitWalletForProject(ctx, "proj_gateway", types.DebitWalletRequest{ AccountID: "acct_001", Currency: "USD", Amount: decimal.RequireFromString("12.50"), SourceType: "manual_adjustment", IdempotencyKey: "debit_001",})To update credit limit:
wallet, err := client.Manager.SetWalletCreditLimitForProject(ctx, "proj_gateway", types.SetWalletCreditLimitRequest{ AccountID: "acct_001", Currency: "USD", CreditLimit: decimal.RequireFromString("250"),})List Ledger Entries
Section titled “List Ledger Entries”history, err := client.Manager.ListWalletLedgerEntries(ctx, types.ListWalletLedgerEntriesRequest{ ProjectID: "proj_gateway", AccountID: "acct_001", Currency: "USD", Limit: 50,})if err != nil { return err}
for _, entry := range history.LedgerEntries { fmt.Println(entry.Direction, entry.Amount, entry.BalanceAfter)}Voucher Grants
Section titled “Voucher Grants”Grant voucher balance:
grant, err := client.Manager.CreateVoucherGrantForProject(ctx, "proj_gateway", types.CreateVoucherGrantRequest{ AccountID: "acct_001", Currency: "USD", Amount: decimal.RequireFromString("20"), SourceType: "promo", SourceID: "campaign_001", IdempotencyKey: "voucher_001",})List grants:
grants, err := client.Manager.ListVoucherGrants(ctx, sdk.ListVoucherGrantsRequest{ ProjectID: "proj_gateway", AccountID: "acct_001", Currency: "USD", Limit: 20,})Revoke a grant:
revoked, err := client.Manager.RevokeVoucherGrantForProject(ctx, "proj_gateway", "vg_001")Supported Methods
Section titled “Supported Methods”| Area | Methods |
|---|---|
| Wallets | CreateWallet, CreateWalletForProject, ListWallets, ReadVirtualWalletAmountForProject, ReadRealtimeUsageControlLimitsForProject |
| Balance changes | CreditWallet, CreditWalletForProject, TopUpWallet, TopUpWalletForProject, DebitWallet, DebitWalletForProject, SetWalletCreditLimit, SetWalletCreditLimitForProject |
| Ledger | ListWalletLedgerEntries |
| Vouchers | CreateVoucherGrant, CreateVoucherGrantForProject, GrantVoucher, ListVoucherGrants, RevokeVoucherGrant, RevokeVoucherGrantForProject |