コード例 #1
0
        public SingleResult <ChargeWalletResponse> ChargeWallet(long price)
        {
            try
            {
                var userId   = ClaimPrincipalFactory.GetUserId(User);
                var user     = _repository.Users.FindByCondition(c => c.Id == userId).FirstOrDefault();
                var customer = _repository.Customer.FindByCondition(c => c.UserId == userId).FirstOrDefault();
                var now      = DateTime.Now.Ticks;

                var request = new ZarinPallRequest
                {
                    amount      = (int)((price) * 10),
                    description = "order NO: " + now,
                    metadata    = new ZarinPalRequestMetaData
                    {
                        mobile = "0" + user.Mobile.ToString(),
                        email  = user.Email
                    }
                };
                var zarinPal = new ZarinPal();
                var res      = zarinPal.Request(request);

                var wallet = new CustomerWalletCharge
                {
                    Cdate         = now,
                    CuserId       = userId,
                    ChargePrice   = price,
                    CustomerId    = customer.Id,
                    FinalStatusId = 38,
                    OrderNo       = now,
                    TraceNo       = res.authority
                };
                _repository.CustomerWalletCharge.Create(wallet);
                _repository.Save();
                var result = new ChargeWalletResponse
                {
                    OrderNo = now,
                    CustomerWalletChargeId = wallet.Id,
                    BankUrl        = "https://www.zarinpal.com/pg/StartPay/" + res.authority,
                    RedirectToBank = true,
                };



                var finalres = SingleResult <ChargeWalletResponse> .GetSuccessfulResult(result);

                _logger.LogData(MethodBase.GetCurrentMethod(), finalres, null, price);
                return(finalres);
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), price);
                return(SingleResult <ChargeWalletResponse> .GetFailResult(e.Message));
            }
        }
コード例 #2
0
        public SingleResult <string> MakePaymentByOrderId(long customerOrderId)
        {
            try
            {
                var userId        = ClaimPrincipalFactory.GetUserId(User);
                var customerId    = _repository.Customer.FindByCondition(c => c.UserId == userId).Select(c => c.Id).FirstOrDefault();
                var customerOrder = _repository.CustomerOrder.FindByCondition(c => c.Id == customerOrderId && c.CustomerId == customerId).FirstOrDefault();

                if (customerOrder == null)
                {
                    throw new BusinessException(XError.BusinessErrors.InvalidOrder());
                }

                var request = new ZarinPallRequest
                {
                    amount      = (int)((customerOrder.FinalPrice.Value + customerOrder.PostServicePrice) * 10),
                    description = "order NO: " + customerOrder.OrderNo
                };
                var zarinPal = new ZarinPal();
                var res      = zarinPal.Request(request);

                var customerOrderPayment = new CustomerOrderPayment
                {
                    OrderNo          = customerOrder.OrderNo.ToString(),
                    TraceNo          = res.authority,
                    TransactionPrice = customerOrder.FinalPrice,
                    TransactionDate  = DateTime.Now.Ticks,
                    Cdate            = DateTime.Now.Ticks,
                    CuserId          = userId,
                    PaymentPrice     = customerOrder.FinalPrice,
                    FinalStatusId    = 26
                };
                _repository.CustomerOrderPayment.Create(customerOrderPayment);
                _repository.Save();
                var finalres = SingleResult <string> .GetSuccessfulResult("https://www.zarinpal.com/pg/StartPay/" + res.authority);

                _logger.LogData(MethodBase.GetCurrentMethod(), finalres, null, customerOrderId);
                return(finalres);
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), customerOrderId);

                return(SingleResult <string> .GetFailResult(e.Message));
            }
        }
コード例 #3
0
 public ActionResult ZarinpalPaymentVerification(int id, string authority, string Status)
 {
     if (!string.IsNullOrEmpty(Status) && !string.IsNullOrEmpty(authority))
     {
         if (Status.Equals("OK"))
         {
             var    requestitem = auditTempRepository.GetItem(id);
             long   refID;
             string MerchantID = "e53f3f7c-d9f1-11e8-a28f-000c295eb8fc";
             var    FinalPrice = requestitem.Price - (requestitem.Price / 10);
             int    statuses   = ZarinPal.ZarinpalPaymentVerification(MerchantID, authority, FinalPrice, out refID);
             if (statuses == 100 || statuses == 101)
             {
                 ViewBag.RefId = "کد پیگیری: " + refID + " - کد سفارش: " + id;
                 auditTempRepository.Edit(id, refID, authority, 2, FinalPrice);
                 TempData["RefId"]     = refID;
                 TempData["OrdeID"]    = id;
                 TempData["authority"] = authority;
                 var audit = auditTempRepository.GetItem(id);
                 audit.RequestDatePersian = new PersianDateTime(audit.RequestDate).ToString(PersianDateTimeFormat.Date);
                 auditRepository.Create(audit);
                 TempData["SuccessAudit"] = "Success";
                 return(RedirectToAction("Index"));
             }
             else
             {
                 TempData["FailAudit"] = ZarinPal.GetMessage(statuses);
             }
         }
         else
         {
             TempData["FailAudit"] = "کد مرجع: " + Request.QueryString["Authority"] + " - وضعیت:" + Request.QueryString["Status"];
         }
     }
     else
     {
         TempData["FailAudit"] = "ورودی نامعتبر است.";
     }
     return(RedirectToAction("Index"));
 }
コード例 #4
0
        public ActionResult ZarinPalPayment(int ID)
        {
            var    requestitem = auditTempRepository.GetItem(ID);
            string MerchantID  = "e53f3f7c-d9f1-11e8-a28f-000c295eb8fc";
            string authority;
            var    urlWebConfig = ConfigurationManager.AppSettings["ZarinPalPayment"];
            string CallbackURL  = "http://" + Request.Url.Authority + urlWebConfig + "/" + requestitem.ID;
            var    FinalPrice   = requestitem.Price - (requestitem.Price / 10);
            int    status       = ZarinPal.ZarinpalPayment(MerchantID, FinalPrice, " کارشناسی برای " + requestitem.CarModelTitle + " " + requestitem.CarManufactureTitle, requestitem.Email, requestitem.Phone, CallbackURL, out authority);

            if (status == 100)
            {
                ////For release mode
                Response.Redirect("https://zarinpal.com/pg/StartPay/" + authority);
                ////For test mode
                //Response.Redirect("https://sandbox.zarinpal.com/pg/StartPay/" + authority);
                return(null);
            }
            TempData["authority"] = authority;
            TempData["Message"]   = ZarinPal.GetMessage(status);
            return(View("Detail", requestitem));
        }
コード例 #5
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("خطا در سامانه"));
            }
        }
コード例 #6
0
        public SingleResult <InsertOrderResultDto> GetProductByIdList_UI(OrderModel order)
        {
            try
            {
                var userId          = ClaimPrincipalFactory.GetUserId(User);
                var cc              = _repository.Customer.FindByCondition(c => c.UserId == userId).FirstOrDefault();
                var customerId      = cc.Id;
                var today           = DateTime.Now.AddDays(-1).Ticks;
                var orerProductList = new List <CustomerOrderProduct>();


                var orderNo = customerId.ToString() + DateTimeFunc.TimeTickToShamsi(DateTime.Now.Ticks).Replace("/", "") +
                              (_repository.CustomerOrder.FindByCondition(c => c.CustomerId == customerId && today > c.Cdate)
                               .Count() + 1).ToString().PadLeft(3, '0');


                order.ProductList.ForEach(c =>
                {
                    var product     = _repository.Product.FindByCondition(x => x.Id == c.ProductId).First();
                    var ofer        = _repository.Offer.FindByCondition(x => x.Id == c.OfferId).FirstOrDefault();
                    var packingType = _repository.ProductPackingType.FindByCondition(x => x.Id == c.PackingTypeId)
                                      .FirstOrDefault();
                    var statusId     = _repository.Status.GetSatusId("CustomerOrderProduct", 2);
                    var orderproduct = new CustomerOrderProduct
                    {
                        OrderCount           = c.Count,
                        ProductId            = c.ProductId,
                        Cdate                = DateTime.Now.Ticks,
                        CuserId              = userId,
                        OrderType            = 1,
                        ProductCode          = product.Coding,
                        ProductIncreasePrice = null,
                        ProductName          = product.Name,
                        ProductPrice         = product.Price,
                        ProductOfferId       = c.OfferId,
                        ProductOfferCode     = ofer?.OfferCode,
                        ProductOfferPrice    = (long?)(ofer != null ? (ofer.Value / 100 * product.Price) : 0),
                        ProductOfferValue    = ofer?.Value,
                        PackingTypeId        = packingType?.PackinggTypeId,
                        PackingWeight        = packingType == null ? 0 : packingType.Weight,
                        PackingPrice         = packingType == null ? 0 : packingType.Price,
                        SellerId             = product.SellerId,
                        Weight               = c.Count * product.Weight,
                        FinalWeight          = (c.Count * product.Weight) + (c.Count * (packingType == null ? 0 : packingType.Weight)),
                        FinalStatusId        = statusId
                    };
                    orerProductList.Add(orderproduct);
                });

                var offer         = _repository.Offer.FindByCondition(c => c.Id == order.OfferId).FirstOrDefault();
                var paking        = _repository.PackingType.FindByCondition(c => c.Id == order.PaymentTypeId).FirstOrDefault();
                var customerOrder = new CustomerOrder
                {
                    Cdate               = DateTime.Now.Ticks,
                    CuserId             = userId,
                    CustomerAddressId   = order.CustomerAddressId,
                    CustomerDescription = order.CustomerDescription,
                    CustomerId          = customerId,
                    FinalStatusId       = _repository.Status.GetSatusId("CustomerOrder", 1),
                    OfferId             = order.OfferId,
                    OrderPrice          = orerProductList.Sum(x =>
                                                              ((x.PackingPrice + x.ProductPrice - x.ProductOfferPrice) * x.OrderCount))
                };

                customerOrder.OrderPrice = orerProductList.Sum(c =>
                                                               (c.ProductPrice + c.PackingPrice - c.ProductOfferPrice) * c.OrderCount);
                customerOrder.OfferPrice =
                    (long?)(customerOrder.OrderPrice * (offer == null ? 0 : offer.Value / 100));
                customerOrder.OfferValue       = (int?)offer?.Value;
                customerOrder.OrderDate        = DateTime.Now.Ticks;
                customerOrder.FinalWeight      = orerProductList.Sum(x => x.FinalWeight);
                customerOrder.OrderNo          = Convert.ToInt64(orderNo);
                customerOrder.OrderProduceTime = 0;
                customerOrder.OrderType        = 1;
                customerOrder.OrderWeight      = customerOrder.FinalWeight;
                customerOrder.PackingPrice     = 0;
                customerOrder.PackingWeight    = 0;
                customerOrder.PaymentTypeId    = order.PaymentTypeId;
                customerOrder.PostServicePrice = 0;
                customerOrder.PostTypeId       = order.PostTypeId;

                //customerOrder.TaxPrice = (long?)((customerOrder.OrderPrice - customerOrder.OfferPrice) * 0.09);
                //customerOrder.TaxValue = 9;
                customerOrder.TaxPrice = 0;
                customerOrder.TaxValue = 9;


                customerOrder.CustomerOrderProduct = orerProductList;
                var toCityId = _repository.CustomerAddress.FindByCondition(c => c.Id == order.CustomerAddressId).Include(c => c.City).Select(c => c.City.PostCode).FirstOrDefault();


                var postType = _repository.PostType.FindByCondition(c => c.Id == order.PostTypeId).FirstOrDefault();
                var payType  = _repository.PaymentType.FindByCondition(c => c.Id == order.PaymentTypeId)
                               .FirstOrDefault();

                if (postType.IsFree.Value)
                {
                    customerOrder.PostServicePrice = 0;
                }
                else
                {
                    var post           = new PostServiceProvider();
                    var postpriceparam = new PostGetDeliveryPriceParam
                    {
                        Price       = (int)customerOrder.OrderPrice.Value,
                        Weight      = (int)customerOrder.FinalWeight.Value,
                        ServiceType = postType?.Rkey ?? 2,// (int)customerOrder.PostTypeId,
                        ToCityId    = (int)toCityId,
                        PayType     = (int)(payType?.Rkey ?? 88)
                    };
                    var postresult = post.GetDeliveryPrice(postpriceparam).Result;
                    if (postresult.ErrorCode != 0)
                    {
                        throw new BusinessException(XError.IncomingSerivceErrors.PostSeerivcError());
                    }
                    customerOrder.PostServicePrice = (postresult.PostDeliveryPrice + postresult.VatTax) / 10;
                }


                customerOrder.FinalPrice = customerOrder.OrderPrice + customerOrder.TaxPrice + customerOrder.PostServicePrice;
                _repository.CustomerOrder.Create(customerOrder);



                var request = new ZarinPallRequest
                {
                    //  amount = (int)((customerOrder.FinalPrice.Value + customerOrder.PostServicePrice) * 10),
                    amount      = (int)((customerOrder.FinalPrice.Value) * 10),
                    description = "order NO: " + customerOrder.OrderNo,
                    metadata    = new ZarinPalRequestMetaData
                    {
                        mobile = "0" + cc.Mobile.ToString(),
                        email  = cc.Email
                    }
                };
                var zarinPal = new ZarinPal();
                var res      = zarinPal.Request(request);

                var customerOrderPayment = new CustomerOrderPayment
                {
                    OrderNo          = customerOrder.OrderNo.ToString(),
                    TraceNo          = res.authority,
                    TransactionPrice = customerOrder.FinalPrice,
                    TransactionDate  = DateTime.Now.Ticks,
                    Cdate            = DateTime.Now.Ticks,
                    CuserId          = userId,
                    PaymentPrice     = customerOrder.FinalPrice,
                    FinalStatusId    = 26
                };
                customerOrder.CustomerOrderPayment.Add(customerOrderPayment);
                _repository.Save();

                var result = new InsertOrderResultDto
                {
                    OrderNo         = customerOrder.OrderNo,
                    CustomerOrderId = customerOrder.Id,
                    BankUrl         = "https://www.zarinpal.com/pg/StartPay/" + res.authority,
                    RedirectToBank  = true,
                    PostPrice       = customerOrder.PostServicePrice
                };
                var finalres = SingleResult <InsertOrderResultDto> .GetSuccessfulResult(result);

                _logger.LogData(MethodBase.GetCurrentMethod(), finalres, null, order);
                return(finalres);
            }
            catch (Exception e)
            {
                _logger.LogError(e, MethodBase.GetCurrentMethod(), order);
                return(SingleResult <InsertOrderResultDto> .GetFailResult(e.Message));
            }
        }
コード例 #7
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));
            }
        }