Esempio n. 1
0
 private bool VerifyOrder(AlipayData alipayData, UserPayOrderInfo payOrder)
 {
     if (Convert.ToDecimal(alipayData.GetValue("invoice_amount")) != payOrder.Cost)
     {
         LogHelper.Logger.Error("用户支付的金额与订单预付款金额不一致,交易失败");
         return(false);
     }
     if (!AliPayConfig.PID.Equals(alipayData.GetValue("seller_id")))
     {
         LogHelper.Logger.Error("seller_id不一致,交易失败");
         return(false);
     }
     if (!AliPayConfig.APPID.Equals(alipayData.GetValue("app_id")))
     {
         LogHelper.Logger.Error("app_id不一致,交易失败");
         return(false);
     }
     return(true);
 }
Esempio n. 2
0
        public bool AlipayCallBack(AlipayData alipayData)
        {
            var userPayInfo = _uerPayOrderInfoRepository.Get(alipayData.GetValue("out_trade_no"));

            if (userPayInfo == null)
            {
                LogHelper.Logger.Error(string.Format("数据库中不存在单号为{0}的订单", alipayData.GetValue("out_trade_no")));
                return(false);
            }
            if (!VerifyOrder(alipayData, userPayInfo))
            {
                return(false);
            }
            var tradeStatus   = alipayData.GetValue("trade_status");
            var transactionId = string.Empty;

            if (alipayData.IsSet("trade_no"))
            {
                transactionId = alipayData.GetValue("trade_no");
            }
            if (tradeStatus.Equals("TRADE_SUCCESS") || tradeStatus.Equals("TRADE_FINISHED"))
            {
                //支付金额
                return(_purchaseServiceRepository.CompleteServiceOrder(new CompleteServiceOrder()
                {
                    OrderID = alipayData.GetValue("out_trade_no"),
                    Cost = Convert.ToDouble(alipayData.GetValue("invoice_amount")),
                    NewID = OrderHelper.GenerateNewId(),
                    PayExtendInfo = alipayData.ToJson(),
                    PayState = tradeStatus,
                    PayOrderID = transactionId,
                    Remarks = "支付宝手机网页支付",
                }) == 0);
            }
            //超时关闭
            else if (tradeStatus.Equals("TRADE_CLOSED"))
            {
                LogHelper.Logger.Debug("订单超时关闭");
                return(_purchaseServiceRepository.UpdateServiceOrder(new UpdateServiceOrder()
                {
                    ID = alipayData.GetValue("out_trade_no"),
                    PayExtendInfo = alipayData.ToJson(),
                    PayState = tradeStatus,
                    PayOrderID = transactionId,
                    State = 3,
                }) == 0);
            }
            else
            {
                return(false);
            }
        }