Beispiel #1
0
        /// <summary>
        /// 轮询查询用户是否支付
        /// </summary>
        /// <param name="outTradeNo">订单号</param>
        /// <param name="pollTime">轮询间隔</param>
        /// <param name="pollCount">轮询次数</param>
        /// <returns></returns>
        private QueryResponse PollQueryTradeState(string outTradeNo, int pollTime, int pollCount)
        {
            for (int i = 0; i < pollCount; i++)
            {
                var queryRequest = new QueryRequest();
                queryRequest.AddGatewayData(new QueryModel
                {
                    OutTradeNo = outTradeNo
                });
                var queryResponse = SubmitProcess.Execute(_merchant, queryRequest);
                if (queryResponse.TradeState == "SUCCESS")
                {
                    return(queryResponse);
                }

                Thread.Sleep(pollTime);
            }

            //支付超时,取消订单
            var cancelRequest = new CancelRequest();

            cancelRequest.AddGatewayData(new CancelModel
            {
                OutTradeNo = outTradeNo
            });
            SubmitProcess.Execute(_merchant, cancelRequest);

            return(null);
        }
Beispiel #2
0
        public void TestQuery()
        {
            var request = new QueryRequest();

            request.AddGatewayData(new QueryModel()
            {
                OutTradeNo = "20191228080146"
            });

            var response = _allinpayGateway.Execute(request);

            Assert.Equal("SUCCESS", response.ReturnCode);
        }
Beispiel #3
0
        public void TestQuery()
        {
            var request = new QueryRequest();

            request.AddGatewayData(new QueryModel()
            {
                OutTradeNo = _outTradeNo
            });

            var response = _alipayGateway.Execute(request);

            Assert.Equal("40004", response.Code);
        }
Beispiel #4
0
        public ActionResult Query(string out_trade_no, string trade_no)
        {
            var request = new QueryRequest();

            request.AddGatewayData(new QueryModel()
            {
                TradeNo    = trade_no,
                OutTradeNo = out_trade_no
            });

            var response = _gateway.Execute(request);

            return(Json(response));
        }
Beispiel #5
0
        public IActionResult Query(string order_id, string query_id)
        {
            var request = new QueryRequest();

            request.AddGatewayData(new QueryModel()
            {
                OrderId = order_id,
                QueryId = query_id
            });

            var response = _gateway.Execute(request);

            return(Json(response));
        }
Beispiel #6
0
        public QueryResponse Query(PayRequest payRequest)
        {
            var queryModel = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(payRequest.BizContent,
                                                                                  new { out_trade_no = "", trade_no = "" });
            var request = new QueryRequest();

            request.AddGatewayData(new QueryModel()
            {
                TradeNo    = queryModel.trade_no,
                OutTradeNo = queryModel.out_trade_no
            });

            var response = _gateway.Execute(request);

            return(response);
        }
Beispiel #7
0
        /// <summary>
        /// 轮询查询用户是否支付
        /// </summary>
        /// <param name="outTradeNo">订单号</param>
        /// <param name="pollTime">轮询间隔</param>
        /// <param name="pollCount">轮询次数</param>
        /// <returns></returns>
        private QueryResponse PollQueryTradeState(string outTradeNo, int pollTime, int pollCount)
        {
            for (var i = 0; i < pollCount; i++)
            {
                var queryRequest = new QueryRequest();
                queryRequest.AddGatewayData(new QueryModel
                {
                    OutTradeNo = outTradeNo
                });
                var queryResponse = SubmitProcess.Execute(_merchant, queryRequest);
                if (queryResponse.TradeStatus == "0000")
                {
                    return(queryResponse);
                }

                Thread.Sleep(pollTime);
            }

            return(null);
        }
Beispiel #8
0
        public async Task SyncOrderStatus(string orderId)
        {
            var orderDTO = await _orderServiceProxy.GetById(orderId);

            if (orderDTO == null)
            {
                return;
            }

            BaseGateway gateway = null;

            if (string.IsNullOrEmpty(orderDTO.OrganizationId))
            {
                gateway = _gateways.Get <WechatpayGateway>();
            }
            else
            {
                WeChatAppConfiguration appConfig = _wechatAppConfigurationRepository.GetFiltered(o => o.OrganizationId == orderDTO.OrganizationId).FirstOrDefault();
                if (appConfig != null)
                {
                    var wechatpayMerchant = new PaySharp.Wechatpay.Merchant
                    {
                        AppId           = appConfig.AppId,
                        MchId           = appConfig.MchId,
                        Key             = appConfig.Key,
                        AppSecret       = appConfig.AppSecret,
                        SslCertPath     = appConfig.SslCertPath,
                        SslCertPassword = appConfig.SslCertPassword,
                        NotifyUrl       = appConfig.NotifyUrl
                    };

                    gateway = new WechatpayGateway(wechatpayMerchant);
                }
                else
                {
                    gateway = _gateways.Get <WechatpayGateway>();
                }
            }


            var request = new QueryRequest();

            request.AddGatewayData(new QueryModel()
            {
                OutTradeNo = orderDTO.OrderNo
            });

            var response = gateway.Execute(request);

            if (response.ReturnCode == "SUCCESS")
            {
                if (response.ResultCode == "SUCCESS")
                {
                    if (response.TradeState == TradeState.SUCCESS.ToString())
                    {
                        await _orderServiceProxy.SetOrderPaidSuccessed(orderId);
                    }
                    if (response.TradeState == TradeState.REVOKED.ToString() ||
                        response.TradeState == TradeState.CLOSED.ToString())
                    {
                        await _orderServiceProxy.SetOrderPaidFailed(orderId);
                    }
                }
            }
        }