mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-24 18:04:38 +08:00
完成订单查询结果对象中coupon的组装逻辑代码,并加入单元测试
This commit is contained in:
parent
c47b8eceba
commit
cbf78114f7
@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.bean.pay.result;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -17,6 +18,7 @@ import java.util.List;
|
||||
* <li>示例值
|
||||
* <li>描述
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a>
|
||||
*/
|
||||
@XStreamAlias("xml")
|
||||
@ -179,75 +181,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
|
||||
private Integer couponCount;
|
||||
|
||||
private List<Coupon> coupons;
|
||||
|
||||
public static class Coupon {
|
||||
/**
|
||||
* <pre>代金券类型
|
||||
* coupon_type_$n
|
||||
* 否
|
||||
* String
|
||||
* CASH
|
||||
* <li>CASH--充值代金券
|
||||
* <li>NO_CASH---非充值代金券
|
||||
* 订单使用代金券时有返回(取值:CASH、NO_CASH)。$n为下标,从0开始编号,举例:coupon_type_$0
|
||||
* </pre>
|
||||
*/
|
||||
private String couponType;
|
||||
|
||||
/**
|
||||
* <pre>代金券ID
|
||||
* coupon_id_$n
|
||||
* 否
|
||||
* String(20)
|
||||
* 10000
|
||||
* 代金券ID, $n为下标,从0开始编号
|
||||
* </pre>
|
||||
*/
|
||||
private String couponId;
|
||||
|
||||
/**
|
||||
* <pre>单个代金券支付金额
|
||||
* coupon_fee_$n
|
||||
* 否
|
||||
* Int
|
||||
* 100
|
||||
* 单个代金券支付金额, $n为下标,从0开始编号
|
||||
* </pre>
|
||||
*/
|
||||
private Integer couponFee;
|
||||
|
||||
public Coupon(String couponType, String couponId, Integer couponFee) {
|
||||
this.couponType = couponType;
|
||||
this.couponId = couponId;
|
||||
this.couponFee = couponFee;
|
||||
}
|
||||
|
||||
public String getCouponType() {
|
||||
return this.couponType;
|
||||
}
|
||||
|
||||
public void setCouponType(String couponType) {
|
||||
this.couponType = couponType;
|
||||
}
|
||||
|
||||
public String getCouponId() {
|
||||
return this.couponId;
|
||||
}
|
||||
|
||||
public void setCouponId(String couponId) {
|
||||
this.couponId = couponId;
|
||||
}
|
||||
|
||||
public Integer getCouponFee() {
|
||||
return this.couponFee;
|
||||
}
|
||||
|
||||
public void setCouponFee(Integer couponFee) {
|
||||
this.couponFee = couponFee;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>微信支付订单号
|
||||
* transaction_id
|
||||
@ -259,7 +192,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
|
||||
*/
|
||||
@XStreamAlias("transaction_id")
|
||||
private String transactionId;
|
||||
|
||||
/**
|
||||
* <pre>商户订单号
|
||||
* out_trade_no
|
||||
@ -271,7 +203,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
|
||||
*/
|
||||
@XStreamAlias("out_trade_no")
|
||||
private String outTradeNo;
|
||||
|
||||
/**
|
||||
* <pre>附加数据
|
||||
* attach
|
||||
@ -283,7 +214,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
|
||||
*/
|
||||
@XStreamAlias("attach")
|
||||
private String attach;
|
||||
|
||||
/**
|
||||
* <pre>支付完成时间
|
||||
* time_end
|
||||
@ -295,7 +225,6 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
|
||||
*/
|
||||
@XStreamAlias("time_end")
|
||||
private String timeEnd;
|
||||
|
||||
/**
|
||||
* <pre>交易状态描述
|
||||
* trade_state_desc
|
||||
@ -460,10 +389,86 @@ public class WxPayOrderQueryResult extends WxPayBaseResult {
|
||||
this.tradeStateDesc = tradeStateDesc;
|
||||
}
|
||||
|
||||
public void composeCoupons(String xmlString){
|
||||
if(this.couponCount != null && this.couponCount > 0 ){
|
||||
/**
|
||||
* 通过xml组装coupons属性内容
|
||||
*/
|
||||
public void composeCoupons() {
|
||||
if (this.couponCount != null && this.couponCount > 0) {
|
||||
this.coupons = Lists.newArrayList();
|
||||
//TODO 暂时待实现
|
||||
XmlPath xmlPath = new XmlPath(this.getXmlString());
|
||||
for (int i = 0; i < this.couponCount; i++){
|
||||
this.coupons.add(new Coupon(this.getXmlValueIfExists(xmlPath, "xml.coupon_type_" + i, String.class),
|
||||
this.getXmlValueIfExists(xmlPath, "xml.coupon_id_" + i, String.class),
|
||||
this.getXmlValueIfExists(xmlPath, "xml.coupon_fee_" + i, Integer.class)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Coupon {
|
||||
/**
|
||||
* <pre>代金券类型
|
||||
* coupon_type_$n
|
||||
* 否
|
||||
* String
|
||||
* CASH
|
||||
* <li>CASH--充值代金券
|
||||
* <li>NO_CASH---非充值代金券
|
||||
* 订单使用代金券时有返回(取值:CASH、NO_CASH)。$n为下标,从0开始编号,举例:coupon_type_$0
|
||||
* </pre>
|
||||
*/
|
||||
private String couponType;
|
||||
|
||||
/**
|
||||
* <pre>代金券ID
|
||||
* coupon_id_$n
|
||||
* 否
|
||||
* String(20)
|
||||
* 10000
|
||||
* 代金券ID, $n为下标,从0开始编号
|
||||
* </pre>
|
||||
*/
|
||||
private String couponId;
|
||||
|
||||
/**
|
||||
* <pre>单个代金券支付金额
|
||||
* coupon_fee_$n
|
||||
* 否
|
||||
* Int
|
||||
* 100
|
||||
* 单个代金券支付金额, $n为下标,从0开始编号
|
||||
* </pre>
|
||||
*/
|
||||
private Integer couponFee;
|
||||
|
||||
public Coupon(String couponType, String couponId, Integer couponFee) {
|
||||
this.couponType = couponType;
|
||||
this.couponId = couponId;
|
||||
this.couponFee = couponFee;
|
||||
}
|
||||
|
||||
public String getCouponType() {
|
||||
return this.couponType;
|
||||
}
|
||||
|
||||
public void setCouponType(String couponType) {
|
||||
this.couponType = couponType;
|
||||
}
|
||||
|
||||
public String getCouponId() {
|
||||
return this.couponId;
|
||||
}
|
||||
|
||||
public void setCouponId(String couponId) {
|
||||
this.couponId = couponId;
|
||||
}
|
||||
|
||||
public Integer getCouponFee() {
|
||||
return this.couponFee;
|
||||
}
|
||||
|
||||
public void setCouponFee(Integer couponFee) {
|
||||
this.couponFee = couponFee;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
package me.chanjar.weixin.mp.bean.pay.result;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by Binary Wang on 2017-01-04.
|
||||
* @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a>
|
||||
* </pre>
|
||||
*/
|
||||
public class WxPayOrderQueryResultTest {
|
||||
@Test
|
||||
public void testComposeCoupons() throws Exception {
|
||||
/**
|
||||
* xml样例字符串来自于官方文档,并稍加改造加入了coupon相关的数据便于测试
|
||||
*/
|
||||
String xmlString = "<xml>\n" +
|
||||
" <return_code><![CDATA[SUCCESS]]></return_code>\n" +
|
||||
" <return_msg><![CDATA[OK]]></return_msg>\n" +
|
||||
" <appid><![CDATA[wx2421b1c4370ec43b]]></appid>\n" +
|
||||
" <mch_id><![CDATA[10000100]]></mch_id>\n" +
|
||||
" <device_info><![CDATA[1000]]></device_info>\n" +
|
||||
" <nonce_str><![CDATA[TN55wO9Pba5yENl8]]></nonce_str>\n" +
|
||||
" <sign><![CDATA[BDF0099C15FF7BC6B1585FBB110AB635]]></sign>\n" +
|
||||
" <result_code><![CDATA[SUCCESS]]></result_code>\n" +
|
||||
" <openid><![CDATA[oUpF8uN95-Ptaags6E_roPHg7AG0]]></openid>\n" +
|
||||
" <is_subscribe><![CDATA[Y]]></is_subscribe>\n" +
|
||||
" <trade_type><![CDATA[MICROPAY]]></trade_type>\n" +
|
||||
" <bank_type><![CDATA[CCB_DEBIT]]></bank_type>\n" +
|
||||
" <total_fee>1</total_fee>\n" +
|
||||
" <fee_type><![CDATA[CNY]]></fee_type>\n" +
|
||||
" <transaction_id><![CDATA[1008450740201411110005820873]]></transaction_id>\n" +
|
||||
" <out_trade_no><![CDATA[1415757673]]></out_trade_no>\n" +
|
||||
" <attach><![CDATA[订单额外描述]]></attach>\n" +
|
||||
" <time_end><![CDATA[20141111170043]]></time_end>\n" +
|
||||
" <trade_state><![CDATA[SUCCESS]]></trade_state>\n" +
|
||||
" <coupon_count>2</coupon_count>\n" +
|
||||
" <coupon_type_0><![CDATA[CASH]]></coupon_type_0>\n" +
|
||||
" <coupon_id_0>10000</coupon_id_0>\n" +
|
||||
" <coupon_fee_0>100</coupon_fee_0>\n" +
|
||||
" <coupon_type_1><![CDATA[NO_CASH]]></coupon_type_1>\n" +
|
||||
" <coupon_id_1>10001</coupon_id_1>\n" +
|
||||
" <coupon_fee_1>200</coupon_fee_1>\n" +
|
||||
"</xml>";
|
||||
|
||||
WxPayOrderQueryResult orderQueryResult = WxPayOrderQueryResult.fromXML(xmlString, WxPayOrderQueryResult.class);
|
||||
orderQueryResult.composeCoupons();
|
||||
|
||||
Assert.assertEquals(orderQueryResult.getCouponCount().intValue(), 2);
|
||||
Assert.assertNotNull(orderQueryResult.getCoupons());
|
||||
Assert.assertEquals(orderQueryResult.getCoupons().size(), 2);
|
||||
|
||||
Assert.assertEquals(orderQueryResult.getCoupons().get(0).getCouponFee().intValue(), 100);
|
||||
Assert.assertEquals(orderQueryResult.getCoupons().get(1).getCouponFee().intValue(), 200);
|
||||
|
||||
Assert.assertEquals(orderQueryResult.getCoupons().get(0).getCouponType(), "CASH");
|
||||
Assert.assertEquals(orderQueryResult.getCoupons().get(1).getCouponType(), "NO_CASH");
|
||||
|
||||
Assert.assertEquals(orderQueryResult.getCoupons().get(0).getCouponId(), "10000");
|
||||
Assert.assertEquals(orderQueryResult.getCoupons().get(1).getCouponId(), "10001");
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user