|
| 1 | +using System; |
| 2 | +using System.Net.Http; |
| 3 | +using System.Threading; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using Flurl.Http; |
| 6 | + |
| 7 | +namespace SKIT.FlurlHttpClient.Wechat.TenpayV3 |
| 8 | +{ |
| 9 | + public static class WechatTenpayClientExecuteRepaymentPartnerExtensions |
| 10 | + { |
| 11 | + /// <summary> |
| 12 | + /// <para>异步调用 [POST] /repayment/combine-transactions/partner/prepay 接口。</para> |
| 13 | + /// <para> |
| 14 | + /// REF: <br/> |
| 15 | + /// <![CDATA[ https://pay.weixin.qq.com/doc/v3/partner/4015124463 ]]> |
| 16 | + /// </para> |
| 17 | + /// </summary> |
| 18 | + /// <param name="client"></param> |
| 19 | + /// <param name="request"></param> |
| 20 | + /// <param name="cancellationToken"></param> |
| 21 | + /// <returns></returns> |
| 22 | + public static async Task<Models.CreateRepaymentPartnerCombineTransactionResponse> ExecuteCreateRepaymentPartnerCombineTransactionAsync(this WechatTenpayClient client, Models.CreateRepaymentPartnerCombineTransactionRequest request, CancellationToken cancellationToken = default) |
| 23 | + { |
| 24 | + if (client is null) throw new ArgumentNullException(nameof(client)); |
| 25 | + if (request is null) throw new ArgumentNullException(nameof(request)); |
| 26 | + |
| 27 | + if (request.CombineMerchantId is null) |
| 28 | + request.CombineMerchantId = client.Credentials.MerchantId; |
| 29 | + |
| 30 | + if (request.SubOrderList is not null) |
| 31 | + { |
| 32 | + foreach (var subOrder in request.SubOrderList) |
| 33 | + { |
| 34 | + if (subOrder.MerchantId is null) |
| 35 | + subOrder.MerchantId = request.CombineMerchantId; |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + IFlurlRequest flurlReq = client |
| 40 | + .CreateFlurlRequest(request, HttpMethod.Post, "repayment", "combine-transactions", "partner", "prepay"); |
| 41 | + |
| 42 | + return await client.SendFlurlRequestAsJsonAsync<Models.CreateRepaymentPartnerCombineTransactionResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 43 | + } |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// <para>异步调用 [GET] /repayment/combine-transactions/partner/out-trade-no/{combine_out_trade_no} 接口。</para> |
| 47 | + /// <para> |
| 48 | + /// REF: <br/> |
| 49 | + /// <![CDATA[ https://pay.weixin.qq.com/doc/v3/partner/4015124483 ]]> |
| 50 | + /// </para> |
| 51 | + /// </summary> |
| 52 | + /// <param name="client"></param> |
| 53 | + /// <param name="request"></param> |
| 54 | + /// <param name="cancellationToken"></param> |
| 55 | + /// <returns></returns> |
| 56 | + public static async Task<Models.GetRepaymentPartnerCombineTransactionByOutTradeNumberResponse> ExecuteGetRepaymentPartnerCombineTransactionByOutTradeNumberAsync(this WechatTenpayClient client, Models.GetRepaymentPartnerCombineTransactionByOutTradeNumberRequest request, CancellationToken cancellationToken = default) |
| 57 | + { |
| 58 | + if (client is null) throw new ArgumentNullException(nameof(client)); |
| 59 | + if (request is null) throw new ArgumentNullException(nameof(request)); |
| 60 | + |
| 61 | + IFlurlRequest flurlReq = client |
| 62 | + .CreateFlurlRequest(request, HttpMethod.Get, "repayment", "combine-transactions", "partner", "out-trade-no", request.CombineOutTradeNumber); |
| 63 | + |
| 64 | + return await client.SendFlurlRequestAsJsonAsync<Models.GetRepaymentPartnerCombineTransactionByOutTradeNumberResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 65 | + } |
| 66 | + |
| 67 | + /// <summary> |
| 68 | + /// <para>异步调用 [POST] /repayment/combine-transactions/partner/out-trade-no/{combine_out_trade_no}/close 接口。</para> |
| 69 | + /// <para> |
| 70 | + /// REF: <br/> |
| 71 | + /// <![CDATA[ https://pay.weixin.qq.com/doc/v3/partner/4015124497 ]]> |
| 72 | + /// </para> |
| 73 | + /// </summary> |
| 74 | + /// <param name="client"></param> |
| 75 | + /// <param name="request"></param> |
| 76 | + /// <param name="cancellationToken"></param> |
| 77 | + /// <returns></returns> |
| 78 | + public static async Task<Models.CloseRepaymentPartnerCombineTransactionResponse> ExecuteCloseRepaymentPartnerCombineTransactionAsync(this WechatTenpayClient client, Models.CloseRepaymentPartnerCombineTransactionRequest request, CancellationToken cancellationToken = default) |
| 79 | + { |
| 80 | + if (client is null) throw new ArgumentNullException(nameof(client)); |
| 81 | + if (request is null) throw new ArgumentNullException(nameof(request)); |
| 82 | + |
| 83 | + IFlurlRequest flurlReq = client |
| 84 | + .CreateFlurlRequest(request, HttpMethod.Post, "repayment", "combine-transactions", "partner", "out-trade-no", request.CombineOutTradeNumber, "close"); |
| 85 | + |
| 86 | + return await client.SendFlurlRequestAsJsonAsync<Models.CloseRepaymentPartnerCombineTransactionResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments