createConversion method

  1. @override
Future<Map> createConversion(
  1. String token,
  2. String? buyAmount,
  3. String buyCurrency,
  4. String? conversionDate,
  5. String? quoteId,
  6. String reason,
  7. String requestId,
  8. String? sellAmount,
  9. String sellCurrency,
  10. bool termAgreement,
)
override

Implementation

@override
Future<Map> createConversion(
    String token,
    String? buyAmount,
    String buyCurrency,
    String? conversionDate,
    String? quoteId,
    String reason,
    String requestId,
    String? sellAmount,
    String sellCurrency,
    bool termAgreement) async {
  final String baseUrl = await getBaseUrl;
  var url = Uri.parse("$baseUrl/api/v1/conversions/create");
  var bodyData = {
    "buy_currency": buyCurrency,
    "reason": reason,
    "request_id": requestId,
    "sell_currency": sellCurrency,
    "term_agreement": termAgreement
  };
  if (buyAmount != null) {
    bodyData.addAll({"buy_amount": buyAmount});
  }
  if (conversionDate != null) {
    bodyData.addAll({"conversion_date": conversionDate});
  }
  if (quoteId != null) {
    bodyData.addAll({"quote_id": quoteId});
  }
  if (sellAmount != null) {
    bodyData.addAll({"sell_amount": sellAmount});
  }
  var jsonBody = jsonEncode(bodyData);
  var response = await http.post(
    url,
    headers: {
      "Content-Type": "application/json",
      "Authorization": "Bearer $token"
    },
    body: jsonBody,
  );
  var data = jsonDecode(response.body);
  return data;
}