checkTranStatus method
Future<DGePayStatusRespModel>
checkTranStatus({
- required BuildContext context,
- required DGePayConfigs dGePayConfigs,
- required String uniqueTxnId,
Implementation
Future<DGePayStatusRespModel> checkTranStatus({
required BuildContext context,
required DGePayConfigs dGePayConfigs,
required String uniqueTxnId,
}) async {
final TokenController tokenController = TokenController();
AuthRespModel? authRespModel = AuthRespModel();
try {
authRespModel = await tokenController.getToken(
dGePayConfigs: dGePayConfigs,
);
if (authRespModel?.statusCode == 200 && authRespModel?.data != null) {
final params = {
"unique_txn_id": uniqueTxnId
};
String body = jsonEncode(params);
String sorted = replaceEach(body);
String signature = generateSignature(sorted, dGePayConfigs.clientAPIKey);
String encryptedData = encryptData(body, dGePayConfigs.clientSecretKey);
var headers = {
'Authorization': 'Bearer ${authRespModel!.data!.accessToken!}',
'Content-Type': 'application/json',
'signature': signature,
};
final response = await http.post(
Uri.parse(
getBaseUrl(dGePayConfigs.env) + ApiEndpoints.transactionStatus),
headers: headers,
body: encryptedData);
CheckTranRespModel checkTranRespModel =
CheckTranRespModel.fromJson(jsonDecode(response.body));
if (response.statusCode == 200) {
if (context.mounted) dGePayPop(context: context);
return DGePayStatusRespModel(
status: true,
amount: checkTranRespModel.data!.amount ?? 0,
message: checkTranRespModel.data!.message ?? 'Not Found',
dGePayOrderId: uniqueTxnId);
} else {
if (context.mounted) dGePayPop(context: context);
return DGePayStatusRespModel(
status: false,
message: "Something went wrong.",
dGePayOrderId: uniqueTxnId);
}
} else {
if (context.mounted) dGePayPop(context: context);
return DGePayStatusRespModel(
status: false,
errorCode: authRespModel?.statusCode,
message: authRespModel?.error![0] ?? "Something went wrong.",
);
}
} catch (_) {
if (context.mounted) dGePayPop(context: context);
return DGePayStatusRespModel(
status: false,
message: "Something went wrong.",
);
}
}