cashPayment method
dynamic
cashPayment(})
Implementation
cashPayment(
BuildContext context,
String id,
String cartId,
String amount,
String localCurrencyAmount, {
bool isCashOnDelivery = false,
}) async {
try {
Helper.progressDialog(context, "Please wait..");
// printLogs(dio);
dio
.post(
'${ApiConstant.posBaseUrl}pos-payment-service-svc/payment-collection/carts/$cartId',
data: json.encode({
"modeList": [
{
"id": id,
"collection": [
[
{
"id": "40",
"value": "USD",
"label": "pos.common.payment.mode.currencyType",
"fieldMappingKey": "currencyType",
"fieldType": "DROPDOWN",
"currency": null,
"configs": {},
"amount": false,
"formatAmount": false,
"unique": false
},
{
"id": "8",
"value": amount,
"label": "pos.common.payment.mode.amount",
"fieldMappingKey": "cashAmount",
"fieldType": "INPUT",
"currency": "USD",
"configs": {},
"amount": true,
"formatAmount": true,
"unique": false
},
{
"id": "42",
"value": null,
"label":
"pos.common.payment.mode.microPay.placeholder.exchangeRate",
"fieldMappingKey": "exchangeRate",
"fieldType": "INPUT",
"currency": "KHR",
"configs": {
"maximumFractionDigits": "5",
"minimumFractionDigits": "5"
},
"amount": false,
"formatAmount": true,
"unique": false
},
{
"id": "41",
"value": localCurrencyAmount,
"label": "pos.common.payment.mode.localCurrencyAmount",
"fieldMappingKey": "localCurrencyAmount",
"fieldType": "INPUT",
"currency": "KHR",
"configs": {},
"amount": false,
"formatAmount": true,
"unique": false
}
]
]
}
],
"currency": "USD"
}),
options: Options(
headers: {
'x-request-txn-id': UDID.uDID,
'X-User-Id': SecureStorageService.readSecureData(
SecureStorageService.xUserId,
),
'X-User-Name': SecureStorageService.readSecureData(
SecureStorageService.xUserId,
),
'Authorization': "Bearer ${SecureStorageService.readSecureData(
SecureStorageService.accessToken,
)}",
},
),
)
.then((response) {
if (response.data != null) {
ConditionalLogs().customLog('paymentCollect${response.data}');
PaymentCollection model = PaymentCollection();
Map<String, dynamic> creditData = response.data;
model = PaymentCollection.fromJson(creditData);
if (model.status == 'POS200') {
Get.back();
orderCreation(
context,
model.data!.paymentCollectionByModeList![0].cartId!,
model.data!.transactionId!,
'SELL_THRU',
isBank: false,
isCashOnDelivery: isCashOnDelivery,
);
} else {
Get.back();
Helper.messageDialog(
Get.context!,
model.errors?[0]?["errorItem"]["errorCode"] ?? "Try Again",
model.errors?[0]?["errorItem"]["errorMessage"] ??
"Something went wrong",
);
}
} else {
Get.back();
}
}).catchError((error) {
ConditionalLogs().customLog("$error");
Get.back();
MainController mainController = Get.put(MainController());
mainController.showErrorPopup();
});
} catch (e) {
Get.back();
}
}