1
0
mirror of synced 2026-10-13 18:58:41 +08:00

🎨 #4024 【微信支付】补齐 V3 退款通知回调中 amount 对象的官方字段并兼容旧 refund 映射

This commit is contained in:
Copilot
2026-06-06 20:27:21 +08:00
committed by GitHub
parent 126750b298
commit cae7d4fbf2
2 changed files with 174 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* 退款结果通知.
@@ -175,7 +176,7 @@ public class WxPayRefundNotifyV3Result implements Serializable, WxPayBaseNotifyV
/**
* <pre>
* 字段名:退款金额
* 变量名:refund
* 变量名:refund_fee
* 是否必填:是
* 类型:int
* 描述:
@@ -183,8 +184,21 @@ public class WxPayRefundNotifyV3Result implements Serializable, WxPayBaseNotifyV
* 示例值:999
* </pre>
*/
@SerializedName(value = "refund")
private Integer refund;
@SerializedName(value = "refund_fee", alternate = {"refund"})
private Integer refundFee;
/**
* <pre>
* 字段名:退款结算金额
* 变量名:settlement_refund
* 是否必填:否
* 类型:int
* 描述:
* 退款结算金额,单位为分。
* 示例值:999
* </pre>
*/
@SerializedName(value = "settlement_refund")
private Integer settlementRefund;
/**
* <pre>
* 字段名:用户支付金额
@@ -211,5 +225,101 @@ public class WxPayRefundNotifyV3Result implements Serializable, WxPayBaseNotifyV
*/
@SerializedName(value = "payer_refund")
private Integer payerRefund;
/**
* <pre>
* 字段名:币种
* 变量名:currency
* 是否必填:否
* 类型:string[1,16]
* 描述:
* 符合ISO 4217标准的三位字母代码,目前只支持人民币:CNY。
* 示例值:CNY
* </pre>
*/
@SerializedName(value = "currency")
private String currency;
/**
* <pre>
* 字段名:结算金额
* 变量名:settlement_total
* 是否必填:否
* 类型:int
* 描述:
* 结算金额,单位为分。
* 示例值:999
* </pre>
*/
@SerializedName(value = "settlement_total")
private Integer settlementTotal;
/**
* <pre>
* 字段名:优惠券退款金额
* 变量名:discount_refund
* 是否必填:否
* 类型:int
* 描述:
* 优惠券退款金额,单位为分。
* 示例值:0
* </pre>
*/
@SerializedName(value = "discount_refund")
private Integer discountRefund;
/**
* <pre>
* 字段名:退款账户来源
* 变量名:from
* 是否必填:否
* 类型:array
* 描述:
* 退款出资的账户类型及金额信息
* </pre>
*/
@SerializedName(value = "from")
private List<FromItem> from;
@Deprecated
public Integer getRefund() {
return this.refundFee;
}
@Deprecated
public void setRefund(Integer refund) {
this.refundFee = refund;
}
}
@Data
@NoArgsConstructor
public static class FromItem implements Serializable {
private static final long serialVersionUID = 1L;
/**
* <pre>
* 字段名:退款账户类型
* 变量名:account
* 是否必填:是
* 类型:string[1,32]
* 描述:
* 下面枚举值多选一。
* 枚举值:
* AVAILABLE : 可用余额
* UNAVAILABLE : 不可用余额
* 示例值:AVAILABLE
* </pre>
*/
@SerializedName(value = "account")
private String account;
/**
* <pre>
* 字段名:退款账户金额
* 变量名:amount
* 是否必填:是
* 类型:int
* 描述:
* 对应账户退款金额
* 示例值:444
* </pre>
*/
@SerializedName(value = "amount")
private Integer amount;
}
}

View File

@@ -0,0 +1,61 @@
package com.github.binarywang.wxpay.bean.notify;
import com.google.gson.Gson;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class WxPayRefundNotifyV3ResultTest {
private static final Gson GSON = new Gson();
@Test
public void shouldDeserializeOfficialAmountFields() {
String json = "{"
+ "\"mchid\":\"1900000100\","
+ "\"out_trade_no\":\"1217752501201407033233368018\","
+ "\"transaction_id\":\"4200000000000000000000000000\","
+ "\"out_refund_no\":\"1217752501201407033233368019\","
+ "\"refund_id\":\"50000000382019052709732678859\","
+ "\"refund_status\":\"SUCCESS\","
+ "\"success_time\":\"2020-12-01T12:00:00+08:00\","
+ "\"user_received_account\":\"支付用户零钱\","
+ "\"amount\":{"
+ "\"refund_fee\":10,"
+ "\"settlement_refund\":9,"
+ "\"total\":100,"
+ "\"currency\":\"CNY\","
+ "\"payer_total\":90,"
+ "\"payer_refund\":10,"
+ "\"settlement_total\":90,"
+ "\"discount_refund\":1,"
+ "\"from\":[{\"account\":\"AVAILABLE\",\"amount\":10}]"
+ "}"
+ "}";
WxPayRefundNotifyV3Result.DecryptNotifyResult result =
GSON.fromJson(json, WxPayRefundNotifyV3Result.DecryptNotifyResult.class);
assertThat(result.getAmount().getRefundFee()).isEqualTo(10);
assertThat(result.getAmount().getRefund()).isEqualTo(10);
assertThat(result.getAmount().getSettlementRefund()).isEqualTo(9);
assertThat(result.getAmount().getTotal()).isEqualTo(100);
assertThat(result.getAmount().getCurrency()).isEqualTo("CNY");
assertThat(result.getAmount().getPayerTotal()).isEqualTo(90);
assertThat(result.getAmount().getPayerRefund()).isEqualTo(10);
assertThat(result.getAmount().getSettlementTotal()).isEqualTo(90);
assertThat(result.getAmount().getDiscountRefund()).isEqualTo(1);
assertThat(result.getAmount().getFrom()).hasSize(1);
assertThat(result.getAmount().getFrom().get(0).getAccount()).isEqualTo("AVAILABLE");
assertThat(result.getAmount().getFrom().get(0).getAmount()).isEqualTo(10);
}
@Test
public void shouldKeepBackwardCompatibilityForRefundAlias() {
WxPayRefundNotifyV3Result.Amount amount =
GSON.fromJson("{\"refund\":88}", WxPayRefundNotifyV3Result.Amount.class);
assertThat(amount.getRefundFee()).isEqualTo(88);
assertThat(amount.getRefund()).isEqualTo(88);
}
}