Skip to content

Commit 8b30615

Browse files
committed
binarywang#530 微信支付申请退款接口结果类增加单个代金券相关参数 ,并根据官方文档整理其他参数
1 parent 2063dcf commit 8b30615

File tree

5 files changed

+192
-72
lines changed

5 files changed

+192
-72
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.github.binarywang.wxpay.bean.result;
2+
3+
import com.thoughtworks.xstream.annotations.XStreamAlias;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
/**
9+
* <pre>
10+
* 退款代金券信息.
11+
* Created by BinaryWang on 2018/4/21.
12+
* </pre>
13+
*
14+
* @author Binary Wang
15+
*/
16+
@Data
17+
@NoArgsConstructor
18+
@AllArgsConstructor
19+
public class WxPayRefundCouponInfo {
20+
/**
21+
* <pre>
22+
* 字段名:退款代金券ID.
23+
* 变量名:coupon_refund_id_$n_$m
24+
* 是否必填:否
25+
* 类型:String(20)
26+
* 示例值:10000
27+
* 描述:退款代金券ID, $n为下标,$m为下标,从0开始编号
28+
* </pre>
29+
*/
30+
@XStreamAlias("coupon_refund_id")
31+
private String couponRefundId;
32+
33+
/**
34+
* <pre>
35+
* 字段名:单个退款代金券支付金额.
36+
* 变量名:coupon_refund_fee_$n_$m
37+
* 是否必填:否
38+
* 类型:Int
39+
* 示例值:100
40+
* 描述:单个退款代金券支付金额, $n为下标,$m为下标,从0开始编号
41+
* </pre>
42+
*/
43+
@XStreamAlias("coupon_refund_fee")
44+
private Integer couponRefundFee;
45+
46+
/**
47+
* <pre>
48+
* 字段名:代金券类型.
49+
* 变量名:coupon_type_$n_$m
50+
* 是否必填:否
51+
* 类型:String(8)
52+
* 示例值:CASH
53+
* 描述:CASH--充值代金券 , NO_CASH---非充值代金券。
54+
* 开通免充值券功能,并且订单使用了优惠券后有返回(取值:CASH、NO_CASH)。
55+
* $n为下标,$m为下标,从0开始编号,举例:coupon_type_$0_$1
56+
* </pre>
57+
*/
58+
@XStreamAlias("coupon_type")
59+
private String couponType;
60+
61+
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayRefundQueryResult.java

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ public void composeRefundRecords() {
151151
continue;
152152
}
153153

154-
List<RefundRecord.RefundCoupon> coupons = Lists.newArrayList();
154+
List<WxPayRefundCouponInfo> coupons = Lists.newArrayList();
155155
for (int j = 0; j < refundRecord.getCouponRefundCount(); j++) {
156156
coupons.add(
157-
new RefundRecord.RefundCoupon(
157+
new WxPayRefundCouponInfo(
158158
this.getXmlValue("xml/coupon_refund_id_" + i + "_" + j),
159159
this.getXmlValueAsInt("xml/coupon_refund_fee_" + i + "_" + j),
160160
this.getXmlValue("xml/coupon_type_" + i + "_" + j)
@@ -277,7 +277,7 @@ public static class RefundRecord {
277277
@XStreamAlias("coupon_refund_count")
278278
private Integer couponRefundCount;
279279

280-
private List<RefundCoupon> refundCoupons;
280+
private List<WxPayRefundCouponInfo> refundCoupons;
281281

282282
/**
283283
* <pre>
@@ -323,54 +323,6 @@ public static class RefundRecord {
323323
@XStreamAlias("refund_success_time")
324324
private String refundSuccessTime;
325325

326-
@Data
327-
@NoArgsConstructor
328-
@AllArgsConstructor
329-
public static class RefundCoupon {
330-
/**
331-
* <pre>
332-
* 字段名:退款代金券ID.
333-
* 变量名:coupon_refund_id_$n_$m
334-
* 是否必填:否
335-
* 类型:String(20)
336-
* 示例值:10000
337-
* 描述:退款代金券ID, $n为下标,$m为下标,从0开始编号
338-
* </pre>
339-
*/
340-
@XStreamAlias("coupon_refund_id")
341-
private String couponRefundId;
342-
343-
/**
344-
* <pre>
345-
* 字段名:单个退款代金券支付金额.
346-
* 变量名:coupon_refund_fee_$n_$m
347-
* 是否必填:否
348-
* 类型:Int
349-
* 示例值:100
350-
* 描述:单个退款代金券支付金额, $n为下标,$m为下标,从0开始编号
351-
* </pre>
352-
*/
353-
@XStreamAlias("coupon_refund_fee")
354-
private Integer couponRefundFee;
355-
356-
/**
357-
* <pre>
358-
* 字段名:代金券类型.
359-
* 变量名:coupon_type_$n_$m
360-
* 是否必填:否
361-
* 类型:String(8)
362-
* 示例值:CASH
363-
* 描述:CASH--充值代金券 , NO_CASH---非充值代金券。
364-
* 开通免充值券功能,并且订单使用了优惠券后有返回(取值:CASH、NO_CASH)。
365-
* $n为下标,$m为下标,从0开始编号,举例:coupon_type_$0_$1
366-
* </pre>
367-
*/
368-
@XStreamAlias("coupon_type")
369-
private String couponType;
370-
371-
372-
}
373-
374326
}
375327

376328
}
Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,122 @@
11
package com.github.binarywang.wxpay.bean.result;
22

3+
import com.google.common.collect.Lists;
34
import com.thoughtworks.xstream.annotations.XStreamAlias;
45
import lombok.Data;
56
import lombok.EqualsAndHashCode;
67
import lombok.NoArgsConstructor;
78

89
import java.io.Serializable;
10+
import java.util.List;
911

1012
/**
1113
* <pre>
12-
* 微信支付-申请退款返回结果
14+
* 微信支付-申请退款返回结果.
1315
* https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
1416
* </pre>
1517
*
16-
* @author liukaitj
18+
* @author liukaitj & Binary Wang
1719
*/
1820
@Data
1921
@EqualsAndHashCode(callSuper = true)
2022
@NoArgsConstructor
2123
@XStreamAlias("xml")
2224
public class WxPayRefundResult extends BaseWxPayResult implements Serializable {
23-
private static final long serialVersionUID = 1L;
24-
25-
@XStreamAlias("device_info")
26-
private String deviceInfo;
27-
25+
private static final long serialVersionUID = -3392333879907788033L;
26+
/**
27+
* 微信订单号.
28+
*/
2829
@XStreamAlias("transaction_id")
2930
private String transactionId;
3031

32+
/**
33+
* 商户订单号.
34+
*/
3135
@XStreamAlias("out_trade_no")
3236
private String outTradeNo;
3337

38+
/**
39+
* 商户退款单号.
40+
*/
3441
@XStreamAlias("out_refund_no")
3542
private String outRefundNo;
3643

44+
/**
45+
* 微信退款单号.
46+
*/
3747
@XStreamAlias("refund_id")
3848
private String refundId;
3949

40-
@XStreamAlias("refund_channel")
41-
private String refundChannel;
42-
50+
/**
51+
* 退款金额.
52+
*/
4353
@XStreamAlias("refund_fee")
44-
private String refundFee;
54+
private Integer refundFee;
4555

56+
/**
57+
* 应结退款金额.
58+
*/
59+
@XStreamAlias("settlement_refund_fee")
60+
private Integer settlementRefundFee;
61+
62+
/**
63+
* 标价金额.
64+
*/
4665
@XStreamAlias("total_fee")
47-
private String totalFee;
66+
private Integer totalFee;
67+
68+
/**
69+
* 应结订单金额.
70+
*/
71+
@XStreamAlias("settlement_total_fee")
72+
private Integer settlementTotalFee;
4873

74+
/**
75+
* 标价币种.
76+
*/
4977
@XStreamAlias("fee_type")
5078
private String feeType;
5179

80+
/**
81+
* 现金支付金额.
82+
*/
5283
@XStreamAlias("cash_fee")
53-
private String cashFee;
84+
private Integer cashFee;
5485

86+
/**
87+
* 现金支付币种.
88+
*/
89+
@XStreamAlias("cash_fee_type")
90+
private String cashFeeType;
91+
92+
/**
93+
* 现金退款金额.
94+
*/
5595
@XStreamAlias("cash_refund_fee")
5696
private String cashRefundFee;
5797

58-
@XStreamAlias("coupon_refund_fee")
59-
private String couponRefundFee;
60-
98+
/**
99+
* 退款代金券使用数量.
100+
*/
61101
@XStreamAlias("coupon_refund_count")
62-
private String couponRefundCount;
63-
64-
@XStreamAlias("coupon_refund_id")
65-
private String couponRefundId;
66-
102+
private Integer couponRefundCount;
103+
104+
private List<WxPayRefundCouponInfo> refundCoupons;
105+
106+
/**
107+
* 组装生成退款代金券信息.
108+
*/
109+
public void composeRefundCoupons() {
110+
List<WxPayRefundCouponInfo> coupons = Lists.newArrayList();
111+
for (int i = 0; i < this.getCouponRefundCount(); i++) {
112+
coupons.add(
113+
new WxPayRefundCouponInfo(
114+
this.getXmlValue("xml/coupon_refund_id_" + i),
115+
this.getXmlValueAsInt("xml/coupon_refund_fee_" + i),
116+
this.getXmlValue("xml/coupon_type_" + i)
117+
)
118+
);
119+
}
120+
this.setRefundCoupons(coupons);
121+
}
67122
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public WxPayRefundResult refund(WxPayRefundRequest request) throws WxPayExceptio
131131
String url = this.getPayBaseUrl() + "/secapi/pay/refund";
132132
String responseContent = this.post(url, request.toXML(), true);
133133
WxPayRefundResult result = BaseWxPayResult.fromXML(responseContent, WxPayRefundResult.class);
134+
result.composeRefundCoupons();
134135
result.checkResult(this, request.getSignType(), true);
135136
return result;
136137
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.github.binarywang.wxpay.bean.result;
2+
3+
import org.testng.annotations.Test;
4+
5+
import static org.assertj.core.api.Assertions.assertThat;
6+
7+
/**
8+
* <pre>
9+
* Created by BinaryWang on 2018/4/22.
10+
* </pre>
11+
*
12+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
13+
*/
14+
public class WxPayRefundResultTest {
15+
16+
@Test
17+
public void testComposeRefundCoupons() {
18+
/*
19+
该xml字符串来自于官方文档示例,稍加改造,加上代金卷
20+
refund_channel 是个什么鬼,官方文档只字不提
21+
*/
22+
String xmlString = "<xml>\n" +
23+
" <return_code><![CDATA[SUCCESS]]></return_code>\n" +
24+
" <return_msg><![CDATA[OK]]></return_msg>\n" +
25+
" <appid><![CDATA[wx2421b1c4370ec43b]]></appid>\n" +
26+
" <mch_id><![CDATA[10000100]]></mch_id>\n" +
27+
" <nonce_str><![CDATA[NfsMFbUFpdbEhPXP]]></nonce_str>\n" +
28+
" <sign><![CDATA[B7274EB9F8925EB93100DD2085FA56C0]]></sign>\n" +
29+
" <result_code><![CDATA[SUCCESS]]></result_code>\n" +
30+
" <transaction_id><![CDATA[1008450740201411110005820873]]></transaction_id>\n" +
31+
" <out_trade_no><![CDATA[1415757673]]></out_trade_no>\n" +
32+
" <out_refund_no><![CDATA[1415701182]]></out_refund_no>\n" +
33+
" <refund_id><![CDATA[2008450740201411110000174436]]></refund_id>\n" +
34+
" <refund_channel><![CDATA[]]></refund_channel>\n" +
35+
" <coupon_refund_fee>1</coupon_refund_fee>\n" +
36+
" <coupon_refund_count>1</coupon_refund_count>\n" +
37+
" <coupon_refund_id_0>123</coupon_refund_id_0>\n" +
38+
" <coupon_refund_fee_0>1</coupon_refund_fee_0>\n" +
39+
" <coupon_type_0><![CDATA[CASH]]></coupon_type_0>\n" +
40+
" <refund_fee>2</refund_fee> \n" +
41+
"</xml>";
42+
43+
WxPayRefundResult result = WxPayRefundResult.fromXML(xmlString, WxPayRefundResult.class);
44+
result.composeRefundCoupons();
45+
46+
assertThat(result.getRefundCoupons()).isNotEmpty();
47+
assertThat(result.getRefundCoupons().get(0).getCouponRefundId()).isEqualTo("123");
48+
assertThat(result.getRefundCoupons().get(0).getCouponType()).isEqualTo("CASH");
49+
assertThat(result.getRefundCoupons().get(0).getCouponRefundFee()).isEqualTo(1);
50+
}
51+
}

0 commit comments

Comments
 (0)