private async Task<Result<GTokenTransactionModel>> ExecuteGTokenTransaction(Result<GTokenTransactionModel> gTokenTransaction, GoEatApi goEatApi) { //execute transaction gTokenTransaction.Data.transaction.status = ConstantValues.S_SUCCESS; gTokenTransaction = await goEatApi.ExecuteGTokenTransaction(gTokenTransaction.Data.transaction); return gTokenTransaction; }
// Call CreateGtoken to Gtoken api in cases we use cash in transaction private async Task<Result<GTokenTransactionModel>> CreateGToken(GoEatApi goEatApi, decimal discountRate, string orderId, decimal originalPrice, decimal cash, string username, string description, decimal orginal_tax, decimal original_service_charge) { var gTokenTransaction = goEatApi.CreateGTokenTransaction(new GTokenTransaction { currency = ConstantValues.S_CURRENCY_SGD, discount_percentage = discountRate, order_id = orderId, original_currency = ConstantValues.S_CURRENCY_SGD, original_price = originalPrice, original_final_amount = cash, username = username, status = ConstantValues.S_PENDING, payment_method = ConstantValues.S_PAYMENT_METHOD, description = description, is_venvici_applicable = true, original_tax = orginal_tax, original_service_charge = original_service_charge }); if (!gTokenTransaction.Succeeded) { return gTokenTransaction; } //execute transaction gTokenTransaction.Data.transaction.status = ConstantValues.S_SUCCESS; gTokenTransaction = await goEatApi.ExecuteGTokenTransaction(gTokenTransaction.Data.transaction); return gTokenTransaction; }
private async Task<Result<GTokenTransactionModel>> CreateGTokenTransaction(GoEatApi goEatApi, decimal discountRate, string orderId, decimal originalPrice, string username, string description, decimal original_tax, decimal original_service_charge) { decimal amountAfterDiscount = originalPrice * (1 - discountRate); decimal amountServiceCharge = amountAfterDiscount * original_service_charge; decimal amountGst = (amountAfterDiscount + amountServiceCharge) * original_tax; var gTokenTransaction = goEatApi.CreateGTokenTransaction(new GTokenTransaction { currency = ConstantValues.S_CURRENCY_SGD, discount_percentage = discountRate, order_id = orderId, original_currency = ConstantValues.S_CURRENCY_SGD, original_price = originalPrice, original_final_amount = originalPrice * (1 - discountRate), username = username, status = ConstantValues.S_PENDING, payment_method = ConstantValues.S_PAYMENT_METHOD, description = description, is_venvici_applicable = true, original_tax = amountGst, original_service_charge = amountServiceCharge }); if (!gTokenTransaction.Succeeded) { return gTokenTransaction; } return gTokenTransaction; }
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 }); }