Exemple #1
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler" /> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext" /> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        public override void ProcessRequest(HttpContext context)
        {
            string transactionRequest = null;

            try
            {
                string jsonParameter = GetJsonParameter(context.Request);

                ITradingOrder requestObject = (ITradingOrder)JsonConvert.DeserializeObject(jsonParameter, typeof(ITradingOrder));

                PaymentClient client = new PaymentClient(this.TransactionInfo);

                var service = new PaymentService();

                if (requestObject != null)
                {
                    transactionRequest = client.CreateTransactionRequest(requestObject);
                }
            }
            catch (Exception ex)
            {
                transactionRequest = ex.Message.ToString();
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write(transactionRequest);
        }
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler" /> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext" /> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        public override void ProcessRequest(HttpContext context)
        {
            TradingOrderStatus orderStatus = TradingOrderStatus.Pending;
            string returnResult = null;
            string orderKey = null;

            try
            {
                var requestUrl = context.Request.Url;
                var parameters = WebUtil.Instance.ConvertKeyValuePairCollectionFromString(requestUrl.Query.Trim('?'));

                if (parameters != null && parameters.Count > 0)
                {
                    if (this.IsNotificationAuthenticated(parameters))
                    {
                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.LoadXml(parameters["notify_data"]);

                        orderKey = xmlDoc.SelectSingleNode("/notify/out_trade_no").InnerText;
                        string tradeNumber = xmlDoc.SelectSingleNode("/notify/trade_no").InnerText;

                        string tradeStatus = xmlDoc.SelectSingleNode("/notify/trade_status").InnerText;
                        returnResult = tradeStatus;

                        if (tradeStatus == "TRADE_FINISHED" || tradeStatus == "TRADE_SUCCESS")
                        {
                            returnResult = "success";
                            orderStatus = TradingOrderStatus.Succeed;
                        }
                    }
                    else
                    {
                        returnResult = "fail";
                        orderStatus = TradingOrderStatus.Failed;
                    }
                }
                else
                {
                    returnResult = "无通知参数";
                }
            }

            catch (Exception ex)
            {
                returnResult = ex.ToString();
            }

            /*
             * update order status in DB
             */
            try
            {
                var service = new PaymentService();
                service.UpdateTradingOrderState(Guid.Parse(orderKey), orderStatus);
            }
            catch (Exception dbException)
            {
                Framework.Instance.HandleExceptionToServiceException("UpdateTradingOrderState", dbException, orderKey);
            }
            context.Response.ContentType = "text/plain";
            context.Response.Write(returnResult);
        }