/// <summary>
        /// Verifies the given invoice.
        /// </summary>
        /// <param name="onlinePayment"></param>
        /// <param name="invoice"></param>
        /// <exception cref="InvoiceNotFoundException"></exception>
        public static IPaymentVerifyResult Verify(this IOnlinePayment onlinePayment, IPaymentFetchResult invoice)
        {
            if (invoice == null)
            {
                throw new ArgumentNullException(nameof(invoice));
            }

            return(onlinePayment.VerifyAsync(invoice.TrackingNumber).GetAwaiter().GetResult());
        }
        /// <summary>
        /// Verifies the given invoice.
        /// </summary>
        /// <param name="onlinePayment"></param>
        /// <param name="invoice"></param>
        /// <param name="cancellationToken"></param>
        /// <exception cref="InvoiceNotFoundException"></exception>
        public static Task <IPaymentVerifyResult> VerifyAsync(
            this IOnlinePayment onlinePayment,
            IPaymentFetchResult invoice,
            CancellationToken cancellationToken = default)
        {
            if (invoice == null)
            {
                throw new ArgumentNullException(nameof(invoice));
            }

            return(onlinePayment.VerifyAsync(invoice.TrackingNumber, cancellationToken));
        }
Ejemplo n.º 3
0
        // 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));
        }
Ejemplo n.º 4
0
        // 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 result = await _onlinePayment.VerifyAsync(invoice =>
            {
                // You can check your database, whether or not you have still products to sell
                // در این مرحله هنوز درخواست تأیید و واریز وجه از وب سایت شما به بانک ارسال نشده است
                // بنابراین شما می توانید اطلاعات صورتحساب را با پایگاه داده خود چک کنید
                // و در صورت لزوم تراکنش را لغو کنید

                if (!Is_There_Still_Enough_SmartPhone_In_Shop(invoice.TrackingNumber))
                {
                    invoice.CancelPayment("We have no more smart phones to sell.");
                }
            });

            // Note: This is just for development and testing.
            // Don't show the actual result object to clients in production environment.
            // Instead, show only the important information such as IsSucceed, Tracking Number and Transaction Code.
            return(View(result));
        }
        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));
        }
Ejemplo n.º 6
0
        // 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>
 /// Verifies the given invoice.
 /// </summary>
 /// <param name="onlinePayment"></param>
 /// <param name="trackingNumber">The tracking number of the invoice which must be verified.</param>
 /// <exception cref="InvoiceNotFoundException"></exception>
 public static IPaymentVerifyResult Verify(this IOnlinePayment onlinePayment, long trackingNumber)
 => onlinePayment.VerifyAsync(trackingNumber).GetAwaiter().GetResult();
Ejemplo n.º 8
0
 public static IPaymentVerifyResult Verify(
     this IOnlinePayment onlinePayment,
     Action <IPaymentVerifyingContext> paymentVerifyingContext)
 => onlinePayment.VerifyAsync(paymentVerifyingContext)
 .GetAwaiter()
 .GetResult();
        public async Task <IActionResult> VerifySend(VerifyRequestDto verifyRequestDto)
        {
            var model = new GateApiReturn <VerifyResponseDto>
            {
                Status = true
            };
            //Error
            var factorFromRepo = await _dbFinancial.FactorRepository.GetByIdAsync(verifyRequestDto.Token);

            if (factorFromRepo == null)
            {
                errorModel.Messages.Clear();
                errorModel.Messages = new string[] { "تراکنشی با این مشخصات یافت نشد" };
                return(BadRequest(errorModel));
            }
            if (factorFromRepo.DateModified.AddMinutes(20) < DateTime.Now)
            {
                errorModel.Messages.Clear();
                errorModel.Messages = new string[] { "زمان تایید تراکنش شما گذشته است" };
                return(BadRequest(errorModel));
            }
            if (factorFromRepo.IsAlreadyVerified)
            {
                errorModel.Messages.Clear();
                errorModel.Messages = new string[] { "این تراکنش قبلا بررسی شده است" };
                return(BadRequest(errorModel));
            }
            var gateFromRepo = (await _db.GateRepository.GetManyAsync(p => p.Id == verifyRequestDto.Api, null, "Wallet")).SingleOrDefault();

            if (gateFromRepo == null)
            {
                errorModel.Messages.Clear();
                errorModel.Messages = new string[] { "Api درگاه معتبر نمیباشد" };
                return(BadRequest(errorModel));
            }
            var userDocuments = await _db.DocumentRepository
                                .GetManyAsync(p => p.Approve == 1 && p.UserId == gateFromRepo.Wallet.UserId, null, "");

            if (!userDocuments.Any())
            {
                errorModel.Messages.Clear();
                errorModel.Messages = new string[] { "مدارک کاربر صاحب درگاه تکمیل نمیباشد" };
                return(BadRequest(errorModel));
            }
            if (!gateFromRepo.IsActive)
            {
                errorModel.Messages.Clear();
                errorModel.Messages = new string[] { "این درگاه غیر فعال میباشد . درصورت نیاز با پشتیبانی در تماس باید" };
                return(BadRequest(errorModel));
            }
            if (gateFromRepo.IsIp)
            {
                var currentIp     = HttpContext.Connection.RemoteIpAddress.ToString(); //::1
                var gateWebsiteIp = await _utilities.GetDomainIpAsync(gateFromRepo.WebsiteUrl);

                if (currentIp != gateWebsiteIp)
                {
                    errorModel.Messages.Clear();
                    errorModel.Messages = new string[] { "آی پی وبسایت درخواست دهنده پرداخت معبتر نمیباشد" };
                    return(BadRequest(errorModel));
                }
            }


            //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, true);

                model.Messages.Clear();
                model.Messages = new string[] { "تراکنش با موفقیت انجام شد" };
                model.Result   = new VerifyResponseDto
                {
                    Amount       = factorFromRepo.EndPrice,
                    FactorNumber = factorFromRepo.FactorNumber,
                    RefBank      = "MPC-" + factorFromRepo.RefBank,
                    Mobile       = factorFromRepo.Mobile,
                    Email        = factorFromRepo.Email,
                    Description  = factorFromRepo.Description,
                    CardNumber   = factorFromRepo.ValidCardNumber
                };
                return(Ok(model));
            }
            else
            {
                factorFromRepo.IsAlreadyVerified = true;
                factorFromRepo.DateModified      = DateTime.Now;
                factorFromRepo.Message           = verifyResult.Message;
                _dbFinancial.FactorRepository.Update(factorFromRepo);
                await _dbFinancial.SaveAsync();


                errorModel.Messages.Clear();
                errorModel.Messages = new string[] { verifyResult.Message };
                return(BadRequest(errorModel));
            }
        }
Ejemplo n.º 10
0
        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));
                }
            }
        }