Пример #1
0
        public ActionResult PostToECPay([Bind(Include = "OrderId, EcpayOrderNumber,PurchaserName,City,District,Road,PurchaserEmail,PurchaserPhone,Discount,Payment,Remember")] OrderViewModel order)
        {
            if (ModelState.IsValid)
            {
                ECPayService ecpayService = new ECPayService();
                string       PostURL      = "https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/v5";
                var          ecpayNumber  = DateTime.Now.ToString("yyyyMMddHHmmss");

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append("<html><body>").AppendLine();
                sb.Append("<form name='ECPayAIO'  id='ECPayAIO' action='" + PostURL + "' method='POST'>").AppendLine();
                var cartItems      = shoppingCartService.GetCartItems(this.HttpContext);
                var createOrder    = orderservice.CreateOrder(this.HttpContext, order, ecpayNumber);
                var postCollection = ecpayService.GetPostCollection(cartItems, order, ecpayNumber);
                foreach (var aa in postCollection)
                {
                    sb.Append("<input type='hidden' name='" + aa.Key + "' value='" + aa.Value + "'>").AppendLine();
                }
                if (!createOrder.isSuccessful)
                {
                    var Error = createOrder.exception;
                    ViewBag.Error = Error.ToString();
                    return(View("Fail"));
                }
                sb.Append("</form>").AppendLine();
                sb.Append("<script> var theForm = document.forms['ECPayAIO'];  if (!theForm) { theForm = document.ECPayAIO; } theForm.submit(); </script>").AppendLine();
                sb.Append("<html><body>").AppendLine();
                TempData["PostForm"] = sb.ToString();
                return(View());
            }
            return(View());
        }
Пример #2
0
        /// <summary>
        /// 重新結帳到綠界
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public ActionResult PostToECPay(string orderId)
        {
            if (orderId != null)
            {
                ECPayService ecpayService = new ECPayService();
                string       PostURL      = "https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/v5";
                var          ecpayNumber  = DateTime.Now.ToString("yyyyMMddHHmmss");

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append("<html><body>").AppendLine();
                sb.Append("<form name='ECPayAIO'  id='ECPayAIO' action='" + PostURL + "' method='POST'>").AppendLine();
                // 重新結帳
                var order        = orderservice.GetOrder(this.HttpContext, orderId).FirstOrDefault();
                var orderDetails = orderservice.GetOrderDetails(orderId.ToString());
                if (orderDetails.FirstOrDefault().Coupon != null)
                {
                    var discount = orderDetails.FirstOrDefault().Coupon.CouponCode;
                    order.Discount = discount;
                }
                var postCollection = ecpayService.GetPostCollection(orderDetails, order, ecpayNumber);
                foreach (var aa in postCollection)
                {
                    sb.Append("<input type='hidden' name='" + aa.Key + "' value='" + aa.Value + "'>").AppendLine();
                }
                sb.Append("</form>").AppendLine();
                sb.Append("<script> var theForm = document.forms['ECPayAIO'];  if (!theForm) { theForm = document.ECPayAIO; } theForm.submit(); </script>").AppendLine();
                sb.Append("<html><body>").AppendLine();
                TempData["PostForm"] = sb.ToString();
                return(View());
            }
            return(View("Index", "Home"));
        }