transferCoupon method
Implementation
Future<void> transferCoupon() async {
final BuildContext context = Get.context!;
String requestTime = '';
String responseTime = '';
try {
Helper.progressDialog(context, '');
final request = {
"partnerId": partnerId,
"toPartnerId": selectedPartner.value?.partnerId ?? "",
"amount": selectedAmount.value,
"referenceID": "",
"walletUsageType": "COUPON_TRANSFER",
"remarks": remarksController.text,
};
final response = await ApiClient(
baseUrl: ApiConstant.baseUrl,
onFetchRequestTime: (time) {
requestTime = time;
},
onFetchResponseTime: (time) {
responseTime = time;
},
screenName: 'couponTransfer',
).couponTransfer(body: request);
Helper.logEvent(
'RESPONSE_EVENT',
success: true,
endPoint: Api.couponTransfer,
responseDate: responseTime,
screenName: 'couponTransfer',
requestDate: requestTime,
);
Helper.close();
if (response.responseCode != null &&
response.responseCode == "SC-CPM-CP-406") {
final double transferredAmount = selectedAmount.value;
final double parentCouponBalance =
(currentCouponBalance.value - transferredAmount).clamp(
0.0,
double.infinity,
);
Get.to(() => CouponTransferSuccessScreen(
currency: currentCurrency.value,
partnerName: selectedPartner.value?.partnerName ?? "",
transactionId: response.transactionId ?? "",
parentCouponBalance: parentCouponBalance.toString(),
transferredAmount: transferredAmount.toString(),
subResellerCouponBalance: transferredAmount.toString(),
));
}
} catch (e, st) {
Helper.close();
ConditionalLogs().customLog('$st');
if (e is DioException) {
UDID.setTraceId(
e.response?.headers.map[Constants.traceIdKey]?[0] ?? '',
);
Helper.logEvent(
'ERROR_EVENT',
failure: true,
requestDate: requestTime,
endPoint: Api.couponTransfer,
responseDate: DateTime.now().toString(),
screenName: 'couponTransfer',
error: e,
);
// MainController mainController = Get.put(MainController());
// mainController.showErrorPopup();
}
}
}