private async Task<JsonResult> UpdateFinalTransaction(GoEatApi goEatApi, ConfirmTransaction model, decimal discountRate)
        {
            Result<MainTransaction> mainTransaction = goEatApi.GetMainTransaction(model.id);

            var customer = goEatApi.GetUserById(model.customer_id);
            string gtoken_transaction_id = string.Empty;
            string description = string.Empty;// GToken.Dal.ConstantValues.S_DESCRIPTION;
            string encodeOrderId = Cryptogahpy.Base64Encode(string.Format("{0}-{1}-{2}", model.restaurant_id, model.order_id, model.customer_id));

            //if user is venvici member and their bill using cash only

            if (customer.Data.Profile.is_venvici_member
                && model.token_amount == 0
                && model.cash_amount > 0)
            {
                //Call creating transaction of GToken
                //var gTokenTransaction = await CreateGToken(goEatApi, discountRate, encodeOrderId, model.original_price,
                //    customer.Data.Profile.account, GToken.Dal.ConstantValues.S_DESCRIPTION);

                var gTokenTransaction = await CreateGTokenTransaction(goEatApi, discountRate, encodeOrderId, model.original_price,
                    customer.Data.Profile.account, ConstantValues.S_DESCRIPTION_AMOUNT_WITH_CASH, ConstantValues.D_GST, ConstantValues.D_SERVICE_CHARGE);

                if (!gTokenTransaction.Succeeded)
                {
                    //TODO: need update status fail for transaction and notify to user ???,
                    return Json(new
                    {
                        success = false,
                        error_code = "CreateGTokenTransaction:" + gTokenTransaction.Error.ToString()
                    });
                }

                var exeGTokenTransaction = await ExecuteGTokenTransaction(gTokenTransaction, goEatApi);

                if (!exeGTokenTransaction.Succeeded)
                {
                    //TODO: need update status fail for transaction and notify to user ???
                    return Json(new
                    {
                        success = false,
                        error_code = "ExecuteGTokenTransaction:" + exeGTokenTransaction.Error.ToString()
                    });
                }

                gtoken_transaction_id = gTokenTransaction.Data.transaction.gtoken_transaction_id;
                description = gTokenTransaction.Data.transaction.description;
            }
            else
            {
                decimal amountAfterDiscount = model.original_price * (1 - discountRate);
                decimal amountServiceCharge = amountAfterDiscount * ConstantValues.D_SERVICE_CHARGE;
                decimal amountGst = (amountAfterDiscount + amountServiceCharge) * ConstantValues.D_GST;

                if (model.token_amount == 0)
                {
                    await goEatApi.RecordTokenTransaction(new GRecordTokenTransaction
                    {
                        username = customer.Data.Profile.account,
                        order_id = encodeOrderId,
                        gtoken_transaction_id = gtoken_transaction_id,
                        token_type = ConstantValues.S_SGD,
                        transaction_type = ConstantValues.S_TRANSACTION_TYPE_CONSUMPTION,
                        amount = model.cash_amount,
                        description = ConstantValues.S_DESCRIPTION_AMOUNT_WITH_CASH,
                        tax = amountGst,
                        service_charge = amountServiceCharge
                    });
                }
                else if (model.cash_amount == 0)
                {
                    await goEatApi.RecordTokenTransaction(new GRecordTokenTransaction
                    {
                        username = customer.Data.Profile.account,
                        order_id = encodeOrderId,
                        gtoken_transaction_id = gtoken_transaction_id,
                        token_type = ConstantValues.S_SUGAR_TOKEN,
                        transaction_type = ConstantValues.S_TRANSACTION_TYPE_CONSUMPTION,
                        amount = model.token_amount,
                        description = ConstantValues.S_DESCRIPTION_AMOUNT_WITH_TOKEN,
                        tax = amountGst,
                        service_charge = amountServiceCharge
                    });
                }
                else
                {
                    await goEatApi.RecordTokenTransaction(new GRecordTokenTransaction
                    {
                        username = customer.Data.Profile.account,
                        order_id = encodeOrderId,
                        gtoken_transaction_id = gtoken_transaction_id,
                        token_type = ConstantValues.S_SUGAR_TOKEN,
                        transaction_type = ConstantValues.S_TRANSACTION_TYPE_CONSUMPTION,
                        amount = model.token_amount,
                        description = ConstantValues.S_DESCRIPTION_AMOUNT_WITH_TOKEN,
                        tax = amountGst,
                        service_charge = amountServiceCharge
                    });


                    await goEatApi.RecordTokenTransaction(new GRecordTokenTransaction
                    {
                        username = customer.Data.Profile.account,
                        order_id = encodeOrderId + "_extra",
                        gtoken_transaction_id = gtoken_transaction_id,
                        token_type = ConstantValues.S_SGD,
                        transaction_type = ConstantValues.S_TRANSACTION_TYPE_CONSUMPTION,
                        amount = model.cash_amount,
                        description = ConstantValues.S_DESCRIPTION_AMOUNT_WITH_CASH,
                        tax = amountGst,
                        service_charge = amountServiceCharge
                    });
                }
            }

            bool result = goEatApi.UpdateFinalTransaction(
                gtoken_transaction_id, description,
                mainTransaction.Data.id, ConstantValues.S_SUCCESS,
                model.customer_id, model.token_amount);

            return Json(new
            {
                success = result,
                error_code = string.Empty
            });
        }