Files
DotNetCore.SKIT.FlurlHttpCl…/src/SKIT.FlurlHttpClient.Wechat.TenpayV3/Extensions/WechatTenpayClientExecuteRefundExtensions.cs

83 lines
5.2 KiB
C#
Raw Normal View History

2021-05-10 15:30:00 +08:00
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Flurl;
using Flurl.Http;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
{
/// <summary>
/// 为 <see cref="WechatTenpayClient"/> 提供退款相关的 API 扩展方法。
/// </summary>
public static class WechatTenpayClientExecuteRefundExtensions
{
/// <summary>
/// <para>异步调用 [POST] /refund/domestic/refunds 接口。</para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_9.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_9.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_9.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_9.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_14.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter6_1_26.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter3_1_9.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter3_2_9.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter3_3_9.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter3_4_9.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter3_5_9.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter5_1_14.shtml </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CreateRefundDomesticRefundResponse> ExecuteCreateRefundDomesticRefundAsync(this WechatTenpayClient client, Models.CreateRefundDomesticRefundRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
IFlurlRequest flurlReq = client
2021-07-11 00:55:41 +08:00
.CreateRequest(request, HttpMethod.Post, "refund", "domestic", "refunds");
2021-05-10 15:30:00 +08:00
return await client.SendRequestWithJsonAsync<Models.CreateRefundDomesticRefundResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [GET] /refund/domestic/refunds/{out_refund_no} 接口。</para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_10.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_10.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_10.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_10.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_10.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_15.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter6_1_27.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter3_1_10.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter3_2_10.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter3_3_10.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter3_4_10.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter3_5_10.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter5_1_15.shtml </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.GetRefundDomesticRefundByOutRefundNumberResponse> ExecuteGetRefundDomesticRefundByOutRefundNumberAsync(this WechatTenpayClient client, Models.GetRefundDomesticRefundByOutRefundNumberRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
IFlurlRequest flurlReq = client
2021-07-11 00:55:41 +08:00
.CreateRequest(request, HttpMethod.Get, "refund", "domestic", "refunds", request.OutRefundNumber);
2021-05-10 15:30:00 +08:00
if (!string.IsNullOrEmpty(request.SubMerchantId))
flurlReq.SetQueryParam("sub_mchid", request.SubMerchantId);
2021-07-11 00:55:41 +08:00
return await client.SendRequestWithJsonAsync<Models.GetRefundDomesticRefundByOutRefundNumberResponse>(flurlReq, cancellationToken: cancellationToken);
2021-05-10 15:30:00 +08:00
}
}
}