prepareCollectionRequest method
Implementation
PaymentCollectionRequest prepareCollectionRequest(
double amount,
double localCurrencyGrandTotal,
String? localCurrency,
String? currency,
String orderId) {
List<PaymentCollection> collection = [];
var identifierMode = "";
if (selectedPaymentLabel == "pos.common.payment.mode.bankTransfers.label") {
paymentDataList.forEach((element) {
if (element.label == "pos.common.payment.mode.bankTransfers.label") {
identifierMode = element.id.toString();
element.attributes!.forEach((attribute) {
if (attribute.label ==
"pos.common.payment.mode.bankTransfer.bankName") {
PaymentCollection paymentCollection = PaymentCollection();
paymentCollection.amount = false;
paymentCollection.formatAmount = false;
paymentCollection.label = attribute.label;
paymentCollection.fieldMappingKey = attribute.fieldSubType;
paymentCollection.fieldType = attribute.fieldType;
paymentCollection.id = attribute.id.toString();
paymentCollection.value = selectedBank.value;
collection.add(paymentCollection);
}
if (attribute.label == "pos.common.payment.mode.bank.seller.name") {
PaymentCollection paymentCollection = PaymentCollection();
paymentCollection.amount = false;
paymentCollection.formatAmount = false;
paymentCollection.label = attribute.label;
paymentCollection.fieldMappingKey = attribute.fieldSubType;
paymentCollection.fieldType = attribute.fieldType;
paymentCollection.id = attribute.id.toString();
paymentCollection.value = selectedBank.value;
collection.add(paymentCollection);
}
if (attribute.label ==
"pos.common.payment.mode.bankAccountNumber") {
PaymentCollection paymentCollection = PaymentCollection();
paymentCollection.amount = false;
paymentCollection.formatAmount = false;
paymentCollection.label = attribute.label;
paymentCollection.fieldMappingKey = attribute.fieldSubType;
paymentCollection.fieldType = attribute.fieldType;
paymentCollection.id = attribute.id.toString();
paymentCollection.value = accountNo.text;
collection.add(paymentCollection);
}
if (attribute.label ==
"pos.common.payment.mode.bankTransfer.bankCode") {
PaymentCollection paymentCollection = PaymentCollection();
paymentCollection.amount = false;
paymentCollection.formatAmount = false;
paymentCollection.label = attribute.label;
paymentCollection.fieldMappingKey = attribute.fieldSubType;
paymentCollection.fieldType = attribute.fieldType;
paymentCollection.id = attribute.id.toString();
paymentCollection.value = selectedBranch.value;
collection.add(paymentCollection);
}
if (attribute.label ==
"pos.common.payment.mode.bankTransfer.transactionReferenceNumber") {
PaymentCollection paymentCollection = PaymentCollection();
paymentCollection.amount = false;
paymentCollection.formatAmount = false;
paymentCollection.label = attribute.label;
paymentCollection.fieldMappingKey = attribute.fieldSubType;
paymentCollection.fieldType = attribute.fieldType;
paymentCollection.id = attribute.id.toString();
paymentCollection.value = refNo.text;
collection.add(paymentCollection);
}
if (attribute.label ==
"pos.common.payment.mode.bankTransfer.transactionamount") {
PaymentCollection paymentCollection = PaymentCollection();
paymentCollection.amount = true;
paymentCollection.formatAmount = true;
paymentCollection.label = attribute.label;
paymentCollection.fieldMappingKey = attribute.fieldSubType;
paymentCollection.fieldType = attribute.fieldType;
paymentCollection.id = attribute.id.toString();
paymentCollection.value = amount.toString();
collection.add(paymentCollection);
}
if (attribute.label == "pos.common.payment.mode.depositAmount") {
PaymentCollection paymentCollection = PaymentCollection();
paymentCollection.amount = false;
paymentCollection.formatAmount = true;
paymentCollection.label = attribute.label;
paymentCollection.fieldMappingKey = attribute.fieldSubType;
paymentCollection.fieldType = attribute.fieldType;
paymentCollection.id = attribute.id.toString();
paymentCollection.value = amount.toString();
collection.add(paymentCollection);
}
if (attribute.label ==
"pos.common.payment.mode.bankTransfer.transactionDateTime") {
PaymentCollection paymentCollection = PaymentCollection();
paymentCollection.amount = false;
paymentCollection.formatAmount = false;
paymentCollection.label = attribute.label;
paymentCollection.fieldMappingKey = attribute.fieldSubType;
paymentCollection.fieldType = attribute.fieldType;
paymentCollection.id = attribute.id.toString();
paymentCollection.value = date;
collection.add(paymentCollection);
}
if (attribute.label ==
"pos.common.payment.mode.bankTransfer.uploadFile") {
PaymentCollection paymentCollection = PaymentCollection();
paymentCollection.amount = false;
paymentCollection.formatAmount = false;
paymentCollection.label = attribute.label;
paymentCollection.fieldMappingKey = attribute.fieldSubType;
paymentCollection.fieldType = attribute.fieldType;
paymentCollection.id = attribute.id.toString();
paymentCollection.value = file1Id;
// TODO: paymentCollection.value = cashAmount.text; files need to send
collection.add(paymentCollection);
}
});
}
});
}
if (selectedPaymentLabel == "pos.common.payment.mode.cash.label") {
paymentDataList.forEach((element) {
if (element.label == "pos.common.payment.mode.cash.label") {
identifierMode = element.id.toString() ?? "";
element.attributes!.forEach((attribute) {
if (attribute.label == "pos.common.payment.mode.cash.amount") {
PaymentCollection paymentCollection = PaymentCollection();
paymentCollection.amount = true;
paymentCollection.formatAmount = true;
paymentCollection.label = attribute.label;
paymentCollection.fieldMappingKey = attribute.fieldSubType;
paymentCollection.fieldType = attribute.fieldType;
paymentCollection.id = attribute.id.toString();
paymentCollection.value = amount.toString();
collection.add(paymentCollection);
}
if (attribute.label == "pos.common.payment.mode.currencyType") {
PaymentCollection paymentCollection = PaymentCollection();
paymentCollection.amount = false;
paymentCollection.formatAmount = false;
paymentCollection.label = attribute.label;
paymentCollection.fieldMappingKey = attribute.fieldSubType;
paymentCollection.fieldType = attribute.fieldType;
paymentCollection.id = attribute.id.toString();
paymentCollection.value = currency ?? "USD";
collection.add(paymentCollection);
}
});
}
});
}
List<ModeList> mode = [];
mode.add(ModeList(id: identifierMode, collection: [collection]));
PaymentCollectionRequest paymentCollectionRequest =
PaymentCollectionRequest(
modeList: mode,
currency: currency ?? "USD",
checkInId: checkinId,
orderId: orderId);
return paymentCollectionRequest;
}