feat(tenpayv3): 新增平台收付通发起异常退款相关接口
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeLint / Lint (push) Has been cancelled

This commit is contained in:
Fu Diwei 2024-10-14 10:51:44 +08:00
parent 5788de8aaf
commit 1ce5ee4f6f
8 changed files with 265 additions and 1 deletions

View File

@ -927,6 +927,8 @@
- 查询垫付回补结果:`GetEcommerceRefundReturnAdvance`
- 发起异常退款:`CreateEcommerceAbnormalRefundApply`
- 平台收付通(余额查询)
- 查询二级商户账户实时余额:`GetEcommerceFundBalance`

View File

@ -804,6 +804,28 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
return await client.SendFlurlRequestAsJsonAsync<Models.GetEcommerceRefundReturnAdvanceResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// <para>异步调用 [POST] /ecommerce/refunds/{refund_id}/apply-abnormal-refund 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://pay.weixin.qq.com/docs/partner/apis/ecommerce-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.CreateEcommerceAbnormalRefundApplyResponse> ExecuteCreateEcommerceAbnormalRefundApplyAsync(this WechatTenpayClient client, Models.CreateEcommerceAbnormalRefundApplyRequest 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, "ecommerce", "refunds", request.RefundId, "apply-abnormal-refund");
return await client.SendFlurlRequestAsJsonAsync<Models.CreateEcommerceAbnormalRefundApplyResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
#endregion
#region Subsidies

View File

@ -0,0 +1,97 @@
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
{
/// <summary>
/// <para>表示 [POST] /ecommerce/refunds/{refund_id}/apply-abnormal-refund 接口的请求。</para>
/// </summary>
[WechatTenpaySensitive]
public class CreateEcommerceAbnormalRefundApplyRequest : WechatTenpayRequest
{
public static class Types
{
public class Amount
{
/// <summary>
/// 获取或设置原订单金额(单位:分)。
/// </summary>
[Newtonsoft.Json.JsonProperty("total")]
[System.Text.Json.Serialization.JsonPropertyName("total")]
public int Total { get; set; }
/// <summary>
/// 获取或设置退款金额(单位:分)。
/// </summary>
[Newtonsoft.Json.JsonProperty("refund")]
[System.Text.Json.Serialization.JsonPropertyName("refund")]
public int Refund { get; set; }
/// <summary>
/// 获取或设置退款币种。
/// <para>默认值:"CNY"</para>
/// </summary>
[Newtonsoft.Json.JsonProperty("currency")]
[System.Text.Json.Serialization.JsonPropertyName("currency")]
public string Currency { get; set; } = "CNY";
}
}
/// <summary>
/// 获取或设置微信二级商户号。
/// </summary>
[Newtonsoft.Json.JsonProperty("sub_mchid")]
[System.Text.Json.Serialization.JsonPropertyName("sub_mchid")]
public string SubMerchantId { get; set; } = string.Empty;
/// <summary>
/// 获取或设置微信退款单号。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string RefundId { get; set; } = string.Empty;
/// <summary>
/// 获取或设置商户退款单号。
/// </summary>
[Newtonsoft.Json.JsonProperty("out_refund_no")]
[System.Text.Json.Serialization.JsonPropertyName("out_refund_no")]
public string OutRefundNumber { get; set; } = string.Empty;
/// <summary>
/// 获取或设置个人收款方受理授权 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("individual_auth_id")]
[System.Text.Json.Serialization.JsonPropertyName("individual_auth_id")]
public string? IndividualAuthId { get; set; }
/// <summary>
/// 获取或设置异常退款处理方式。
/// </summary>
[Newtonsoft.Json.JsonProperty("type")]
[System.Text.Json.Serialization.JsonPropertyName("type")]
public string Type { get; set; } = string.Empty;
/// <summary>
/// 获取或设置收款开户银行。
/// </summary>
[Newtonsoft.Json.JsonProperty("bank_type")]
[System.Text.Json.Serialization.JsonPropertyName("bank_type")]
public string? BankName { get; set; }
/// <summary>
/// 获取或设置收款银行卡号(需使用平台公钥/证书加密)。
/// </summary>
[Newtonsoft.Json.JsonProperty("bank_account")]
[System.Text.Json.Serialization.JsonPropertyName("bank_account")]
[WechatTenpaySensitiveProperty(scheme: Constants.SignSchemes.WECHATPAY2_RSA_2048_WITH_SHA256, algorithm: Constants.EncryptionAlgorithms.RSA_2048_ECB_PKCS8_OAEP_WITH_SHA1_AND_MGF1)]
[WechatTenpaySensitiveProperty(scheme: Constants.SignSchemes.WECHATPAY2_SM2_WITH_SM3, algorithm: Constants.EncryptionAlgorithms.SM2_C1C3C2_ASN1)]
public string? BankAccountNumber { get; set; }
/// <summary>
/// 获取或设置收款用户姓名(需使用平台公钥/证书加密)。
/// </summary>
[Newtonsoft.Json.JsonProperty("real_name")]
[System.Text.Json.Serialization.JsonPropertyName("real_name")]
[WechatTenpaySensitiveProperty(scheme: Constants.SignSchemes.WECHATPAY2_RSA_2048_WITH_SHA256, algorithm: Constants.EncryptionAlgorithms.RSA_2048_ECB_PKCS8_OAEP_WITH_SHA1_AND_MGF1)]
[WechatTenpaySensitiveProperty(scheme: Constants.SignSchemes.WECHATPAY2_SM2_WITH_SM3, algorithm: Constants.EncryptionAlgorithms.SM2_C1C3C2_ASN1)]
public string? RealName { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
{
/// <summary>
/// <para>表示 [POST] /ecommerce/refunds/{refund_id}/apply-abnormal-refund 接口的响应。</para>
/// </summary>
public class CreateEcommerceAbnormalRefundApplyResponse : GetEcommerceRefundByOutRefundNumberResponse
{
}
}

View File

@ -1,4 +1,4 @@
using System;
using System;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
{
@ -11,6 +11,26 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
{
public class Amount
{
public static class Types
{
public class From
{
/// <summary>
/// 获取或设置出资账户类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("account")]
[System.Text.Json.Serialization.JsonPropertyName("account")]
public string Account { get; set; } = default!;
/// <summary>
/// 获取或设置出资金额(单位:分)。
/// </summary>
[Newtonsoft.Json.JsonProperty("amount")]
[System.Text.Json.Serialization.JsonPropertyName("amount")]
public int Amount { get; set; }
}
}
/// <summary>
/// 获取或设置退款金额(单位:分)。
/// </summary>
@ -32,12 +52,26 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
[System.Text.Json.Serialization.JsonPropertyName("discount_refund")]
public int DiscountRefund { get; set; }
/// <summary>
/// 获取或设置电商平台垫付金额(单位:分)。
/// </summary>
[Newtonsoft.Json.JsonProperty("advance")]
[System.Text.Json.Serialization.JsonPropertyName("advance")]
public int? Advance { get; set; }
/// <summary>
/// 获取或设置退款币种。
/// </summary>
[Newtonsoft.Json.JsonProperty("currency")]
[System.Text.Json.Serialization.JsonPropertyName("currency")]
public string Currency { get; set; } = default!;
/// <summary>
/// 获取或设置退款出资账户及金额信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("from")]
[System.Text.Json.Serialization.JsonPropertyName("from")]
public Types.From[]? From { get; set; }
}
public class Promotion

View File

@ -0,0 +1,9 @@
{
"sub_mchid": "1900000109",
"individual_auth_id": "1900000110",
"out_refund_no": "1217752501201407033233368018",
"type": "USER_BANK_CARD",
"bank_type": "ICBC_DEBIT",
"bank_account": "d+xT+MQCvrLHUVDWv/8MR/dB7TkXLVfSrUxMPZy6jWWYzpRrEEaYQE8ZRGYoeorwC+w==",
"real_name": "UPgQcZSdq3zOayJwZ5XLrHY2dZU1W2Cd"
}

View File

@ -0,0 +1,35 @@
{
"refund_id": "1217752501201407033233368018",
"out_refund_no": "1217752501201407033233368018",
"transaction_id": "1217752501201407033233368018",
"out_trade_no": "1217752501201407033233368018",
"channel": "ORIGINAL",
"user_received_account": "招商银行信用卡0403",
"success_time": "2018-06-08T10:34:56+08:00",
"create_time": "2018-06-08T10:34:56+08:00",
"status": "SUCCESS",
"amount": {
"refund": 888,
"from": [
{
"account": "AVAILABLE",
"amount": 444
}
],
"payer_refund": 888,
"discount_refund": 888,
"currency": "CNY",
"advance": 888
},
"promotion_detail": [
{
"promotion_id": "109519",
"scope": "SINGLE",
"type": "DISCOUNT",
"amount": 5,
"refund_amount": 100
}
],
"refund_account": "REFUND_SOURCE_SUB_MERCHANT",
"funds_account": "UNSETTLED"
}

View File

@ -677,6 +677,62 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
}
}
[Fact(DisplayName = "测试用例:加密请求中的敏感数据([POST] /ecommerce/refunds/{refund_id}/apply-abnormal-refund")]
public async Task TestEncryptRequestSensitiveProperty_CreateEcommerceAbnormalRefundApplyRequest()
{
static Models.CreateEcommerceAbnormalRefundApplyRequest GenerateMockRequestModel()
{
return new Models.CreateEcommerceAbnormalRefundApplyRequest()
{
BankAccountNumber = MOCK_PLAIN_STR,
RealName = MOCK_PLAIN_STR
};
}
static void AssertMockRequestModel(Models.CreateEcommerceAbnormalRefundApplyRequest request, Func<string, string> decryptor)
{
Assert.NotEqual(MOCK_PLAIN_STR, request.BankAccountNumber!);
Assert.NotEqual(MOCK_PLAIN_STR, request.RealName!);
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.BankAccountNumber!));
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.RealName!));
Assert.Equal(MOCK_CERT_SN, request.WechatpayCertificateSerialNumber!, ignoreCase: true);
}
if (!string.IsNullOrEmpty(TestConfigs.WechatMerchantRSACertificatePrivateKey))
{
using (var client = CreateMockClientUseRSA(autoEncrypt: false))
{
var request = GenerateMockRequestModel();
client.EncryptRequestSensitiveProperty(request);
AssertMockRequestModel(request, (cipher) => Utilities.RSAUtility.DecryptWithECB(RSA_PEM_PRIVATE_KEY, (EncodedString)cipher)!);
}
using (var client = CreateMockClientUseRSA(autoEncrypt: true))
{
var request = GenerateMockRequestModel();
await client.ExecuteCreateEcommerceAbnormalRefundApplyAsync(request);
AssertMockRequestModel(request, (cipher) => Utilities.RSAUtility.DecryptWithECB(RSA_PEM_PRIVATE_KEY, (EncodedString)cipher)!);
}
}
if (!string.IsNullOrEmpty(TestConfigs.WechatMerchantSM2CertificatePrivateKey))
{
using (var client = CreateMockClientUseSM2(autoEncrypt: false))
{
var request = GenerateMockRequestModel();
client.EncryptRequestSensitiveProperty(request);
AssertMockRequestModel(request, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, (EncodedString)cipher)!);
}
using (var client = CreateMockClientUseSM2(autoEncrypt: true))
{
var request = GenerateMockRequestModel();
await client.ExecuteCreateEcommerceAbnormalRefundApplyAsync(request);
AssertMockRequestModel(request, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, (EncodedString)cipher)!);
}
}
}
[Fact(DisplayName = "测试用例:加密请求中的敏感数据([POST] /eduschoolpay/contracts/presign")]
public async Task TestEncryptRequestSensitiveProperty_PresignEducationSchoolPayContractRequest()
{