feat: 增加V2退款

- 由于V3没有退款 所以暂时用V2退款代替
This commit is contained in:
felord.cn
2021-01-23 11:38:41 +08:00
committed by felord.cn
parent dc9933e1e8
commit 49bf3d3d50
17 changed files with 235 additions and 87 deletions

View File

@@ -5,11 +5,11 @@
<parent> <parent>
<groupId>cn.felord</groupId> <groupId>cn.felord</groupId>
<artifactId>payment-spring-boot</artifactId> <artifactId>payment-spring-boot</artifactId>
<version>1.0.4.RELEASE</version> <version>1.0.5.SNAPSHOT</version>
</parent> </parent>
<artifactId>payment-spring-boot-autoconfigure</artifactId> <artifactId>payment-spring-boot-autoconfigure</artifactId>
<version>1.0.4.RELEASE</version> <version>1.0.5.SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2019-2021 felord.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* Website:
* https://felord.cn
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.felord.payment.wechat.v2;
import cn.felord.payment.wechat.WechatPayProperties;
import cn.felord.payment.wechat.v2.model.RefundModel;
import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.http.HttpMethod;
/**
* The type Wechat pay refund api.
*
* @author felord.cn
* @since 1.0.4.RELEASE
*/
public class WechatPayRefundApi {
private final WechatV2Client wechatV2Client;
/**
* Instantiates a new Wechat pay refund api.
*
* @param wechatV2Client the wechat v 2 client
*/
public WechatPayRefundApi(WechatV2Client wechatV2Client) {
this.wechatV2Client = wechatV2Client;
}
/**
* 退款
*
* @param refundModel the refund model
* @return json node
*/
public JsonNode transfer(RefundModel refundModel) {
WechatPayProperties.V3 v3 = wechatV2Client.getWechatMetaBean().getV3();
refundModel.setAppid(v3.getAppId());
refundModel.setMchId(v3.getMchId());
return wechatV2Client.wechatPayRequest(refundModel,
HttpMethod.POST,
"https://api.mch.weixin.qq.com/secapi/pay/refund");
}
}

View File

@@ -61,7 +61,7 @@ import java.security.cert.CertificateException;
* @since 1.0.5.RELEASE * @since 1.0.5.RELEASE
*/ */
@Getter @Getter
public class BaseModel { public abstract class BaseModel {
private static final XmlMapper XML_MAPPER = new XmlMapper(); private static final XmlMapper XML_MAPPER = new XmlMapper();
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2019-2021 felord.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* Website:
* https://felord.cn
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.felord.payment.wechat.v2.model;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author felord.cn
* @since 1.0.4.RELEASE
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class RefundModel extends BaseModel {
private String appid;
private String mchId;
private String signType="MD5";
private String transactionId;
private String outTradeNo;
private String outRefundNo;
private Integer totalFee;
private Integer refundFee;
private String refundFeeType="CNY";
private String refundDesc;
private String refundAccount;
private String notifyUrl;
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright 2019-2021 felord.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* Website:
* https://felord.cn
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.felord.payment.wechat.v2.model;
/**
* @author felord.cn
* @since 1.0.4.RELEASE
*/
public class RefundQueryModel {
}

View File

@@ -262,7 +262,7 @@ public class WechatPayClient {
responseConsumer.accept(responseEntity); responseConsumer.accept(responseEntity);
} }
} else { } else {
throw new PayException("wechat pay signature failed, Request-ID " + requestId); throw new PayException("wechat pay signature verify failed, Request-ID " + requestId);
} }
} }

View File

@@ -29,11 +29,11 @@ import lombok.Data;
@Data @Data
public class Amount { public class Amount {
/** /**
* The Total. * 金额,单位【分】。
*/ */
private int total; private int total;
/** /**
* The Currency. * 货币单位,固定为 CNY 。
*/ */
private String currency = "CNY"; private String currency = "CNY";
} }

View File

@@ -29,54 +29,58 @@ import lombok.Data;
@Data @Data
public class CallbackParams { public class CallbackParams {
/** /**
* The Id. * 通知Id
*/ */
private String id; private String id;
/** /**
* The Create time. * 通知创建时间
*/ */
private String createTime; private String createTime;
/** /**
* The Event type. * 通知类型
* @see cn.felord.payment.wechat.v3.WechatPayCallback
*/ */
private String eventType; private String eventType;
/** /**
* The Resource type. * 通知数据类型
*/ */
private String resourceType; private String resourceType;
/** /**
* The Summary. * 回调摘要
*/ */
private String summary; private String summary;
/** /**
* The Resource. * 通知数据
*/ */
private Resource resource; private Resource resource;
/** /**
* The type Resource. * 通知数据
*
* @author felord.cn
* @since 1.0.0.RELEASE
*/ */
@Data @Data
public static class Resource { public static class Resource {
/** /**
* The Algorithm. * 对开启结果数据进行加密的加密算法目前只支持AEAD_AES_256_GCM。
*/ */
private String algorithm; private String algorithm;
/** /**
* The Ciphertext. * Base64编码后的开启/停用结果数据密文。
*/ */
private String ciphertext; private String ciphertext;
/** /**
* The Associated data. * 附加数据。
*/ */
private String associatedData; private String associatedData;
/** /**
* The Nonce. * 加密使用的随机串。
*/ */
private String nonce; private String nonce;
/** /**
* The Original type. * 原始回调类型。
*/ */
private String originalType; private String originalType;
} }

View File

@@ -32,22 +32,22 @@ import java.util.List;
public class ConsumeInformation { public class ConsumeInformation {
/** /**
* The Consume mchid. * 核销商户号
*/ */
private String consumeMchid; private String consumeMchid;
/** /**
* The Consume time. * 核销时间 YYYY-MM-DDTHH:mm:ss.sss+TIMEZONE
*/ */
private String consumeTime; private String consumeTime;
/** /**
* The Goods detail. * 商户下单接口传的单品信息
*/ */
private List<GoodsDetail> goodsDetail; private List<GoodsDetail> goodsDetail;
/** /**
* The Transaction id. * 核销订单号
*/ */
private String transactionId; private String transactionId;

View File

@@ -18,6 +18,7 @@
*/ */
package cn.felord.payment.wechat.v3.model; package cn.felord.payment.wechat.v3.model;
import cn.felord.payment.wechat.enumeration.CouponStatus;
import lombok.Data; import lombok.Data;
/** /**
@@ -30,67 +31,68 @@ import lombok.Data;
public class CouponConsumeData { public class CouponConsumeData {
/** /**
* The Available begin time. * 可用开始时间 YYYY-MM-DDTHH:mm:ss.sss+TIMEZONE
*/ */
private String availableBeginTime; private String availableBeginTime;
/** /**
* The Available end time. * 可用结束时间 YYYY-MM-DDTHH:mm:ss.sss+TIMEZONE
*/ */
private String availableEndTime; private String availableEndTime;
/** /**
* The Consume information. * 实扣代金券信息
*/ */
private ConsumeInformation consumeInformation; private ConsumeInformation consumeInformation;
/** /**
* The Coupon id. * 代金券id
*/ */
private String couponId; private String couponId;
/** /**
* The Coupon name. * 代金券名称
*/ */
private String couponName; private String couponName;
/** /**
* The Coupon type. * 代金券类型
*/ */
private CouponType couponType; private CouponType couponType;
/** /**
* The Create time. * 领券时间
*/ */
private String createTime; private String createTime;
/** /**
* The Description. * 代金券描述
*/ */
private String description; private String description;
/** /**
* The Discount to. * 减至优惠特定信息
*/ */
private DiscountTo discountTo; private DiscountTo discountTo;
/** /**
* The No cash. * 是否无资金流
*/ */
private Boolean noCash; private Boolean noCash;
/** /**
* The Normal coupon information. * 普通满减券信息
*/ */
private NormalCouponInformation normalCouponInformation; private NormalCouponInformation normalCouponInformation;
/** /**
* The Singleitem. * 是否单品优惠
*/ */
private Boolean singleitem; private Boolean singleitem;
/** /**
* The Singleitem discount off. * 单品优惠特定信息
*/ */
private SingleitemDiscountOff singleitemDiscountOff; private SingleitemDiscountOff singleitemDiscountOff;
/** /**
* The Status. * 代金券状态
* @see CouponStatus
*/ */
private String status; private CouponStatus status;
/** /**
* The Stock creator mchid. * 创建批次的商户号
*/ */
private String stockCreatorMchid; private String stockCreatorMchid;
/** /**
* The Stock id. * 批次号
*/ */
private String stockId; private String stockId;

View File

@@ -30,19 +30,19 @@ import lombok.Data;
public class GoodsDetail { public class GoodsDetail {
/** /**
* The Discount amount. * 优惠金额,单位【分】
*/ */
private Long discountAmount; private Long discountAmount;
/** /**
* The Goods id. * 单品券创建时录入的单品编码。
*/ */
private String goodsId; private String goodsId;
/** /**
* The Price. * 单品单价
*/ */
private Long price; private Long price;
/** /**
* The Quantity. * 单品数量
*/ */
private Long quantity; private Long quantity;

View File

@@ -30,11 +30,11 @@ import lombok.Data;
public class NormalCouponInformation { public class NormalCouponInformation {
/** /**
* The Coupon amount. * 面额,单位:分。
*/ */
private Long couponAmount; private Long couponAmount;
/** /**
* The Transaction minimum. * 使用券金额门槛,单位:分。
*/ */
private Long transactionMinimum; private Long transactionMinimum;

View File

@@ -24,7 +24,7 @@ import lombok.Data;
import java.util.List; import java.util.List;
/** /**
* The type Promotion detail. * 优惠功能
* *
* @author felord.cn * @author felord.cn
* @since 1.0.0.RELEASE * @since 1.0.0.RELEASE
@@ -33,52 +33,60 @@ import java.util.List;
public class PromotionDetail { public class PromotionDetail {
/** /**
* The Amount. * 优惠券面额,单位【分】
*/ */
private Long amount; private Long amount;
/** /**
* The Coupon id. * 券ID
*/ */
private String couponId; private String couponId;
/** /**
* The Currency. * 优惠币种,内商户号仅支持人民币 CNY
*/ */
private String currency; private String currency;
/** /**
* The Goods detail. * 单品列表信息
*/ */
private List<GoodsDetail> goodsDetail; private List<GoodsDetail> goodsDetail;
/** /**
* The Merchant contribute. * 商户出资,单位为分
*/ */
private Long merchantContribute; private Long merchantContribute;
/** /**
* The Name. * 优惠名称
*/ */
private String name; private String name;
/** /**
* The Other contribute. * 其他出资,单位为分
*/ */
private Long otherContribute; private Long otherContribute;
/** /**
* The Scope. * 优惠范围
* <ul>
* <li>GLOBAL全场代金券</li>
* <li>SINGLE单品优惠</li>
* </ul>
*/ */
private String scope; private String scope;
/** /**
* The Stock id. * 活动ID
*/ */
private String stockId; private String stockId;
/** /**
* The Type. * 优惠类型
* <ul>
* <li>CASH充值</li>
* <li>NOCASH预充值</li>
* </ul>
*/ */
private String type; private String type;
/** /**
* The Wechatpay contribute. * 微信出资,单位为分
*/ */
private Long wechatpayContribute; private Long wechatpayContribute;
/** /**
* The type Goods detail. * 单品列表信息
* *
* @author felord.cn * @author felord.cn
* @since 1.0.0.RELEASE * @since 1.0.0.RELEASE
@@ -87,23 +95,23 @@ public class PromotionDetail {
public static class GoodsDetail { public static class GoodsDetail {
/** /**
* The Goods id. * 商品编码
*/ */
private String goodsId; private String goodsId;
/** /**
* The Quantity. * 商品数量
*/ */
private Long quantity; private Long quantity;
/** /**
* The Unit price. * 商品单价
*/ */
private Long unitPrice; private Long unitPrice;
/** /**
* The Discount amount. * 商品优惠金额,单位【分】
*/ */
private Long discountAmount; private Long discountAmount;
/** /**
* The Goods remark. * 商品备注
*/ */
private String goodsRemark; private String goodsRemark;

View File

@@ -29,6 +29,9 @@ import lombok.Data;
@Data @Data
public class SingleitemDiscountOff { public class SingleitemDiscountOff {
/**
* 单品最高优惠价格,单位:分。
*/
private Long singlePriceMax; private Long singlePriceMax;
} }

View File

@@ -25,6 +25,8 @@ import lombok.Data;
import java.util.List; import java.util.List;
/** /**
* 支付成功通知解密
*
* @author felord.cn * @author felord.cn
* @since 1.0.0.RELEASE * @since 1.0.0.RELEASE
*/ */
@@ -32,67 +34,71 @@ import java.util.List;
public class TransactionConsumeData { public class TransactionConsumeData {
/** /**
* The Amount. * 订单金额
*/ */
private Amount amount; private Amount amount;
/** /**
* The Appid. * 应用ID
*/ */
private String appid; private String appid;
/** /**
* The Attach. * 附加数据在查询API和支付通知中原样返回可作为自定义参数使用
*/ */
private String attach; private String attach;
/** /**
* The Bank type. * 银行类型,采用字符串类型的银行标识。银行标识请参考 <a target= "_blank" href= "https://pay.weixin.qq.com/wiki/doc/apiv3/terms_definition/chapter1_1_3.shtml#part-6">《银行类型对照表》</a>
*/ */
private String bankType; private String bankType;
/** /**
* The Mchid. * 商户号
*/ */
private String mchid; private String mchid;
/** /**
* The Out trade no. * 商户订单号
*/ */
private String outTradeNo; private String outTradeNo;
/** /**
* The Payer. * 支付者信息
*/ */
private Payer payer; private Payer payer;
/** /**
* The Promotion detail. * 优惠功能,享受优惠时返回该字段。
*/ */
private List<PromotionDetail> promotionDetail; private List<PromotionDetail> promotionDetail;
/** /**
* The Scene info. * 支付场景信息描述
*/ */
private SceneInfo sceneInfo; private SceneInfo sceneInfo;
/** /**
* The Success time. * 支付完成时间 YYYY-MM-DDTHH:mm:ss+TIMEZONE
*/ */
private String successTime; private String successTime;
/** /**
* 在 1.0.0.RELEASE 直接返回了枚举字符串1.0.2.RELEASE 中变更为枚举 * 在 1.0.0.RELEASE 直接返回了枚举字符串1.0.2.RELEASE 中变更为枚举
*
* @since 1.0.0.RELEASE * @since 1.0.0.RELEASE
*/ */
private TradeState tradeState; private TradeState tradeState;
/** /**
* The Trade state desc. * 交易状态描述
*/ */
private String tradeStateDesc; private String tradeStateDesc;
/** /**
* 交易类型
* <p>
* 在 1.0.0.RELEASE 直接返回了枚举字符串1.0.2.RELEASE 中变更为枚举 * 在 1.0.0.RELEASE 直接返回了枚举字符串1.0.2.RELEASE 中变更为枚举
*
* @since 1.0.0.RELEASE * @since 1.0.0.RELEASE
*/ */
private TradeType tradeType; private TradeType tradeType;
/** /**
* The Transaction id. * 微信支付订单号
*/ */
private String transactionId; private String transactionId;
/** /**
* The type Payer. * 支付者信息
* *
* @author felord.cn * @author felord.cn
* @since 1.0.0.RELEASE * @since 1.0.0.RELEASE
@@ -100,13 +106,13 @@ public class TransactionConsumeData {
@Data @Data
public static class Payer { public static class Payer {
/** /**
* The Openid. * 用户在直连商户appid下的唯一标识。
*/ */
private String openid; private String openid;
} }
/** /**
* The type Scene info. * 支付场景信息描述
* *
* @author felord.cn * @author felord.cn
* @since 1.0.0.RELEASE * @since 1.0.0.RELEASE
@@ -114,13 +120,13 @@ public class TransactionConsumeData {
@Data @Data
public static class SceneInfo { public static class SceneInfo {
/** /**
* The Device id. * 商户端设备号门店号或收银设备ID
*/ */
private String deviceId; private String deviceId;
} }
/** /**
* The type Amount. * 订单金额
* *
* @author felord.cn * @author felord.cn
* @since 1.0.0.RELEASE * @since 1.0.0.RELEASE
@@ -128,19 +134,19 @@ public class TransactionConsumeData {
@Data @Data
public static class Amount { public static class Amount {
/** /**
* The Total. * 订单总金额,单位为分。
*/ */
private Integer total; private Integer total;
/** /**
* The Payer total. * 用户支付金额,单位为分。
*/ */
private Integer payerTotal; private Integer payerTotal;
/** /**
* The Currency. * CNY人民币境内商户号仅支持人民币。
*/ */
private String currency; private String currency;
/** /**
* The Payer currency. * 用户支付币种
*/ */
private String payerCurrency; private String payerCurrency;
} }

View File

@@ -5,11 +5,11 @@
<parent> <parent>
<groupId>cn.felord</groupId> <groupId>cn.felord</groupId>
<artifactId>payment-spring-boot</artifactId> <artifactId>payment-spring-boot</artifactId>
<version>1.0.4.RELEASE</version> <version>1.0.5.SNAPSHOT</version>
</parent> </parent>
<artifactId>payment-spring-boot-starter</artifactId> <artifactId>payment-spring-boot-starter</artifactId>
<version>1.0.4.RELEASE</version> <version>1.0.5.SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>cn.felord</groupId> <groupId>cn.felord</groupId>
<artifactId>payment-spring-boot</artifactId> <artifactId>payment-spring-boot</artifactId>
<version>1.0.4.RELEASE</version> <version>1.0.5.SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>