Files
DotNetCore.SKIT.FlurlHttpCl…/src/SKIT.FlurlHttpClient.Wechat.TenpayV3/Extensions/WechatTenpayClientExecuteRefundExtensions.cs
Fu Diwei b953a43bd7 refactor
2024-08-08 14:26:14 +08:00

113 lines
7.9 KiB
C#

using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Flurl;
using Flurl.Http;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
{
public static class WechatTenpayClientExecuteRefundExtensions
{
/// <summary>
/// <para>异步调用 [POST] /refund/domestic/refunds 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/jsapi-payment/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/in-app-payment/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/h5-payment/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/native-payment/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/mini-program-payment/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/combine-payment/refunds/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/refund/refunds/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/weixin-pay-score/refunds/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/wexin-pay-score-parking/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/wexin-pay-score-parking/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/partner-jsapi-payment/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/partner-in-app-payment/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/partner-h5-payment/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/partner-native-payment/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/partner-mini-program-payment/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/combine-payment/refunds/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/refund/refunds/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/wexin-pay-score-parking/create.html ]]>
/// </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
.CreateFlurlRequest(request, HttpMethod.Post, "refund", "domestic", "refunds");
return await client.SendFlurlRequestAsJsonAsync<Models.CreateRefundDomesticRefundResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// <para>异步调用 [GET] /refund/domestic/refunds/{out_refund_no} 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/jsapi-payment/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/in-app-payment/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/h5-payment/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/native-payment/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/mini-program-payment/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/combine-payment/refunds/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/refund/refunds/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/weixin-pay-score/refunds/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/partner-jsapi-payment/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/partner-in-app-payment/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/partner-h5-payment/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/partner-native-payment/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/partner-mini-program-payment/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/refund/refunds/create.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/refund/refunds/query-by-out-refund-no.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/wexin-pay-score-parking/query-by-out-refund-no.html ]]>
/// </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
.CreateFlurlRequest(request, HttpMethod.Get, "refund", "domestic", "refunds", request.OutRefundNumber)
.SetQueryParam("sub_mchid", request.SubMerchantId);
return await client.SendFlurlRequestAsJsonAsync<Models.GetRefundDomesticRefundByOutRefundNumberResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// <para>异步调用 [POST] /refund/domestic/refunds/{refund_id}/apply-abnormal-refund 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/refund/refunds/create-abnormal-refund.html ]]> <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/refund/refunds/create-abnormal-refund.html ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CreateRefundDomesticAbnormalRefundApplyResponse> ExecuteCreateRefundDomesticAbnormalRefundApplyAsync(this WechatTenpayClient client, Models.CreateRefundDomesticAbnormalRefundApplyRequest 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
.CreateFlurlRequest(request, HttpMethod.Post, "refund", "domestic", "refunds", request.RefundId, "apply-abnormal-refund");
return await client.SendFlurlRequestAsJsonAsync<Models.CreateRefundDomesticAbnormalRefundApplyResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}