kamiPay LogokamiPay Docs

Refund Wallet

Create the refund wallet of your account, read its USDt, and turn refunds on or off for each checkout.

A pay-in refund in wallet mode takes the USDt of the refund from your refund wallet, before kamiPay sends the BRL back to the payer. Use the endpoints below to set up the wallet.

  • One refund wallet for your account. It serves all your checkouts. You turn refunds on or off for each checkout.
  • kamiPay creates the wallet on Polygon and keeps its key. kamiPay signs each transfer from it.
  • You send only USDt to it. kamiPay keeps POL in the wallet for the gas.
  • To withdraw USDt, use Withdraw.

Access: all the endpoints of this page need credentials with the pay-in scope. The role depends on the endpoint:

ActionUser role
Create Refund Wallet, Turn Refunds On or Off, Withdraw from the refund walletA management role (owner, super user or super admin). Other roles get 403.
Get Refund Wallet, ask for a refundAny role.

Create Refund Wallet

POST /v2/pay_in_refunds/wallet

Creates the refund wallet of your account. The request has no body. If your account already has a refund wallet, the API creates nothing and returns 200 with that wallet. Thus, you can send this request again with no risk.

Example Request

const url = `${baseURL}/v2/pay_in_refunds/wallet`;

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${access_token}`,
  },
});
import requests

url = f"{base_url}/v2/pay_in_refunds/wallet"

headers = {
  "Authorization": f"Bearer {access_token}",
}

response = requests.post(url, headers=headers)
package main

import (
  "fmt"
  "net/http"
)

func main() {
  url := fmt.Sprintf("%s/v2/pay_in_refunds/wallet", baseURL)

  req, _ := http.NewRequest("POST", url, nil)
  req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", accessToken))

  client := &http.Client{}
  resp, err := client.Do(req)
  if err != nil {
    fmt.Println("Error making request:", err)
    return
  }
  defer resp.Body.Close()
}

Response

A new wallet. Its balances are 0. Response Fields shows each field:

{
  "address": "0x4b1e9c7a2f3d58e6a0c4b7d9e2f1a3c5b8d0e6f2",
  "network": "polygon",
  "balance_usdt": "0.000000",
  "reserved_usdt": "0.000000",
  "med_owed_usdt": "0.000000",
  "available_usdt": "0.000000",
  "balance_pol": "0.000000",
  "checkouts": [],
  "created_at": 1792587521
}

Your account already has a refund wallet. The response is that wallet, with its balances on Polygon, as in Get Refund Wallet.

With an invalid or expired token:

{
  "detail": "Could not validate credentials"
}

With a valid token without the pay-in scope:

{
  "detail": "Token Profile Not Authorized for this Endpoint"
}

Your user does not have a management role:

{
  "detail": "User role not authorized for this endpoint"
}

Your account has more than one refund wallet. Contact support:

{
  "detail": "the merchant has more than one refund wallet: contact support"
}

kamiPay cannot read the balances on Polygon now. Nothing changed. Send the request again later:

{
  "detail": "could not read the refund wallet balances on-chain; retry later"
}

Get Refund Wallet

GET /v2/pay_in_refunds/wallet

Returns the refund wallet of your account: its address, its balances on Polygon and the checkouts with refunds on.

Example Request

const url = `${baseURL}/v2/pay_in_refunds/wallet`;

const response = await fetch(url, {
  method: "GET",
  headers: {
    Authorization: `Bearer ${access_token}`,
  },
});
import requests

url = f"{base_url}/v2/pay_in_refunds/wallet"

headers = {
  "Authorization": f"Bearer {access_token}",
}

response = requests.get(url, headers=headers)
package main

import (
  "fmt"
  "net/http"
)

func main() {
  url := fmt.Sprintf("%s/v2/pay_in_refunds/wallet", baseURL)

  req, _ := http.NewRequest("GET", url, nil)
  req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", accessToken))

  client := &http.Client{}
  resp, err := client.Do(req)
  if err != nil {
    fmt.Println("Error making request:", err)
    return
  }
  defer resp.Body.Close()
}

Response

The wallet holds 10 USDt, and a refund that takes 0.960507 USDt from it is in progress:

{
  "address": "0x4b1e9c7a2f3d58e6a0c4b7d9e2f1a3c5b8d0e6f2",
  "network": "polygon",
  "balance_usdt": "10.000000",
  "reserved_usdt": "0.960507",
  "med_owed_usdt": "0.000000",
  "available_usdt": "9.039493",
  "balance_pol": "0.850000",
  "checkouts": [
    { "store_id": 1, "checkout_id": 1 },
    { "store_id": 1, "checkout_id": 2 }
  ],
  "created_at": 1792587521
}

With an invalid or expired token:

{
  "detail": "Could not validate credentials"
}

With a valid token without the pay-in scope:

{
  "detail": "Token Profile Not Authorized for this Endpoint"
}

Your account has no refund wallet. Create it with Create Refund Wallet:

{
  "detail": "refund wallet not found"
}

Your account has more than one refund wallet. Contact support:

{
  "detail": "the merchant has more than one refund wallet: contact support"
}

kamiPay cannot read the balances on Polygon now. Send the request again later:

{
  "detail": "could not read the refund wallet balances on-chain; retry later"
}

Response Fields

The three endpoints of this page return this object. Each amount is a string with 6 decimals.

FieldTypeDescription
addressstringThe address of the wallet on Polygon. Send USDt to it.
networkstringAlways "polygon".
balance_usdtstringThe USDt that the wallet holds on Polygon.
reserved_usdtstringThe USDt that the refunds in progress take from the wallet.
med_owed_usdtstringThe USDt that the wallet owes for a MED: kamiPay could not take it when the wallet had too little USDt, and takes it later. Only a MED changes it. "0.000000" when the wallet owes nothing.
available_usdtstringThe USDt for new refunds and withdrawals: balance_usdt minus reserved_usdt and med_owed_usdt, never less than 0.
balance_polstringThe POL that the wallet holds for the gas. kamiPay adds POL when it is low.
checkoutsarrayThe checkouts with refunds on, each with store_id and checkout_id, in the order of store_id and then checkout_id.
created_atintegerWhen kamiPay created the wallet, in epoch seconds.

Turn Refunds On or Off

PUT /v2/pay_in_refunds/wallet/checkouts/{store_id}/{checkout_id}

Turns refunds on or off for one checkout of your account. kamiPay accepts a refund of a charge only when the checkout of the charge has refunds on at the time of the request. If you turn refunds off for a checkout, its refunds in progress continue.

If the checkout already has the value that you send, nothing changes. The response is your refund wallet, with the same fields as Get Refund Wallet.

Path Parameters

NameTypeDescription
store_idintegerRequired. The store of the checkout.
checkout_idintegerRequired. The checkout.

Body Parameters

NameTypeDescription
refunds_enabledbooleanRequired. true turns refunds on for the checkout. false turns them off.

Example Request

const storeId = 1;
const checkoutId = 2;
const url = `${baseURL}/v2/pay_in_refunds/wallet/checkouts/${storeId}/${checkoutId}`;

const response = await fetch(url, {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${access_token}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ refunds_enabled: true }),
});
import requests

store_id = 1
checkout_id = 2
url = f"{base_url}/v2/pay_in_refunds/wallet/checkouts/{store_id}/{checkout_id}"

headers = {
  "Authorization": f"Bearer {access_token}",
  "Content-Type": "application/json",
}

response = requests.put(url, json={"refunds_enabled": True}, headers=headers)
package main

import (
  "bytes"
  "encoding/json"
  "fmt"
  "net/http"
)

func main() {
  storeID := 1
  checkoutID := 2
  url := fmt.Sprintf("%s/v2/pay_in_refunds/wallet/checkouts/%d/%d", baseURL, storeID, checkoutID)

  requestBody, _ := json.Marshal(map[string]interface{}{
    "refunds_enabled": true,
  })

  req, _ := http.NewRequest("PUT", url, bytes.NewBuffer(requestBody))
  req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", accessToken))
  req.Header.Add("Content-Type", "application/json")

  client := &http.Client{}
  resp, err := client.Do(req)
  if err != nil {
    fmt.Println("Error making request:", err)
    return
  }
  defer resp.Body.Close()
}

Response

Your refund wallet. checkouts now has checkout 2 of store 1:

{
  "address": "0x4b1e9c7a2f3d58e6a0c4b7d9e2f1a3c5b8d0e6f2",
  "network": "polygon",
  "balance_usdt": "10.000000",
  "reserved_usdt": "0.960507",
  "med_owed_usdt": "0.000000",
  "available_usdt": "9.039493",
  "balance_pol": "0.850000",
  "checkouts": [
    { "store_id": 1, "checkout_id": 1 },
    { "store_id": 1, "checkout_id": 2 }
  ],
  "created_at": 1792587521
}

With an invalid or expired token:

{
  "detail": "Could not validate credentials"
}

With a valid token without the pay-in scope:

{
  "detail": "Token Profile Not Authorized for this Endpoint"
}

Your user does not have a management role:

{
  "detail": "User role not authorized for this endpoint"
}

The checkout is not a checkout of your account:

{
  "detail": "checkout not found"
}

Your account has no refund wallet. Create it with Create Refund Wallet:

{
  "detail": "the merchant has no refund wallet"
}

Your account has more than one refund wallet. Contact support:

{
  "detail": "the merchant has more than one refund wallet: contact support"
}

kamiPay disabled the refund wallet, so you cannot turn refunds on. You can still turn them off. Contact support:

{
  "detail": "refund wallet missing or disabled"
}

kamiPay cannot read the balances on Polygon now. Nothing changed. Send the request again:

{
  "detail": "could not read the refund wallet balances on-chain; retry later"
}

On this page