Gravv
/Docs
Search docs or ask a question⌘K
DocsAgent
ChangelogTry sandbox
Recipes Sandbox Test savings end to end

Test savings end to end

Open a sandbox savings account, fund it, save, add interest, read a statement, withdraw, and trigger a failed save, a waiting withdrawal and a refunded withdrawal.

7 min read

Use this recipe to run the whole savings flow in sandbox: open a savings account, fund it, save, add interest, read a statement and withdraw. Then trigger the three outcomes you need screens for: a failed save, a withdrawal that waits, and a refunded withdrawal.

Who it is for. A neobank adding a savings jar to its app, testing every screen before launch.

Status. Available in sandbox. Savings is not yet available with a live key.

Money example

1.
You simulate a 150.00 USD deposit. Available is 150, saved is 0.
2.
You save 100. About a minute later: available 50, saved 100.
3.
You add 0.25 of interest. Saved is 100.25.
4.
You withdraw 50. Available 100, saved 50.25.
5.
A save of 5.13 fails, and nothing moves.
6.
A withdrawal of 5.13 waits about 2 minutes, then completes. Available 105.13, saved 45.12.
7.
A withdrawal of 5.14 fails, and the 5.14 stays in savings.

Before you start

•
A sandbox key (grvSec_sandbox_) that can initiate transfers.
•
A sandbox customer whose KYC is completed. New sandbox customers do not complete KYC today, so ask support for a verified one if you have none. See Verify a customer in sandbox.
•
A webhook URL set in the Dashboard in Sandbox mode, to see the events.

Find out what is required

A savings account takes customer_id, customer_type, currency USD and category savings. A customer can hold one. Saves and withdrawals use the savings account id on both sides of POST /v1/transfer. See How savings works.

Steps

1. Open the savings account

cURLNodePython
curl --request POST \
--url https://api.gravv.xyz/v2/accounts \
--header 'Api-Key: <API_KEY>' \
--header 'Idempotency-Key: a21a3f07-dda3-4cfb-8ac2-f7ce9c85eacf' \
--header 'Content-Type: application/json' \
--data '
{
"customer_id": "b140f51d-2598-410a-a583-e1cb7a871443",
"customer_type": "individual",
"currency": "USD",
"category": "savings",
"label": "Ada savings"
}
'

The response has account_id and status pending. Read the account with GET /v2/accounts/{id} until it is active, or wait for applications.accounts.completed.

2. Fund it

Simulate a deposit into the account.

cURLNodePython
curl --request POST \
--url https://api.gravv.xyz/v2/accounts/simulate/deposit \
--header 'Api-Key: <API_KEY>' \
--header 'Idempotency-Key: fe18ca7e-7a24-4bb0-9a2a-441b0ecaae9b' \
--header 'Content-Type: application/json' \
--data '
{
"account_id": "d9eae506-77b4-4e8b-8ab3-caaf96054d79",
"amount": "150.00",
"currency": "USD"
}
'

When the deposit's transfer.inflow.* webhook arrives, available is 150. See Test accounts with a simulated deposit for the deposit's options.

3. Save 100

cURLNodePython
curl --request POST \
--url https://api.gravv.xyz/v1/transfer \
--header 'Api-Key: <API_KEY>' \
--header 'Idempotency-Key: a02b8e7b-dcdc-4fff-9c78-b1dc85424b77' \
--header 'Content-Type: application/json' \
--data '
{
"source": {
"source_type": "internal_account",
"id": "d9eae506-77b4-4e8b-8ab3-caaf96054d79"
},
"destination": {
"destination_type": "savings",
"id": "d9eae506-77b4-4e8b-8ab3-caaf96054d79"
},
"amount": "100.00",
"customer_id": "b140f51d-2598-410a-a583-e1cb7a871443"
}
'

The response is pending. About a minute later you receive transfer.status.completed with workflow_type savings_deposit.

4. Add interest

Sandbox has no nightly interest, so add it yourself.

cURLNodePython
curl --request POST \
--url https://api.gravv.xyz/v1/savings/simulate/interest \
--header 'Api-Key: <API_KEY>' \
--header 'Idempotency-Key: 7525a5f5-c150-4096-89c4-b5d7ca4f42af' \
--header 'Content-Type: application/json' \
--data '
{
"account_id": "d9eae506-77b4-4e8b-8ab3-caaf96054d79",
"amount": "0.25"
}
'

The response shows saved_balance 100.250000, and savings.interest.credited arrives with source simulated.

5. Read the savings and the statement

cURLNodePython
curl --request GET \
--url https://api.gravv.xyz/v1/savings/d9eae506-77b4-4e8b-8ab3-caaf96054d79 \
--header 'Api-Key: <API_KEY>'

available_balance is 50.000000, saved_balance 100.250000 and earned_total 0.250000.

cURLNodePython
curl --request GET \
--url 'https://api.gravv.xyz/v1/savings/d9eae506-77b4-4e8b-8ab3-caaf96054d79/statement?format=csv' \
--header 'Api-Key: <API_KEY>'

Today's row reads saved 100, interest 0.25, closing 100.25.

6. Withdraw 50

cURLNodePython
curl --request POST \
--url https://api.gravv.xyz/v1/transfer \
--header 'Api-Key: <API_KEY>' \
--header 'Idempotency-Key: bc5fb19c-857b-4ff2-9d64-4e3d5b7d9e96' \
--header 'Content-Type: application/json' \
--data '
{
"source": {
"source_type": "savings",
"id": "d9eae506-77b4-4e8b-8ab3-caaf96054d79"
},
"destination": {
"destination_type": "internal_account",
"id": "d9eae506-77b4-4e8b-8ab3-caaf96054d79"
},
"amount": "50.00",
"customer_id": "b140f51d-2598-410a-a583-e1cb7a871443"
}
'

After transfer.status.completed, available is 100 and saved is 50.25.

7. Trigger the other outcomes

Repeat step 3 or step 6 with these amounts. Each needs a new Idempotency-Key.

MoveAmountWhat happens
Save5.13transfer.status.failed. Nothing moves
Withdraw5.13transfer.savings.awaiting_liquidity, and pending_balance is -5.130000 while it waits. About 2 minutes later, transfer.status.completed
Withdraw5.14transfer.status.failed. The 5.14 stays in savings

What can go wrong

ResponseWhyFix
400 that says the customer has not completed KYC, on step 1The customer is not verifiedUse a verified sandbox customer
400 no account option is available for the requested combination ... on step 1customer_type is missingSend customer_type
409 SAVINGS_ACCOUNT_ALREADY_EXISTSThe customer already has a savings accountUse that account. Find it with GET /v2/accounts?customer_id=...
400 nothing saved: save into this account before simulating interestStep 4 before step 3 completedWait for transfer.status.completed on the save
400 The amount is more than the savings balance.A withdrawal larger than saved_balanceWithdraw less
400 savings interest can only be simulated in sandboxA live key on step 4Use your sandbox key
501 on a savings readA live keyUse your sandbox key

Webhooks you will receive

•
applications.accounts.completed when the account opens.
•
A transfer.inflow.* event for the simulated deposit.
•
transfer.status.pending, then transfer.status.completed or transfer.status.failed, for each save and withdrawal.
•
transfer.savings.awaiting_liquidity for the 5.13 withdrawal.
•
savings.interest.credited for the simulated interest.

Testing in sandbox

This page is the sandbox guide for savings. Sandbox differs from live in four ways: the rate is fixed at 3.50 and indicative is true, there is no nightly interest, the 1 USD smallest save is not applied, and the .13 and .14 amounts above choose the outcome.

Reference

Was this page helpful? Yes No