public ActionResult Verify(int id)
 {
     if (!string.IsNullOrEmpty(Request.QueryString["Status"]) && !string.IsNullOrEmpty(Request.QueryString["Authority"]))
     {
         if (Request.QueryString["Status"].Equals("OK"))
         {
             int  amount = 1000;
             long refId;
             ServicePointManager.Expect100Continue = false;
             Zarinpal.PaymentGatewayImplementationServicePortTypeClient client = new Zarinpal.PaymentGatewayImplementationServicePortTypeClient();
             int status = client.PaymentVerification("MerchantID", Request.QueryString["Authority"], amount, out refId);
             if (status == 100 || status == 101)
             {
                 ViewBag.RefId = "کد پیگیری: " + refId + " - کد سفارش: " + id;
             }
             else
             {
                 ViewBag.Message = GetMessage(status);
             }
         }
         else
         {
             ViewBag.Message = "کد مرجع: " + Request.QueryString["Authority"] + " - وضعیت:" + Request.QueryString["Status"];
         }
     }
     else
     {
         ViewBag.Message = "ورودی نامعتبر است.";
     }
     return(View());
 }
示例#2
0
        public ActionResult Payment(Guid NidOrder, decimal TotalPrice)
        {
            dataTransfer = new DataTransfer();
            var tmporder = dataTransfer.GetOrderByNidOrder(NidOrder);

            if (tmporder != null)
            {
                System.Net.ServicePointManager.Expect100Continue = false;
                Zarinpal.PaymentGatewayImplementationServicePortTypeClient zp = new Zarinpal.PaymentGatewayImplementationServicePortTypeClient();
                //ZarinpalTest.PaymentGatewayImplementationServicePortTypeClient zp = new ZarinpalTest.PaymentGatewayImplementationServicePortTypeClient();//debug
                string Authority;
                int    ProcessedPrice = decimal.ToInt32(tmporder.TotalPrice / 10);
                int    Status         = zp.PaymentRequest(Merchant, ProcessedPrice, "خرید از سایت کاربیس", tmporder.Email, tmporder.Tel, "https://carbass.ir/Verify?NidOrder=" + NidOrder, out Authority);
                //int Status = zp.PaymentRequest(Merchant, ProcessedPrice, "خرید از سایت کاربیس",tmporder.Email, tmporder.Tel, "http://localhost:2000/Verify?NidOrder=" + NidOrder, out Authority);//debug

                if (Status == 100)
                {
                    return(Redirect("https://www.zarinpal.com/pg/StartPay/" + Authority));
                    //return Redirect("https://sandbox.zarinpal.com/pg/StartPay/" + Authority);//debug
                }
                else
                {
                    TempData["dargahRedirectError"] = "در انتقال به درگاه خطایی رخ داده است.لطفا مجدد امتحان کنید";
                    return(RedirectToAction("CheckoutDetail", "Home"));
                }
            }
            else
            {
                TempData["dargahRedirectError"] = "خطایی در سرور رخ داده است.لطفا مجدد امتحان نمایید";
                return(RedirectToAction("CheckoutDetail", "Home"));
            }
        }
        public ActionResult Payment(PaymentModel model)
        {
            if (!ModelState.IsValid)
            {
                string message = string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, message));
            }
            ServicePointManager.Expect100Continue = false;
            Zarinpal.PaymentGatewayImplementationServicePortTypeClient client = new Zarinpal.PaymentGatewayImplementationServicePortTypeClient();
            string authority;
            int    amount      = model.Amount;
            string description = model.Description;
            string email       = model.Email;
            string mobile      = model.Mobile;
            int    orderId     = model.OrderId;
            string callbackUrl = "http://" + Request.Url.Authority + "/Home/Verify/" + orderId;

            int status = client.PaymentRequest("MerchantID", amount, description, email, mobile, 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["Message"] = GetMessage(status);
            return(View("Index"));
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["Status"] != "" && Request.QueryString["Status"] != null && Request.QueryString["Authority"] != "" && Request.QueryString["Authority"] != null)
        {
            if (Request.QueryString["Status"].ToString().Equals("OK"))
            {
                int  Amount = 100;
                long RefID;
                System.Net.ServicePointManager.Expect100Continue = false;
                Zarinpal.PaymentGatewayImplementationServicePortTypeClient zp = new Zarinpal.PaymentGatewayImplementationServicePortTypeClient();

                int Status = zp.PaymentVerification("YOUR-ZARINPAL-MERCHANT-CODE", Request.QueryString["Authority"].ToString(), Amount, out RefID);

                if (Status == 100)
                {
                    Response.Write("Success!! RefId: " + RefID);
                }
                else
                {
                    Response.Write("Error!! Status: " + Status);
                }
            }
            else
            {
                Response.Write("Error! Authority: " + Request.QueryString["Authority"].ToString() + " Status: " + Request.QueryString["Status"].ToString());
            }
        }
        else
        {
            Response.Write("Invalid Input");
        }
    }
        public async Task <IHttpActionResult> NewFakeDepositInvoice(NewDepositInvoiceBM model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Zarinpal.PaymentGatewayImplementationServicePortTypeClient zp =
                new Zarinpal.PaymentGatewayImplementationServicePortTypeClient();

            var invoice = new DepositInvoice
            {
                Amount             = model.Amount,
                PaymentGateway     = PaymentGateway.Fake,
                ReceiverCampaignId = model.ReceiverCampaignId,
                AccountName        = model.Email,
                ExtraInfoJSON      = new ExtraInfoJSON {
                    InfoJSON = model.ExtraInfoJSON
                }
            };

            db.DepositInvoices.Add(invoice);
            await db.SaveChangesAsync();

            return(Ok());
        }
示例#6
0
        public ActionResult Verify(Guid NidOrder)
        {
            dataTransfer = new DataTransfer();
            Order       tmpOrder = dataTransfer.GetOrderByNidOrder(NidOrder);
            List <Cart> carts    = dataTransfer.GetAllCartsByNidOrder(NidOrder);

            if (Request.QueryString["Status"] != "" && Request.QueryString["Status"] != null && Request.QueryString["Authority"] != "" && Request.QueryString["Authority"] != null)
            {
                if (Request.QueryString["Status"].ToString().Equals("OK"))
                {
                    int  Amount = decimal.ToInt32(tmpOrder.TotalPrice / 10);
                    long RefID;
                    System.Net.ServicePointManager.Expect100Continue = false;
                    Zarinpal.PaymentGatewayImplementationServicePortTypeClient zp = new Zarinpal.PaymentGatewayImplementationServicePortTypeClient();
                    //ZarinpalTest.PaymentGatewayImplementationServicePortTypeClient zp = new ZarinpalTest.PaymentGatewayImplementationServicePortTypeClient();//debug

                    int Status = zp.PaymentVerification(Merchant, Request.QueryString["Authority"].ToString(), Amount, out RefID);
                    tmpOrder.state = Status;
                    tmpOrder.RefId = RefID;
                    if (dataTransfer.UpdateOrder(tmpOrder))
                    {
                        foreach (var cart in carts)
                        {
                            cart.State = 1;
                            if (dataTransfer.UpdateCart(cart))
                            {
                                var cartandfav = dataTransfer.GetCartAndFavoriteCount(tmpOrder.NidUser);
                                if (Request.Cookies.AllKeys.Contains("AudioShopCart"))
                                {
                                    Response.Cookies["AudioShopCart"].Value = cartandfav.Item1.ToString();
                                }
                                if (Request.Cookies.AllKeys.Contains("AudioShopFavorites"))
                                {
                                    Response.Cookies["AudioShopFavorites"].Value = cartandfav.Item2.ToString();
                                }
                            }
                        }
                    }
                }
                else
                {
                    tmpOrder.state = -100;
                    dataTransfer.UpdateOrder(tmpOrder);
                }
            }
            else
            {
                tmpOrder.state = -101;
                dataTransfer.UpdateOrder(tmpOrder);
            }
            return(View(new CheckoutViewModel()
            {
                Carts = carts, Order = tmpOrder
            }));
        }
    protected void btnRequest_Click(object sender, EventArgs e)
    {
        System.Net.ServicePointManager.Expect100Continue = false;
        Zarinpal.PaymentGatewayImplementationServicePortTypeClient zp = new Zarinpal.PaymentGatewayImplementationServicePortTypeClient();
        string Authority;

        int Status = zp.PaymentRequest("YOUR-ZARINPAL-MERCHANT-CODE", int.Parse(txtAmount.Text), txtDescription.Text.ToString(), "*****@*****.**", "09123456789", "http://localhost/Verify.aspx", out Authority);

        if (Status == 100)
        {
            Response.Redirect("https://www.zarinpal.com/pg/StartPay/" + Authority);
        }
        else
        {
            Response.Write("error: " + Status);
        }
    }
        public async Task <IHttpActionResult> NewZarinpalDepositInvoice(NewDepositInvoiceBM model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Zarinpal.PaymentGatewayImplementationServicePortTypeClient zp =
                new Zarinpal.PaymentGatewayImplementationServicePortTypeClient();

            var invoice = new DepositInvoice
            {
                Amount             = model.Amount,
                PaymentGateway     = PaymentGateway.ZarinPal,
                ReceiverCampaignId = model.ReceiverCampaignId,
                AccountName        = model.Email,
                ExtraInfoJSON      = new ExtraInfoJSON {
                    InfoJSON = model.ExtraInfoJSON
                }
            };

            db.DepositInvoices.Add(invoice);
            await db.SaveChangesAsync();

            //NOTE: We do not provide Zarinpal with our customers' email or mobile number
            //NOTE that we used Async version and changed the original source code, we should check whether this works
            var resp = await zp.PaymentRequestAsync("YOUR-ZARINPAL-MERCHANT-CODE", model.Amount, model.Description,
                                                    "", "", Url.Link("VerifyZarinpal", new { id = invoice.Id })
                                                    );

            var status    = resp.Body.Status;
            var Authority = resp.Body.Authority;

            if (status == 100)
            {
                return(Created("DefaultApi", new { Authority = Authority }));
            }
            else
            {
                return(InternalServerError(new Exception("Zarinpal gateway error, status:" + status.ToString())));
            }
        }
        public async Task <IHttpActionResult> ZarinpalPaid(long id, string Authority, string Status)
        {
            if (string.IsNullOrEmpty(Authority) || string.IsNullOrEmpty(Status))
            {
                return(BadRequest());
            }

            if (Status != "OK")
            {
                return(InternalServerError(new Exception("Zarinpal gateway error, Authority:" + Authority + ", Status:" + Status)));
            }

            var invoice = await db.DepositInvoices.FindAsync(id);

            if (invoice == null)
            {
                return(NotFound());
            }
            System.Net.ServicePointManager.Expect100Continue = false;
            Zarinpal.PaymentGatewayImplementationServicePortTypeClient zp = new Zarinpal.PaymentGatewayImplementationServicePortTypeClient();

            long RefID;
            int  verStatus = zp.PaymentVerification("YOUR-ZARINPAL-MERCHANT-CODE", Authority, invoice.Amount, out RefID);

            if (verStatus == 100)
            {
                invoice.ReferenceNumber = RefID.ToString();
                //1) Create an account for the payer according to AccountName
                //2) Create two journal entries to debit the campaign and credit the user
                //3) Create the related transaction
            }
            else
            {
                return(InternalServerError(new Exception("Zarinpal gateway error, status:" + verStatus.ToString())));
            }
            db.Entry(invoice).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));
        }