callGenerateExpir static method
Implementation
static Future<int> callGenerateExpir(
String tranIdEx,
String referrerId,
) async {
bool? isProduction = B24PaymentSdk.storeIsProduction;
DateTime _currentTimes = DateTime.now();
final urlGenerateExpir =
isProduction == false ? envDemo().UrlExpire : envPro().UrlExpire;
final Map<String, dynamic> data = {
"tran_id": tranIdEx,
};
final Map<String, String> headers = {
'token': envDemo().token,
'Content-Type': 'application/json',
'X-Referrer-Key': referrerId,
'X-Client-Time': '$_currentTimes',
};
final response = await http.post(
Uri.parse(urlGenerateExpir),
body: jsonEncode(data),
headers: headers,
);
if (response.statusCode == 200) {
print('Expred ApI');
final jsonResponse = json.decode(response.body);
statusCode = jsonResponse['code'];
final expiredDate = jsonResponse['data']['expired_date'];
final expirationDateTime = _parseCustomDate(expiredDate);
final currentTime = DateTime.now();
final timeDifference = expirationDateTime.difference(currentTime);
final secondsDifference = timeDifference.inSeconds;
return secondsDifference;
} else {
throw Exception('Failed to call Generate API: ${response.statusCode}');
}
}