withdrawExchange method
If the anchor supports SEP-38 quotes, it can provide a withdraw that makes a bridge between non-equivalent tokens by receiving, for instance USDC from the Stellar network and in return sending the equivalent value (minus fees) as NGN to the user's bank account.
The /withdraw-exchange endpoint allows a wallet to get withdraw information from an anchor when the user intends to make a conversion between non-equivalent tokens. With this endpoint, a user has all the information needed to initiate a withdraw and it also lets the anchor specify additional information (if desired) that the user must submit via SEP-12.
Implementation
Future<WithdrawResponse> withdrawExchange(
WithdrawExchangeRequest request) async {
Uri serverURI =
Util.appendEndpointToUrl(_transferServiceAddress, 'withdraw-exchange');
_WithdrawRequestBuilder requestBuilder =
_WithdrawRequestBuilder(httpClient, serverURI);
final Map<String, String> queryParams = {
"source_asset": request.sourceAsset,
"destination_asset": request.destinationAsset,
"amount": request.amount,
"type": request.type,
};
if (request.quoteId != null) {
queryParams["quote_id"] = request.quoteId!;
}
if (request.dest != null) {
queryParams["dest"] = request.dest!;
}
if (request.destExtra != null) {
queryParams["dest_extra"] = request.destExtra!;
}
if (request.account != null) {
queryParams["account"] = request.account!;
}
if (request.memo != null) {
queryParams["memo"] = request.memo!;
}
if (request.memoType != null) {
queryParams["memo_type"] = request.memoType!;
}
if (request.walletName != null) {
queryParams["wallet_name"] = request.walletName!;
}
if (request.walletUrl != null) {
queryParams["wallet_url"] = request.walletUrl!;
}
if (request.lang != null) {
queryParams["lang"] = request.lang!;
}
if (request.onChangeCallback != null) {
queryParams["on_change_callback"] = request.onChangeCallback!;
}
if (request.countryCode != null) {
queryParams["country_code"] = request.countryCode!;
}
if (request.refundMemo != null) {
queryParams["refund_memo"] = request.refundMemo!;
}
if (request.refundMemoType != null) {
queryParams["refund_memo_type"] = request.refundMemoType!;
}
if (request.customerId != null) {
queryParams["customer_id"] = request.customerId!;
}
if (request.locationId != null) {
queryParams["location_id"] = request.locationId!;
}
try {
return await requestBuilder
.forQueryParameters(queryParams)
.execute(request.jwt);
} on ErrorResponse catch (e) {
if (e.code == 403) {
_handleForbiddenResponse(e);
}
throw e;
}
}