prepareCollectPaymentRequestSubmit method
Implementation
CollectPaymentRequest prepareCollectPaymentRequestSubmit(
PaymentData data,
Map<String, String> selectedDates,
Map<String, TextEditingController> controllers,
Map<String, String> dropdownValues,
String currency,
String selectFile) {
List<CollectPayment> collection = [];
var identifierMode = "";
Map<String, dynamic> enteredData = {};
identifierMode = data.id.toString();
var amount = "";
for (var attr in data.attributes!) {
if (attr.fieldType == "DATE_PICKER") {
enteredData[attr.fieldName ?? ""] = selectedDates[attr.fieldName] ?? "";
CollectPayment paymentCollection = CollectPayment();
paymentCollection.label = attr.label;
paymentCollection.attributeName = attr.fieldType;
paymentCollection.attributeValue = selectedDates[attr.fieldName] ?? "";
collection.add(paymentCollection);
} else if (attr.fieldType == "DROPDOWN") {
enteredData[attr.fieldName ?? ""] =
dropdownValues[attr.fieldName] ?? "";
CollectPayment paymentCollection = CollectPayment();
paymentCollection.label = attr.label;
paymentCollection.attributeName = attr.fieldType;
paymentCollection.attributeValue = dropdownValues[attr.fieldName] ?? "";
collection.add(paymentCollection);
} else {
enteredData[attr.fieldName ?? ""] =
controllers[attr.fieldName]?.text ?? "";
if (attr.fieldName!.toLowerCase().contains("amount")) {
amount = controllers[attr.fieldName]?.text ?? "";
currency = attr.currency ?? "USD";
}
if (attr.fieldName!.toLowerCase().contains("uploadFile")) {
CollectPayment paymentCollection = CollectPayment();
paymentCollection.label = attr.label;
paymentCollection.attributeName = attr.fieldType;
paymentCollection.attributeValue = selectFile;
collection.add(paymentCollection);
} else {
CollectPayment paymentCollection = CollectPayment();
paymentCollection.label = attr.label;
paymentCollection.attributeName = attr.fieldType;
paymentCollection.attributeValue =
controllers[attr.fieldName]?.text ?? "";
collection.add(paymentCollection);
}
}
}
mode.removeWhere((element) => element.paymentModeId == identifierMode);
mode.add(CollectPaymentModeList(
paymentModeId: identifierMode,
amountPaid: AmountPaid(amount: double.parse(amount)),
attributes: collection));
mode.sort((a, b) => a.paymentModeId!.compareTo(b.paymentModeId!));
print("mode ${mode.toString()}");
print("Entered Data: $enteredData");
CollectPaymentRequest paymentCollectionRequest =
CollectPaymentRequest(modeList: mode, currency: currency ?? "USD");
return paymentCollectionRequest;
// Send data to API or model
}