コード例 #1
0
        public SingleResult <string> VerifyPayment(string authority, string status)
        {
            try
            {
                var orderpeymnt = _repository.CustomerOrderPayment.FindByCondition(c => c.TraceNo == authority)
                                  .FirstOrDefault();
                if (orderpeymnt == null)
                {
                    throw new BusinessException(XError.BusinessErrors.PaymentInfoNotFound());
                }


                var customerOrderId = orderpeymnt.CustomerOrderId;
                var customer        = _repository.CustomerOrder.FindByCondition(c => c.Id == customerOrderId)
                                      .Include(c => c.Customer).Select(c => c.Customer).First();

                var zarinPalVerifyRequest = new ZarinPalVerifyRequest
                {
                    authority = authority,
                    amount    = (int)orderpeymnt.TransactionPrice.Value * 10
                };

                var zarinPal = new ZarinPal();
                var result   = zarinPal.VerifyPayment(zarinPalVerifyRequest);
                if (result.code == 100 || result.code == 101)
                {
                    orderpeymnt.FinalStatusId   = 24;
                    orderpeymnt.RefNum          = result.ref_id.ToString();
                    orderpeymnt.TransactionDate = DateTime.Now.Ticks;
                    orderpeymnt.CardPan         = result.card_pan;
                    _repository.CustomerOrderPayment.Update(orderpeymnt);

                    var sendSms = new SendSMS();
                    sendSms.SendSuccessOrderPayment(customer.Mobile.Value, orderpeymnt.OrderNo, orderpeymnt.PaymentPrice.Value);

                    var sendEmail = new SendEmail();
                    var email     = customer.Email;
                    sendEmail.SendSuccessOrderPayment(email, orderpeymnt.OrderNo, customerOrderId.Value);



                    var productist = _repository.CustomerOrderProduct.FindByCondition(c => c.CustomerOrderId == customerOrderId).Select(c => c.Product).ToList();
                    productist.ForEach(c =>
                    {
                        c.Count = c.Count--;
                        _repository.Product.Update(c);
                    });


                    var sellerList = _repository.CustomerOrderProduct.FindByCondition(c => c.CustomerOrderId == customerOrderId).Select(c => c.Seller.Mobile).ToList();

                    sellerList.ForEach(c =>
                    {
                        if (c == null)
                        {
                            return;
                        }
                        var sendSms = new SendSMS();
                        sendSms.SendOrderSmsForSeller(c.Value);
                    });


                    _repository.Save();

                    var finalres = SingleResult <string> .GetSuccessfulResult("عملیات پرداخت با موفقیت انجام شد.");

                    _logger.LogData(MethodBase.GetCurrentMethod(), finalres, null, customerOrderId);
                    return(finalres);
                }
                else
                {
                    orderpeymnt.FinalStatusId   = 25;
                    orderpeymnt.TransactionDate = DateTime.Now.Ticks;
                    _repository.CustomerOrderPayment.Update(orderpeymnt);
                    _repository.Save();

                    throw new BusinessException(XError.BusinessErrors.FailedPayment());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), authority, status);

                return(SingleResult <string> .GetFailResult("خطا در سامانه"));
            }
        }
コード例 #2
0
        public SingleResult <string> VerifyWalletCharge(string authority, string status)
        {
            try
            {
                var wallet = _repository.CustomerWalletCharge.FindByCondition(c => c.TraceNo == authority)
                             .FirstOrDefault();
                if (wallet == null)
                {
                    throw new BusinessException(XError.BusinessErrors.PaymentInfoNotFound());
                }



                var customer = _repository.CustomerOrder.FindByCondition(c => c.Id == wallet.CustomerId)
                               .Include(c => c.Customer).Select(c => c.Customer).First();

                var zarinPalVerifyRequest = new ZarinPalVerifyRequest
                {
                    authority = authority,
                    amount    = (int)wallet.ChargePrice.Value * 10
                };

                var zarinPal = new ZarinPal();
                var result   = zarinPal.VerifyPayment(zarinPalVerifyRequest);
                if (result.code == 100 || result.code == 101)
                {
                    wallet.FinalStatusId = 40;
                    wallet.RefNum        = result.ref_id.ToString();
                    wallet.ChargeDate    = DateTime.Now.Ticks;
                    wallet.BankCard      = result.card_pan;
                    _repository.CustomerWalletCharge.Update(wallet);



                    customer.WalletFinalPrice += wallet.ChargePrice;
                    _repository.Customer.Update(customer);
                    _repository.Save();

                    var sendSms = new SendSMS();
                    sendSms.SendWalletSuccessChargeSms(customer.Mobile.Value, wallet.ChargePrice.ToString(), customer.Name + " " + customer.Name);

                    var finalres = SingleResult <string> .GetSuccessfulResult("عملیات پرداخت با موفقیت انجام شد.");

                    _logger.LogData(MethodBase.GetCurrentMethod(), finalres, null, authority, status);
                    return(finalres);
                }
                else
                {
                    wallet.FinalStatusId = 41;
                    wallet.ChargeDate    = DateTime.Now.Ticks;
                    _repository.CustomerWalletCharge.Update(wallet);
                    _repository.Save();

                    throw new BusinessException(XError.BusinessErrors.FailedPayment());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), authority, status);

                return(SingleResult <string> .GetFailResult(e.Message));
            }
        }