callFavoriteAPI function

void callFavoriteAPI(
  1. String bankId,
  2. String tranNo,
  3. bool isFavorite,
  4. String referrerId,
)

Implementation

void callFavoriteAPI(
    String bankId, String tranNo, bool isFavorite, String referrerId) async {
  bool? isProduction = B24PaymentSdk.storeIsProduction;

  final apiUrl =
      isProduction == false ? envDemo().urlFavorite : envPro().urlFavorite;

  final payload = {
    'tran_id': tranNo,
    'bank_id': bankId,
    'is_favorite': isFavorite,
  };

  final headers = <String, String>{
    'token': envDemo().token,
    'Content-Type': 'application/json',
    'X-Referrer-Key': referrerId,
  };

  final response = await http.post(
    Uri.parse(apiUrl),
    headers: headers,
    body: jsonEncode(payload),
  );

  if (response.statusCode == 200) {
    final jsonResponseData = json.decode(response.body);
    final favoriteCode = jsonResponseData['code'];
    return favoriteCode;
  } else {
    print('API call failed with status code: ${response.statusCode}');
  }
}