// It's better to set no HttpMethods(HttpGet, HttpPost, etc.) for the Verify action, // because the banks send their information with different http methods // درگاههای بانکی، اطلاعات خود را با متدهای مختلفی ارسال میکنند // بنابراین بهتر است هیچگونه خصوصیتی برای این اکشن متد در نظر گرفته نشود public async Task <ActionResult> Verify() { var invoice = await _onlinePayment.FetchAsync(); if (Is_There_Still_Product_In_Shop(invoice.TrackingNumber)) { var verifyResult = await _onlinePayment.VerifyAsync(invoice); return(View(verifyResult)); } var cancelResult = await _onlinePayment.CancelAsync(invoice, cancellationReason : "Sorry, We have no more products to sell."); return(View("CancelResult", cancelResult)); }
public async Task <IActionResult> Verify(string token = null) { if (!string.IsNullOrEmpty(token)) { var factor = await _dbFinancial.FactorRepository.GetByIdAsync(token); factor.IsAlreadyVerified = false; factor.DateModified = DateTime.Now; factor.Message = "کاربر پرداخت را کنسل کرده است"; _dbFinancial.FactorRepository.Update(factor); await _dbFinancial.SaveAcync(); return(Redirect(factor.RedirectUrl + "?token=" + factor.Id)); } var invoice = await _onlinePayment.FetchAsync(); var factorFromRepo = (await _dbFinancial.FactorRepository .GetAllAsync(p => p.RefBank == invoice.TrackingNumber.ToString(), null, "")).SingleOrDefault(); if (invoice.Status == PaymentFetchResultStatus.AlreadyProcessed) { factorFromRepo.IsAlreadyVerified = true; factorFromRepo.DateModified = DateTime.Now; factorFromRepo.Message = "این تراکنش قبلا برررسی شده است"; factorFromRepo.GatewayName = invoice.GatewayName; _dbFinancial.FactorRepository.Update(factorFromRepo); await _dbFinancial.SaveAcync(); } else { factorFromRepo.IsAlreadyVerified = invoice.IsAlreadyVerified; factorFromRepo.DateModified = DateTime.Now; factorFromRepo.Message = "پرداخت با موفقیت انجام شد اما توسط کاربر تایید نشده است"; factorFromRepo.GatewayName = invoice.GatewayName; _dbFinancial.FactorRepository.Update(factorFromRepo); await _dbFinancial.SaveAcync(); } return(Redirect(factorFromRepo.RedirectUrl + "?token=" + factorFromRepo.Id)); }
public async Task <IActionResult> Verify() { var invoice = await _onlinePayment.FetchAsync(); var order = _orderRepository.GetOrderByPaymentTrackingNumber(invoice.TrackingNumber); if (invoice.Status == PaymentFetchResultStatus.ReadyForVerifying) { var verifyResult = await _onlinePayment.VerifyAsync(invoice); _orderRepository.UpdateOrder(order, verifyResult.IsSucceed, verifyResult.Message, verifyResult.TransactionCode); } else { _orderRepository.OrderFailed(order, invoice.Message); } var clientAppUrl = "http://localhost:5000/payment-result/" + order.Id; return(Redirect(clientAppUrl)); }
// It's better to set no HttpMethods(HttpGet, HttpPost, etc.) for the Verify action, // because the banks send their information with different HTTP methods public async Task <ActionResult> Verify() { var invoice = await _onlinePayment.FetchAsync(); // Check if the invoice is new or it's already processed before. if (invoice.Status == PaymentFetchResultStatus.AlreadyProcessed) { // You can also see if the invoice is already verified before. var isAlreadyVerified = invoice.IsAlreadyVerified; return(Content("The payment is already processed before.")); } // This is an example of cancelling an invoice when you think that the payment process must be stopped. if (!Is_There_Still_Product_In_Shop(invoice.TrackingNumber)) { var cancelResult = await _onlinePayment.CancelAsync(invoice, cancellationReason : "Sorry, We have no more products to sell."); return(View("CancelResult", cancelResult)); } var verifyResult = await _onlinePayment.VerifyAsync(invoice); return(View(verifyResult)); }
/// <summary> /// Fetches the invoice by the given tracking number. /// </summary> /// <param name="onlinePayment"></param> /// <param name="trackingNumber">Invoice's tracking number.</param> /// <exception cref="PaymentTokenProviderException"></exception> /// <exception cref="InvoiceNotFoundException"></exception> public static IPaymentFetchResult Fetch(this IOnlinePayment onlinePayment, long trackingNumber) => onlinePayment.FetchAsync(trackingNumber).GetAwaiter().GetResult();
/// <summary> /// Fetches the invoice from the incoming request. /// </summary> /// <param name="onlinePayment"></param> /// <exception cref="PaymentTokenProviderException"></exception> /// <exception cref="InvoiceNotFoundException"></exception> public static IPaymentFetchResult Fetch(this IOnlinePayment onlinePayment) => onlinePayment.FetchAsync().GetAwaiter().GetResult();
public async Task <IActionResult> Verify(string token = null, string error = null) { if (!string.IsNullOrEmpty(error)) { if (!string.IsNullOrEmpty(token)) { var factor = await _dbFinancial.FactorRepository.GetByIdAsync(token); factor.IsAlreadyVerified = true; factor.DateModified = DateTime.Now; factor.Message = error; _dbFinancial.FactorRepository.Update(factor); await _dbFinancial.SaveAsync(); model.Status = false; model.Message = error; model.Result = factor; return(View(model)); } else { model.Status = false; model.Message = error; model.Result = null; return(View(model)); } } var invoice = await _onlinePayment.FetchAsync(); var factorFromRepo = (await _dbFinancial.FactorRepository .GetManyAsync(p => p.RefBank == invoice.TrackingNumber.ToString(), null, "")).SingleOrDefault(); if (invoice.Status == PaymentFetchResultStatus.AlreadyProcessed) { factorFromRepo.IsAlreadyVerified = true; factorFromRepo.DateModified = DateTime.Now; factorFromRepo.Message = "این تراکنش قبلا برررسی شده است"; factorFromRepo.GatewayName = invoice.GatewayName; _dbFinancial.FactorRepository.Update(factorFromRepo); await _dbFinancial.SaveAsync(); model.Status = false; model.Message = "این تراکنش قبلا برررسی شده است"; model.Result = factorFromRepo; return(View(model)); } else { //Verify var trackingNumber = Convert.ToInt64(factorFromRepo.RefBank); var verifyResult = await _onlinePayment.VerifyAsync(trackingNumber); if (verifyResult.IsSucceed) { factorFromRepo.Status = true; factorFromRepo.IsAlreadyVerified = true; factorFromRepo.DateModified = DateTime.Now; factorFromRepo.Message = "تراکنش با موفقیت انجام شد"; _dbFinancial.FactorRepository.Update(factorFromRepo); await _dbFinancial.SaveAsync(); await _walletService .IncreaseInventoryAsync(factorFromRepo.EndPrice, factorFromRepo.EnterMoneyWalletId, false); model.Status = true; model.Message = "تراکنش با موفقیت انجام شد"; model.Result = factorFromRepo; return(View(model)); } else { factorFromRepo.IsAlreadyVerified = true; factorFromRepo.DateModified = DateTime.Now; factorFromRepo.Message = verifyResult.Message; _dbFinancial.FactorRepository.Update(factorFromRepo); await _dbFinancial.SaveAsync(); model.Status = false; model.Message = verifyResult.Message; model.Result = factorFromRepo; return(View(model)); } } }