Exemplo n.º 1
0
        /// <summary>
        /// Updates order state if online pay complete
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        private bool UpdateOrder(PayResult result, out string returnUrl)
        {
            bool success = false;
            returnUrl = string.Empty;

            if (result != null)
            {
                TradeOrder order = orderService.GetOrderByOrderId(result.OrderId);
                if (order != null && result.Amount == order.Amount)
                {
                    int newState = -1;

                    switch (result.TradeStatus)
                    {
                        case PayStatus.Failed:
                            newState = (int)OrderState.Failed;
                            break;
                        case PayStatus.Invalid:
                            newState = (int)OrderState.Invalid;
                            break;
                        case PayStatus.Success:
                            newState = (int)OrderState.Succeed;
                            break;
                        case PayStatus.UnKnow:
                        default:
                            newState = (int)OrderState.Invalid;
                            break;
                    }

                    success = true;
                    if (order.State != newState)
                    {
                        success = orderService.UpdateOrderState(order.OrderId, newState);
                    }

                    if (success)
                    {
                        returnUrl = order.ResourceUrl;
                    }
                }
            }

            return success;
        }
Exemplo n.º 2
0
        /// <summary>
        /// <see cref="IPayService.ParseResult"/>
        /// </summary>
        /// <param name="requestParamamters"></param>
        /// <returns></returns>
        public PayResult ParseResult(NameValueCollection requestParamamters)
        {
            PayResult result = null;

            if (requestParamamters != null && requestParamamters.Count > 0)
            {
                result = new PayResult();
                result.OrderId = requestParamamters["out_trade_no"];

                decimal amount = 0;
                decimal.TryParse(requestParamamters["total_fee"], out amount);
                result.Amount = amount;

                string status = requestParamamters["trade_status"];
                if (status.Equals("TRADE_SUCCESS") || status.Equals("TRADE_FINISHED"))
                {
                    result.TradeStatus = PayStatus.Success;
                }
                else if (status.Equals("WAIT_BUYER_PAY") || status.Equals("TRADE_CLOSED") || status.Equals("TRADE_PENDING"))
                {
                    result.TradeStatus = PayStatus.Failed;
                }
                else
                {
                    result.TradeStatus = PayStatus.UnKnow;
                }

                result.OrderSubject = requestParamamters["subject"];
                result.OrderBody = requestParamamters["body"];
            }

            return result;
        }
Exemplo n.º 3
0
        /// <summary>
        /// <see cref="IPayService.ParseResult"/>
        /// </summary>
        /// <param name="requestParamamters"></param>
        /// <returns></returns>
        public PayResult ParseResult(NameValueCollection requestParamamters)
        {
            PayResult result = null;

            if (requestParamamters != null && requestParamamters.Count > 0)
            {
                result = new PayResult();
                result.OrderId = requestParamamters["v_oid"];

                decimal amount = 0;
                decimal.TryParse(requestParamamters["v_amount"], out amount);
                result.Amount = amount;

                string status = requestParamamters["v_pstatus"];

                if (status.Equals("20"))
                {
                    result.TradeStatus = PayStatus.Success;
                }
                else if (status.Equals("30"))
                {
                    result.TradeStatus = PayStatus.Failed;
                }
                else
                {
                    result.TradeStatus = PayStatus.UnKnow;
                }

                //("remark1", "[subject=" + subject + "][body=" + body + "]")
                string remark1 = requestParamamters["remark1"];
                string[] temps;

                if (remark1 != string.Empty)
                {
                    temps = remark1.Split(new string[] { "][" }, StringSplitOptions.None);
                    if (temps != null && temps.Length > 0)
                    {
                        foreach (var item in temps)
                        {
                            if (!string.IsNullOrEmpty(item))
                            {
                                if (item.IndexOf("[subject=") > -1)
                                {
                                    result.OrderSubject = item.Replace("[subject=", string.Empty);
                                }
                                else if (item.IndexOf("body=") > -1)
                                {
                                    result.OrderBody = item.Replace("body=", string.Empty);
                                    result.OrderBody = result.OrderBody.Remove(result.OrderBody.Length - 1);
                                }
                                else
                                {
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }
Exemplo n.º 4
0
        public PayResult ParseResult(System.Collections.Specialized.NameValueCollection requestParamamters)
        {
            PayResult result = null;

            if (requestParamamters != null && requestParamamters.Count > 0)
            {
                result = new PayResult();

                //取结果参数做业务处理
                string out_trade_no = requestParamamters["out_trade_no"];

                //金额,以分为单位
                string total_fee = requestParamamters["total_fee"];
                //支付结果
                string trade_state = requestParamamters["trade_state"];

                result.OrderId = out_trade_no;
                result.Amount = ParseAmountFromFenToYuan(total_fee);

                if ("0".Equals(trade_state))
                {
                    result.TradeStatus = PayStatus.Success;
                }
                else
                {
                    result.TradeStatus = PayStatus.Failed;
                }
                result.OrderSubject = string.Empty;
                result.OrderBody = string.Empty;
                ////("attach", "[subject=" + subject + "][body=" + body + "]")
                //string attach = requestParamamters["attach"];
                //string[] temps;

                //if (attach != string.Empty)
                //{
                //    temps = attach.Split(new string[] { "][" }, StringSplitOptions.None);
                //    if (temps != null && temps.Length > 0)
                //    {
                //        foreach (var item in temps)
                //        {
                //            if (!string.IsNullOrEmpty(item))
                //            {
                //                if (item.IndexOf("[subject=") > -1)
                //                {
                //                    result.OrderSubject = item.Replace("[subject=", string.Empty);
                //                }
                //                else if (item.IndexOf("body=") > -1)
                //                {
                //                    result.OrderBody = item.Replace("body=", string.Empty);
                //                    result.OrderBody = result.OrderBody.Remove(result.OrderBody.Length - 1);
                //                }
                //                else
                //                {
                //                }
                //            }
                //        }
                //    }
                //}
            }

            return result;
        }