예제 #1
0
        public async Task Test()
        {
            //设置返回响应
            var response = @"<xml>
                                <return_code><![CDATA[SUCCESS]]></return_code>
                                <return_msg><![CDATA[OK]]></return_msg>
                                <appid><![CDATA[wx9b90e1788b39fec6]]></appid>
                                <mch_id><![CDATA[1985518532]]></mch_id>
                                <nonce_str><![CDATA[wrKodsjUFk34qYno]]></nonce_str>
                                <sign><![CDATA[5F721ADF22DD2C60B4E171228F8DA36E]]></sign>
                                <result_code><![CDATA[SUCCESS]]></result_code>
                                <prepay_id><![CDATA[wx141217433636466fe2c3b2a10139084028]]></prepay_id>
                                <trade_type><![CDATA[APP]]></trade_type>
                            </xml>";

            //操作
            var result = new WechatpayResult(new TestConfigProvider(), response);

            //验证
            Assert.Equal("SUCCESS", result.GetReturnCode());
            Assert.Equal("OK", result.GetReturnMessage());
            Assert.Equal("wx9b90e1788b39fec6", result.GetAppId());
            Assert.Equal("1985518532", result.GetMerchantId());
            Assert.Equal("wrKodsjUFk34qYno", result.GetNonce());
            Assert.Equal("5F721ADF22DD2C60B4E171228F8DA36E", result.GetSign());
            Assert.Equal("SUCCESS", result.GetResultCode());
            Assert.Equal("wx141217433636466fe2c3b2a10139084028", result.GetPrepayId());
            Assert.Equal("APP", result.GetTradeType());
            var isValid = (await result.ValidateAsync()).IsValid;

            Assert.True(isValid);
        }
 /// <summary>
 /// 验证
 /// </summary>
 public async Task <ValidationResultCollection> ValidateAsync()
 {
     Init();
     if (Money <= 0)
     {
         return(new ValidationResultCollection(PayResource.InvalidMoney));
     }
     return(await _result.ValidateAsync());
 }
예제 #3
0
        /// <summary>
        /// 请求失败
        /// </summary>
        private async Task <WechatpayDownloadBillResult> Fail(string response, WechatpayConfig config, WechatpayParameterBuilder builder)
        {
            var result = new WechatpayResult(ConfigProvider, response, config, builder);

            WriteLog(config, builder, result);
            var success = (await result.ValidateAsync()).IsValid;

            return(new WechatpayDownloadBillResult(success, result));
        }
예제 #4
0
        /// <summary>
        /// 创建支付结果
        /// </summary>
        /// <param name="result">支付结果</param>
        protected virtual async Task <PayResult> CreateResult(WechatpayResult result)
        {
            var success = (await result.ValidateAsync()).IsValid;

            return(new PayResult(success, result.GetPrepayId(), result.Raw)
            {
                Parameter = result.Builder.ToString(),
                Message = result.GetReturnMessage(),
                Result = success ? GetResult(result) : null
            });
        }
예제 #5
0
        /// <summary>
        /// 创建退款结果
        /// </summary>
        /// <param name="config">支付配置</param>
        /// <param name="builder">参数生成器</param>
        /// <param name="result">支付结果</param>
        protected virtual async Task <RefundResult> CreateResult(WechatpayConfig config, WechatpayRefundParameterBuilder builder, WechatpayResult result)
        {
            var success = (await result.ValidateAsync()).IsValid;

            return(new RefundResult(success, result.GetRefundId(), result.Raw)
            {
                Parameter = builder.ToString(),
                Message = result.GetReturnMessage(),
                Result = success ? GetResult(config, builder, result) : null
            });
        }
예제 #6
0
 /// <summary>
 /// 验证
 /// </summary>
 public async Task <ValidationResultCollection> ValidateAsync()
 {
     Init();
     return(await _result.ValidateAsync());
 }
예제 #7
0
        /// <summary>
        /// 创建关闭订单结果
        /// </summary>
        private async Task <WechatpayCloseOrderResult> CreateResult(WechatpayResult result)
        {
            var success = (await result.ValidateAsync()).IsValid;

            return(new WechatpayCloseOrderResult(success, result));
        }
예제 #8
0
 /// <summary>
 /// 验证返回结果
 /// </summary>
 /// <param name="config">支付配置</param>
 /// <param name="builder">参数生成器</param>
 /// <param name="result">支付结果</param>
 protected virtual async Task ValidateResult <TResponse>(WechatpayResult <TResponse> result) where TResponse : WechatpayResponse
 {
     var validationResult = await result.ValidateAsync();
 }