protected void Page_Load(object sender, EventArgs e)
    {
        var    collection = HttpUtility.ParseQueryString(this.ClientQueryString);
        String Status     = collection["Status"];


        if (Status != "OK")
        {
            Response.Write("<script>alert('Purchase unsuccessfully')</script>");
            return;
        }



        var    zarinpal   = ZarinPal.ZarinPal.Get();
        String Authority  = collection["Authority"];
        String MerchantID = "71c705f8-bd37-11e6-aa0c-000c295eb8fc";
        long   Amount     = 5000;


        var verificationRequest  = new ZarinPal.PaymentVerification(MerchantID, Amount, Authority);
        var verificationResponse = zarinpal.InvokePaymentVerification(verificationRequest);

        if (verificationResponse.Status == 100)
        {
            Response.Write(String.Format("<script>alert('Purchase successfully with ref transaction {0}')</script>", verificationResponse.RefID));
        }
        else
        {
            Response.Write(String.Format("<script>alert('Purchase unsuccessfully Error code is: {0}')</script>", verificationResponse.Status));
        }
    }
Exemplo n.º 2
0
        public VerificationResponse InvokePaymentVerificationWithExtra(PaymentVerification verificationRequest)
        {
            URLs url = new URLs(this.IsSandBox, true);

            _HttpCore.URL    = url.GetVerificationURL();
            _HttpCore.Method = Method.POST;
            _HttpCore.Raw    = verificationRequest;


            String response = _HttpCore.Get();
            VerificationResponse verification = Newtonsoft.Json.JsonConvert.DeserializeObject <VerificationResponse>(response);

            return(verification);
        }
Exemplo n.º 3
0
        public VerificationResponse InvokePaymentVerification(PaymentVerification verificationRequest)
        {
            URLs url = new URLs(IsSandBox);

            _HttpCore.URL    = url.GetVerificationURL();
            _HttpCore.Method = Method.POST;
            _HttpCore.Raw    = verificationRequest;


            string response = _HttpCore.Get();
            VerificationResponse verification = JsonConvert.DeserializeObject <VerificationResponse>(response);

            return(verification);
        }
Exemplo n.º 4
0
        public VerificationResponse InvokePaymentVerification(PaymentVerification verificationRequest)
        {
            URLs url = new URLs(this.IsSandBox);

            _HttpCore.URL    = url.GetVerificationURL();
            _HttpCore.Method = Method.POST;
            _HttpCore.Raw    = verificationRequest;


            String response                   = _HttpCore.Get();
            JavaScriptSerializer j            = new JavaScriptSerializer();
            VerificationResponse verification = j.Deserialize <VerificationResponse>(response);

            return(verification);
        }
Exemplo n.º 5
0
        public ActionResult PaymentVerification(int billID = 0)
        {
            NameValueCollection nvc = Request.Params;
            String Status           = nvc["Status"];

            var bill     = db.Tbl_Bill.Find(billID);
            var user     = db.Tbl_User.Where(a => a.User_ID == bill.Bill_UserID).SingleOrDefault();
            var username = user.User_Username;

            Session["UserName"] = username;

            if (Status != "OK")
            {
                Response.Write("<script>alert('Purchase unsuccessfully')</script>");
                TempData["PayError"] = "متاسفانه پرداخت با موفقیت انجام نشد، لطفا دوباره تلاش کنید.";
                return(RedirectToAction("Index", "Cart"));
            }


            int Amount   = bill.Bill_PayPrice;
            var zarinpal = ZarinPal.ZarinPal.Get();

            zarinpal.DisableSandboxMode();
            //zarinpal.EnableSandboxMode();
            String Authority  = nvc["Authority"];
            String MerchantID = "91afdd4e-006f-11ea-bad7-000c295eb8fc";

            var verificationRequest  = new ZarinPal.PaymentVerification(MerchantID, Amount, Authority);
            var verificationResponse = zarinpal.InvokePaymentVerification(verificationRequest);

            if (verificationResponse.Status == 100)
            {
                //clear carts
                var carts = db.Tbl_UserBills.Where(a => a.UserBills_Bill_ID == bill.Bill_ID).ToList();
                List <Tbl_InterimBill> ib_list = new List <Tbl_InterimBill>();
                foreach (var cart in carts)
                {
                    Tbl_InterimBill ib = new Tbl_InterimBill();
                    ib = db.Tbl_InterimBill.Where(a => a.InterimBill_ID == cart.UserBills_InterimBill_ID).SingleOrDefault();
                    ib.InterimBill_Status = true;
                    db.SaveChanges();
                }
                // db.Tbl_InterimBill.RemoveRange(ib_list);
                //db.SaveChanges();

                //update bill table
                bill.Bill_Status = true;
                //bill.Bill_RefID = RefID;
                db.SaveChanges();

                ViewBag.NameFamily = user.User_NameFamily;
                ViewBag.InvoiceNum = bill.Bill_InvoiceNumber;

                return(View());
            }
            else
            {
                TempData["PayError"] = "تراکنش با موفقیت انجام نشد، لطفا دوباره تلاش کنید.";
                return(RedirectToAction("Index", "Cart"));
            }
        }