Honor Liquidity Provider Withdrawals
Learn how to honor withdrawal requests from liquidity providers.
Overview
In the previous tutorial, you learned how you the Payment Gateway can acknowledge fund deposits into a liquidity provider’s account.
Liquidity providers may also wish to withdraw some, or all of those deposited funds. Liquidity providers may also have funds available to be withdrawn from trades done.
It is your job, you the financial institution PAPE integrator, to honor those withdrawal requests.
You do that by checking all pending withdrawals that concern your financial instititon. The relevant APIs are found below. Once you’ve found pending withdrawal requests, you process them in your own backend.
NB
: Withdrawal requests DO NOT get pushed to you the integrator. You will have to continuously POLL the withdrawals endpoint to find new withdrawal requests for you to process.
Liquidity Provider Withdrawal - Data Model
field | type | description |
---|---|---|
id | string | ID of the liquidity provider withdrawal. Usually in the form of a UUID. > Post Requests: Omit this field. |
liquidityProviderId | string | Id of the liquidity provider performing the withdrawal |
paymentGatewayId | string | Payment Gateway that will process the withdrawal |
paymentGatewayTransactionId | string | Transaction ID supplied by the payment gateway after honoring this withdrawal. Should be unique |
amount | string | Amount to liquidity provider requested to be withdrawn. Should be a string |
currency | string | Three letter currency code used for the liquidity provider withdrawal request |
blockchainTransactionId | string | Transaction ID on the blockchain for the withdrawal request. > POST Requests: Omit this field. |
status | string | Status of the withdrawal request. Value is pending_gateway for an unprocessed withdrawal request.> POST Requests: Omit this field. > PUT Requests: Include this field. |
Liquidity Provider Withdrawal - API Calls
Gets list of all withdrawals requested for a payment gateway. Pending, failed and successful withdrawals are returned.
Gets list of all pending withdrawal requests initiated on a payment gateway.
status=pending_gateway
: filter only pending withdrawal requests_size=3
: return at most 3 items_sort=pagingToken.asc
: sort in ascending order. Oldest withdrawal requests will be returned first.Update status and gateway transaction id of a withdrawal request.
{
"status"
: “[string]
New status of the withdrawal request. Can be pending_gateway, processed, or error”,
"paymentGatewayTransactionId"
: “[string]
Unique transaction id generated by the payment gateway.”
}
Try it out:
Let’s get a list of pending withdrawal requests and confirm a withdrawal.
Prerequisites
Interswitch should have already provided you with a liquidity provider account.
You’ve followed the previous tutorial to deposit funds into your liquidity provider account.
IMPORTANT: You’ve used the Liquidity Provider Dashboard UI to initiate a withdrawal request.
Tools you might need
These are the tools you might need to follow along this tutorial.
linux
ormac
: Many of the command line examples have been customized for UNIX-like operating systems.curl
: To perform API calls.- mac:
brew install curl
- ubuntu/debian:
sudo apt-get install curl
- mac:
jq: To process json on the command line.
- mac:
brew install jq
- ubuntu/debian:
sudo apt-get install jq
- mac:
jo: To create json on the command line.
- mac:
brew install jo
- ubuntu/debian:
sudo apt-get install jo
- mac:
openssl: To perform cryptographic operations on the command line.
- mac:
brew install openssl
- ubuntu/debian:
sudo apt-get install openssl
- mac:
RSA Keys
Depositing funds requires digital signatures as previously outlined in our Security Prologue.
To facilitate our command line operations for this tutorial, we will store our payment gateway RSA keys in special folders.
mkdir -p ~/.pape-rsa-keys
The private and public keys of each payment gateway you manage should be kept inside the above folder with the format below:
- ~/.pape-rsa-keys/
paymentGatewayId
.pub for the public key, and - ~/.pape-rsa-keys/
paymentGatewayId
.priv for the private key
e.g.
- ~/.pape-rsa-keys/ng.bank.ecobank.ngn.pub for the public key, and
- ~/.pape-rsa-keys/ng.bank.ecobank.ngn.priv for the private key
Liquidity Provider Account
For the purpose of this demo, you will withdraw funds from a liquidity provider you control.
Please contact Interswitch to give you a valid PAPE liquidity provider ID with credentials.
Get Token
export PAPE_TOKEN_ENDPOINT=https://id.dev.projectwhite.io/auth/realms/projectwhite/protocol/openid-connect/token;
export PAPE_API_ENDPOINT=https://apis-alpha.dev.projectwhite.io
export PAPE_USERNAME=cm.wallet.interstellar-demo.xaf;
export PAPE_PASSWORD=abc;
export PAPE_TOKEN=`curl -s --request POST \
--url "$PAPE_TOKEN_ENDPOINT" \
--data-urlencode grant_type=password \
--data-urlencode username=$PAPE_USERNAME \
--data-urlencode password=$PAPE_PASSWORD \
--data-urlencode 'client_id=projectwhite' \
| jq -r ".access_token"`
echo $PAPE_TOKEN
Withdrawal List APIs
# {{ base_url }}/payment-gateways/{{payment-gateway-id}}/withdrawals
curl --request GET \
--url "https://apis-alpha.dev.projectwhite.io/payment-gateways/$PAPE_USERNAME/withdrawals?status=pending_gateway&_size=3&_sort=pagingToken.asc" \
--header "Authorization: Bearer $PAPE_TOKEN" | jq .
Sample Response
[
{
"id": "f182f3c6-58e6-454e-a002-2c2f95016372",
"createdAt": "2021-06-04T08:22:55.0839286+01:00",
"updatedAt": "2021-06-04T08:22:55.0839286+01:00",
"pagingToken": "1622791370957-848514799",
"paymentGatewayId": "cm.wallet.interstellar-demo.xaf",
"paymentGatewayTransactionId": "",
"amount": "1000",
"fee": "",
"currency": "XAF",
"blockchainTransactionId": "dacd46d9140a899e8cb46f97eaa8cf298fb35a781a1b156feec10e2936447f58",
"status": "pending_gateway",
"extras": null
},
{
"id": "0b2cf945-e4bb-4883-b258-4dc21927e1c2",
"createdAt": "2021-06-04T15:16:47.5880189+01:00",
"updatedAt": "2021-06-04T15:16:47.5880189+01:00",
"pagingToken": "1622816207588-236698997",
"paymentGatewayId": "cm.wallet.interstellar-demo.xaf",
"paymentGatewayTransactionId": "",
"amount": "1000",
"fee": "100",
"currency": "XAF",
"blockchainTransactionId": "f21a0d5109cb3c0543a6b51166cb68d43bcff8b37931daad90fac4573b17f3f0",
"status": "pending_gateway",
"extras": null
},
{
"id": "ebdb9649-3163-40c4-80bc-d82fea822bb2",
"createdAt": "2021-06-04T21:12:43.718656+01:00",
"updatedAt": "2021-06-04T21:12:43.718656+01:00",
"pagingToken": "1622837563718-1133030347",
"paymentGatewayId": "cm.wallet.interstellar-demo.xaf",
"paymentGatewayTransactionId": "",
"amount": "1500",
"fee": "100",
"currency": "XAF",
"blockchainTransactionId": "ba6e3e24d9dda78921602dd42e7ad3a0fe0d8aae50862786aee7d237aed54958",
"status": "pending_gateway",
"extras": null
}
]
Error Response
{
"error": "string",
"message": "string"
}
If you receive an empty array, this means you have not yet initiated a withdrawal on the liquidity provider dashboard.
Confirm Processed Withdrawal.
curl --request PUT \
--url "https://apis-alpha.dev.projectwhite.io/payment-gateways/$PAPE_USERNAME/withdrawals/ebdb9649-3163-40c4-80bc-d82fea822bb2" \
--header 'Authorization: Bearer $PAPE_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"gatewayTransactionId": "'$(date +%s)'",
"status": "processed"
}' | jq .