cashPayment method

dynamic cashPayment(
  1. BuildContext context,
  2. String id,
  3. String cartId,
  4. String amount,
  5. String localCurrencyAmount, {
  6. bool isCashOnDelivery = false,
})

Implementation

cashPayment(
  BuildContext context,
  String id,
  String cartId,
  String amount,
  String localCurrencyAmount, {
  bool isCashOnDelivery = false,
}) async {
  WidgetsBinding.instance.addPostFrameCallback((_) {
    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-User-Id': storage.read("XUSER_ID"),
        'X-User-Name': storage.read("XUSER_ID")
      },
    ),
  )
      .then((response) {
    Get.back();
    if (response.data != null) {
      print('paymentCollect${response.data}');
      PaymentCollection model = PaymentCollection();
      Map<String, dynamic> creditData = response.data;
      model = PaymentCollection.fromJson(creditData);
      if (model.status == 'POS200') {
        orderCreation(
          context,
          model.data!.paymentCollectionByModeList![0].cartId!,
          model.data!.transactionId!,
          'SELL_THRU',
          isBank: false,
          isCashOnDelivery: isCashOnDelivery,
        );
      } else {
        Helper.messageDialog(
          Get.context!,
          model.errors?[0]?["errorItem"]["errorCode"] ?? "Try Again",
          model.errors?[0]?["errorItem"]["errorMessage"] ??
              "Something went wrong",
        );
      }
    }
  }, onError: (error) {
    print(error.toString());
    Get.back();
    Helper.messageDialog(Get.context!, "Try Again!!", error.toString());
  });
}