Wallets
Close a wallet
Close a wallet and settle its remaining balance — refund paid balance, forfeit promotional balance.
POST
/
v1
/
wallets
/
{id}
/
close
Close a wallet and settle its balance
curl --request POST \
--url https://billing.example.com/v1/wallets/{id}/close \
--header 'Authorization: Bearer <token>'import requests
url = "https://billing.example.com/v1/wallets/{id}/close"
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://billing.example.com/v1/wallets/{id}/close', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://billing.example.com/v1/wallets/{id}/close",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://billing.example.com/v1/wallets/{id}/close"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://billing.example.com/v1/wallets/{id}/close")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/wallets/{id}/close")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"data": {
"refunded": 123,
"forfeited": 123
},
"message": "<string>"
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}Path parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The wallet ID. |
- Paid balance (top-ups the customer funded) is refunded to the customer.
- Promotional balance (granted credit) is forfeited.
Example request
curl -X POST https://api.recurso.dev/v1/wallets/wal_8kQ2/close \
-H "Authorization: Bearer $API_KEY"
Example response
{
"data": {
"refunded": 30000,
"forfeited": 5000
},
"message": "wallet closed"
}
This can’t be undone. Once closed, the wallet’s balance is zero and it can no
longer be topped up or drained. Amounts are in the wallet currency’s smallest
unit.
Errors
| Status | Code | When | Fix |
|---|---|---|---|
400 | validation_failed | id in the path is not a UUID | Use the wallet’s UUID |
400 | validation_failed | The wallet is already closed (message: wallet is already closed) | Nothing to do — the balance was settled when it closed; treat as success |
403 | forbidden | The session user is not an owner or admin — closing refunds money out | Have an owner/admin close it (API keys are not role-gated) |
404 | not_found | Wallet doesn’t exist (or belongs to another tenant) | Check the wallet ID via List Wallets |
⌘I
Close a wallet and settle its balance
curl --request POST \
--url https://billing.example.com/v1/wallets/{id}/close \
--header 'Authorization: Bearer <token>'import requests
url = "https://billing.example.com/v1/wallets/{id}/close"
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://billing.example.com/v1/wallets/{id}/close', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://billing.example.com/v1/wallets/{id}/close",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://billing.example.com/v1/wallets/{id}/close"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://billing.example.com/v1/wallets/{id}/close")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/wallets/{id}/close")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"data": {
"refunded": 123,
"forfeited": 123
},
"message": "<string>"
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}