This page explains how to use the value from the baseAmount
value retrieved from the Fees-Included approximate quote API response in the Trade Widget setup. This enables you to create Buy trades where all the fees are included in the amount the customer specified to spend.
- Create the Fees-Included Approximate quote for Buy trade
- Fetch the
baseAmount
value from the API response body - Pass the
baseAmount
value as thebaseAmount
parameter in the Request Trade Quote API request - Fetch the returned Quote ID and use it when calling the Create Trade API endpoint
- Create the trade using the quote ID and redirect your customer to the Payment Page (in case of Credit Card payment) or show the Bank Account details for the bank transfer (in case of the Bank transfer payment).
Example of the flow
Let's take an example of a customer who wants to buy 200 USD worth of Bitcoin with a credit card purchase. We'll go through the example by taking the above mentioned steps.
- Here's an example of the Fees-Included cURL API request and response from the Approximate quote endpoint:
curl --location 'https://app-api.sandbox.coinify.com/partners/24d17a54-81e6-464b-aba8-30935fc0fd3f/approximate-quote?transferInMedium=card&transferOutMedium=blockchain"eCurrency=USDT&sendAmount=-200&sendCurrency=USD' \
--header 'Authorization: Bearer eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MzEzMjk0OTIsImV4cCI6MTczMTMzMDY5MiwidWlkIjo1ODYxNywiZXYiOnRydWUsInNjIjp7InRfMTM0NTAiOiIqIn19.mMGg9mdzSqwayb6rPhNNgp36HmEvesASkgtMxSOfgt6CX5-RwuCk_TEl4p5SMGPmiVrNhmmTcjHMugoAEdFQQw' \
--data ''
{
"baseAmount": -177.28,//the value passed as the baseAmount in the Trade Quote API request (Requested amount - transferIn.feeAmount)
"baseCurrency": "USD",
"sendAmount": -200,
"sendCurrency": "USD",
"quoteAmount": 177.1223611,//quoted amount for the requested cryptocurrency, before transferOut.feeAmount deducted
"quoteCurrency": "USDT",
"receiveAmount": 175.93502096,//approximated amount the end-user will receive) after transferOut.feeAmount deducted from quoteAmount
"receiveCurrency": "USDT",
"transferIn": {
"medium": "card",
"feeAmount": 22.71,
"currency": "USD"
},
"transferOut": {
"medium": "blockchain",
"feeAmount": 1.18734014,//network transaction fee
"currency": "USDT"
}
}
- In this example, we can see that the
baseAmount
value is -177.28 andbaseCurrency
is USD. - Now we're going to pass the
baseAmount
(andbaseCurrency
) from the Approximate quote response to thebaseAmount
of the Request Trade Quote API request. Here's a cURL example of the request:
curl --location 'https://app-api.sandbox.coinify.com/trades/quote' \
--header 'Authorization: Bearer eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MzEzMjk0OTIsImV4cCI6MTczMTMzMDY5MiwidWlkIjo1ODYxNywiZXYiOnRydWUsInNjIjp7InRfMTM0NTAiOiIqIn19.mMGg9mdzSqwayb6rPhNNgp36HmEvesASkgtMxSOfgt6CX5-RwuCk_TEl4p5SMGPmiVrNhmmTcjHMugoAEdFQQw' \
--header 'Content-Type: application/json' \
--data '{
"baseAmount": -177.28,
"baseCurrency": "USD",
"quoteCurrency": "USDT",
"transferIn": {
"medium": "card"
},
"transferOut": {
"medium" : "blockchain"
}
}'
{
"id": 1410817,
"baseCurrency": "USD",
"quoteCurrency": "USDT",
"baseAmount": -177.28,
"quoteAmount": 177.13120978,
"transferIn": {
"medium": "card",
"feeAmount": 22.72,
"currency": "USD"
},
"transferOut": {
"medium": "blockchain",
"feeAmount": 1.34214936,
"currency": "USDT"
},
"issueTime": "2024-11-11T13:08:05.000Z",
"expiryTime": "2024-11-11T13:23:05.039Z",
"approximateAmount": false
}
- Create a trade based on the previous quote example:
curl --location 'https://app-api.sandbox.coinify.com/trades' \
--header 'Authorization: Bearer eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MzEzMjk0OTIsImV4cCI6MTczMTMzMDY5MiwidWlkIjo1ODYxNywiZXYiOnRydWUsInNjIjp7InRfMTM0NTAiOiIqIn19.mMGg9mdzSqwayb6rPhNNgp36HmEvesASkgtMxSOfgt6CX5-RwuCk_TEl4p5SMGPmiVrNhmmTcjHMugoAEdFQQw' \
--header 'Origin: https://trade.coinify.com' \
--header 'referer: https://trade.coinify.com/' \
--header 'sec-ch-ua: \' \
--header 'Content-Type: application/json' \
--data '{
"priceQuoteId": 1410817,//the ID of the quote from previous response
"transferIn": {
"medium": "card",
"details": {
"returnUrl": "https://www.coinify.com"
}
},
"transferOut": {
"medium": "blockchain",
"details": {
"account": "0x8c58D12ce7219B6F53B1803d00b7021CB8e9A4c6"
}
}
}'
{
"id": 209552,
"trackingId": "ead34559-8e1f-475e-bc15-20f2090f310a",
"state": "awaiting_transfer_in",
"traderId": 13450,
"traderEmail": "[email protected]",
"inAmount": 177.28,
"inCurrency": "USD",
"outCurrency": "USDT",
"outAmountExpected": 177.13120978,
"transferIn": {
"id": 622244,
"sendAmount": 200,//the amount end-user has to pay in total
"receiveAmount": 177.28,
"currency": "USD",
"medium": "card",
"details": {
"returnUrl": "https://www.coinify.com",
"redirectUrl": "https://payment-page-ui.sandbox.coinify.com/?paymentId=1000049103&traderId=13450&country=HR&email=sni%2Balltest%40coinify.com&transferInAmount=200&transferInFeeAmount=22.72&transferInHandlingFee=4.99&transferInCurrency=USD&transferOutAmount=175.78906042&transferOutFeeAmount=1.34214936&transferOutHandlingFee=1.34214936&transferOutCurrency=USDT&returnUrl=https%3A%2F%2Fwww.coinify.com&tradeId=209552&partnerId=255&provider=safecharge&isApplePayAvailable=false",
"provider": "safecharge",
"isApplePayAvailable": false,
"cardPaymentId": "1000049103"
}
},
"transferOut": {
"id": 622245,
"sendAmount": 177.13120978,
"receiveAmount": 175.78906042,
"currency": "USDT",
"medium": "blockchain",
"details": {
"account": "0x8c58D12ce7219B6F53B1803d00b7021CB8e9A4c6"
}
},
"createTime": "2024-11-11T13:09:39.488Z",
"updateTime": "2024-11-11T13:09:39.488Z",
"isPriceQuoteApproximate": false,
"quoteExpireTime": "2024-11-11T13:23:05.039Z"
}
We can see that the final amount the end-user has to pay (sendAmount
) is the same as the amount they initially requested (200 USD in this example).