mirror of
https://github.com/dromara/payment-spring-boot.git
synced 2026-03-14 05:43:46 +08:00
feat: 增加V2退款
- 由于V3没有退款 所以暂时用V2退款代替
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ import java.security.cert.CertificateException;
|
||||
* @since 1.0.5.RELEASE
|
||||
*/
|
||||
@Getter
|
||||
public class BaseModel {
|
||||
public abstract class BaseModel {
|
||||
private static final XmlMapper XML_MAPPER = new XmlMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -262,7 +262,7 @@ public class WechatPayClient {
|
||||
responseConsumer.accept(responseEntity);
|
||||
}
|
||||
} else {
|
||||
throw new PayException("wechat pay signature failed, Request-ID " + requestId);
|
||||
throw new PayException("wechat pay signature verify failed, Request-ID " + requestId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,11 +29,11 @@ import lombok.Data;
|
||||
@Data
|
||||
public class Amount {
|
||||
/**
|
||||
* The Total.
|
||||
* 金额,单位【分】。
|
||||
*/
|
||||
private int total;
|
||||
/**
|
||||
* The Currency.
|
||||
* 货币单位,固定为 CNY 。
|
||||
*/
|
||||
private String currency = "CNY";
|
||||
}
|
||||
|
||||
@@ -29,54 +29,58 @@ import lombok.Data;
|
||||
@Data
|
||||
public class CallbackParams {
|
||||
/**
|
||||
* The Id.
|
||||
* 通知Id
|
||||
*/
|
||||
private String id;
|
||||
/**
|
||||
* The Create time.
|
||||
* 通知创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
/**
|
||||
* The Event type.
|
||||
* 通知类型
|
||||
* @see cn.felord.payment.wechat.v3.WechatPayCallback
|
||||
*/
|
||||
private String eventType;
|
||||
/**
|
||||
* The Resource type.
|
||||
* 通知数据类型
|
||||
*/
|
||||
private String resourceType;
|
||||
/**
|
||||
* The Summary.
|
||||
* 回调摘要
|
||||
*/
|
||||
private String summary;
|
||||
/**
|
||||
* The Resource.
|
||||
* 通知数据
|
||||
*/
|
||||
private Resource resource;
|
||||
|
||||
|
||||
/**
|
||||
* The type Resource.
|
||||
* 通知数据
|
||||
*
|
||||
* @author felord.cn
|
||||
* @since 1.0.0.RELEASE
|
||||
*/
|
||||
@Data
|
||||
public static class Resource {
|
||||
/**
|
||||
* The Algorithm.
|
||||
* 对开启结果数据进行加密的加密算法,目前只支持AEAD_AES_256_GCM。
|
||||
*/
|
||||
private String algorithm;
|
||||
/**
|
||||
* The Ciphertext.
|
||||
* Base64编码后的开启/停用结果数据密文。
|
||||
*/
|
||||
private String ciphertext;
|
||||
/**
|
||||
* The Associated data.
|
||||
* 附加数据。
|
||||
*/
|
||||
private String associatedData;
|
||||
/**
|
||||
* The Nonce.
|
||||
* 加密使用的随机串。
|
||||
*/
|
||||
private String nonce;
|
||||
/**
|
||||
* The Original type.
|
||||
* 原始回调类型。
|
||||
*/
|
||||
private String originalType;
|
||||
}
|
||||
|
||||
@@ -32,22 +32,22 @@ import java.util.List;
|
||||
public class ConsumeInformation {
|
||||
|
||||
/**
|
||||
* The Consume mchid.
|
||||
* 核销商户号
|
||||
*/
|
||||
private String consumeMchid;
|
||||
|
||||
/**
|
||||
* The Consume time.
|
||||
* 核销时间 YYYY-MM-DDTHH:mm:ss.sss+TIMEZONE
|
||||
*/
|
||||
private String consumeTime;
|
||||
|
||||
/**
|
||||
* The Goods detail.
|
||||
* 商户下单接口传的单品信息
|
||||
*/
|
||||
private List<GoodsDetail> goodsDetail;
|
||||
|
||||
/**
|
||||
* The Transaction id.
|
||||
* 核销订单号
|
||||
*/
|
||||
private String transactionId;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package cn.felord.payment.wechat.v3.model;
|
||||
|
||||
import cn.felord.payment.wechat.enumeration.CouponStatus;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -30,67 +31,68 @@ import lombok.Data;
|
||||
public class CouponConsumeData {
|
||||
|
||||
/**
|
||||
* The Available begin time.
|
||||
* 可用开始时间 YYYY-MM-DDTHH:mm:ss.sss+TIMEZONE
|
||||
*/
|
||||
private String availableBeginTime;
|
||||
/**
|
||||
* The Available end time.
|
||||
* 可用结束时间 YYYY-MM-DDTHH:mm:ss.sss+TIMEZONE
|
||||
*/
|
||||
private String availableEndTime;
|
||||
/**
|
||||
* The Consume information.
|
||||
* 实扣代金券信息
|
||||
*/
|
||||
private ConsumeInformation consumeInformation;
|
||||
/**
|
||||
* The Coupon id.
|
||||
* 代金券id
|
||||
*/
|
||||
private String couponId;
|
||||
/**
|
||||
* The Coupon name.
|
||||
* 代金券名称
|
||||
*/
|
||||
private String couponName;
|
||||
/**
|
||||
* The Coupon type.
|
||||
* 代金券类型
|
||||
*/
|
||||
private CouponType couponType;
|
||||
/**
|
||||
* The Create time.
|
||||
* 领券时间
|
||||
*/
|
||||
private String createTime;
|
||||
/**
|
||||
* The Description.
|
||||
* 代金券描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* The Discount to.
|
||||
* 减至优惠特定信息
|
||||
*/
|
||||
private DiscountTo discountTo;
|
||||
/**
|
||||
* The No cash.
|
||||
* 是否无资金流
|
||||
*/
|
||||
private Boolean noCash;
|
||||
/**
|
||||
* The Normal coupon information.
|
||||
* 普通满减券信息
|
||||
*/
|
||||
private NormalCouponInformation normalCouponInformation;
|
||||
/**
|
||||
* The Singleitem.
|
||||
* 是否单品优惠
|
||||
*/
|
||||
private Boolean singleitem;
|
||||
/**
|
||||
* The Singleitem discount off.
|
||||
* 单品优惠特定信息
|
||||
*/
|
||||
private SingleitemDiscountOff singleitemDiscountOff;
|
||||
/**
|
||||
* The Status.
|
||||
* 代金券状态
|
||||
* @see CouponStatus
|
||||
*/
|
||||
private String status;
|
||||
private CouponStatus status;
|
||||
/**
|
||||
* The Stock creator mchid.
|
||||
* 创建批次的商户号
|
||||
*/
|
||||
private String stockCreatorMchid;
|
||||
/**
|
||||
* The Stock id.
|
||||
* 批次号
|
||||
*/
|
||||
private String stockId;
|
||||
|
||||
|
||||
@@ -30,19 +30,19 @@ import lombok.Data;
|
||||
public class GoodsDetail {
|
||||
|
||||
/**
|
||||
* The Discount amount.
|
||||
* 优惠金额,单位【分】
|
||||
*/
|
||||
private Long discountAmount;
|
||||
/**
|
||||
* The Goods id.
|
||||
* 单品券创建时录入的单品编码。
|
||||
*/
|
||||
private String goodsId;
|
||||
/**
|
||||
* The Price.
|
||||
* 单品单价
|
||||
*/
|
||||
private Long price;
|
||||
/**
|
||||
* The Quantity.
|
||||
* 单品数量
|
||||
*/
|
||||
private Long quantity;
|
||||
|
||||
|
||||
@@ -30,11 +30,11 @@ import lombok.Data;
|
||||
public class NormalCouponInformation {
|
||||
|
||||
/**
|
||||
* The Coupon amount.
|
||||
* 面额,单位:分。
|
||||
*/
|
||||
private Long couponAmount;
|
||||
/**
|
||||
* The Transaction minimum.
|
||||
* 使用券金额门槛,单位:分。
|
||||
*/
|
||||
private Long transactionMinimum;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Promotion detail.
|
||||
* 优惠功能
|
||||
*
|
||||
* @author felord.cn
|
||||
* @since 1.0.0.RELEASE
|
||||
@@ -33,52 +33,60 @@ import java.util.List;
|
||||
public class PromotionDetail {
|
||||
|
||||
/**
|
||||
* The Amount.
|
||||
* 优惠券面额,单位【分】
|
||||
*/
|
||||
private Long amount;
|
||||
/**
|
||||
* The Coupon id.
|
||||
* 券ID
|
||||
*/
|
||||
private String couponId;
|
||||
/**
|
||||
* The Currency.
|
||||
* 优惠币种,内商户号仅支持人民币 CNY
|
||||
*/
|
||||
private String currency;
|
||||
/**
|
||||
* The Goods detail.
|
||||
* 单品列表信息
|
||||
*/
|
||||
private List<GoodsDetail> goodsDetail;
|
||||
/**
|
||||
* The Merchant contribute.
|
||||
* 商户出资,单位为分
|
||||
*/
|
||||
private Long merchantContribute;
|
||||
/**
|
||||
* The Name.
|
||||
* 优惠名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* The Other contribute.
|
||||
* 其他出资,单位为分
|
||||
*/
|
||||
private Long otherContribute;
|
||||
/**
|
||||
* The Scope.
|
||||
* 优惠范围
|
||||
* <ul>
|
||||
* <li>GLOBAL:全场代金券</li>
|
||||
* <li>SINGLE:单品优惠</li>
|
||||
* </ul>
|
||||
*/
|
||||
private String scope;
|
||||
/**
|
||||
* The Stock id.
|
||||
* 活动ID
|
||||
*/
|
||||
private String stockId;
|
||||
/**
|
||||
* The Type.
|
||||
* 优惠类型
|
||||
* <ul>
|
||||
* <li>CASH:充值</li>
|
||||
* <li>NOCASH:预充值</li>
|
||||
* </ul>
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* The Wechatpay contribute.
|
||||
* 微信出资,单位为分
|
||||
*/
|
||||
private Long wechatpayContribute;
|
||||
|
||||
/**
|
||||
* The type Goods detail.
|
||||
* 单品列表信息
|
||||
*
|
||||
* @author felord.cn
|
||||
* @since 1.0.0.RELEASE
|
||||
@@ -87,23 +95,23 @@ public class PromotionDetail {
|
||||
public static class GoodsDetail {
|
||||
|
||||
/**
|
||||
* The Goods id.
|
||||
* 商品编码
|
||||
*/
|
||||
private String goodsId;
|
||||
/**
|
||||
* The Quantity.
|
||||
* 商品数量
|
||||
*/
|
||||
private Long quantity;
|
||||
/**
|
||||
* The Unit price.
|
||||
* 商品单价
|
||||
*/
|
||||
private Long unitPrice;
|
||||
/**
|
||||
* The Discount amount.
|
||||
* 商品优惠金额,单位【分】
|
||||
*/
|
||||
private Long discountAmount;
|
||||
/**
|
||||
* The Goods remark.
|
||||
* 商品备注
|
||||
*/
|
||||
private String goodsRemark;
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@ import lombok.Data;
|
||||
@Data
|
||||
public class SingleitemDiscountOff {
|
||||
|
||||
/**
|
||||
* 单品最高优惠价格,单位:分。
|
||||
*/
|
||||
private Long singlePriceMax;
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付成功通知解密
|
||||
*
|
||||
* @author felord.cn
|
||||
* @since 1.0.0.RELEASE
|
||||
*/
|
||||
@@ -32,67 +34,71 @@ import java.util.List;
|
||||
public class TransactionConsumeData {
|
||||
|
||||
/**
|
||||
* The Amount.
|
||||
* 订单金额
|
||||
*/
|
||||
private Amount amount;
|
||||
/**
|
||||
* The Appid.
|
||||
* 应用ID
|
||||
*/
|
||||
private String appid;
|
||||
/**
|
||||
* The Attach.
|
||||
* 附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用
|
||||
*/
|
||||
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;
|
||||
/**
|
||||
* The Mchid.
|
||||
* 商户号
|
||||
*/
|
||||
private String mchid;
|
||||
/**
|
||||
* The Out trade no.
|
||||
* 商户订单号
|
||||
*/
|
||||
private String outTradeNo;
|
||||
/**
|
||||
* The Payer.
|
||||
* 支付者信息
|
||||
*/
|
||||
private Payer payer;
|
||||
/**
|
||||
* The Promotion detail.
|
||||
* 优惠功能,享受优惠时返回该字段。
|
||||
*/
|
||||
private List<PromotionDetail> promotionDetail;
|
||||
/**
|
||||
* The Scene info.
|
||||
* 支付场景信息描述
|
||||
*/
|
||||
private SceneInfo sceneInfo;
|
||||
/**
|
||||
* The Success time.
|
||||
* 支付完成时间 YYYY-MM-DDTHH:mm:ss+TIMEZONE
|
||||
*/
|
||||
private String successTime;
|
||||
/**
|
||||
* 在 1.0.0.RELEASE 直接返回了枚举字符串,1.0.2.RELEASE 中变更为枚举
|
||||
*
|
||||
* @since 1.0.0.RELEASE
|
||||
*/
|
||||
private TradeState tradeState;
|
||||
/**
|
||||
* The Trade state desc.
|
||||
* 交易状态描述
|
||||
*/
|
||||
private String tradeStateDesc;
|
||||
/**
|
||||
* 交易类型
|
||||
* <p>
|
||||
* 在 1.0.0.RELEASE 直接返回了枚举字符串,1.0.2.RELEASE 中变更为枚举
|
||||
*
|
||||
* @since 1.0.0.RELEASE
|
||||
*/
|
||||
private TradeType tradeType;
|
||||
/**
|
||||
* The Transaction id.
|
||||
* 微信支付订单号
|
||||
*/
|
||||
private String transactionId;
|
||||
|
||||
|
||||
/**
|
||||
* The type Payer.
|
||||
* 支付者信息
|
||||
*
|
||||
* @author felord.cn
|
||||
* @since 1.0.0.RELEASE
|
||||
@@ -100,13 +106,13 @@ public class TransactionConsumeData {
|
||||
@Data
|
||||
public static class Payer {
|
||||
/**
|
||||
* The Openid.
|
||||
* 用户在直连商户appid下的唯一标识。
|
||||
*/
|
||||
private String openid;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type Scene info.
|
||||
* 支付场景信息描述
|
||||
*
|
||||
* @author felord.cn
|
||||
* @since 1.0.0.RELEASE
|
||||
@@ -114,13 +120,13 @@ public class TransactionConsumeData {
|
||||
@Data
|
||||
public static class SceneInfo {
|
||||
/**
|
||||
* The Device id.
|
||||
* 商户端设备号(门店号或收银设备ID)。
|
||||
*/
|
||||
private String deviceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type Amount.
|
||||
* 订单金额
|
||||
*
|
||||
* @author felord.cn
|
||||
* @since 1.0.0.RELEASE
|
||||
@@ -128,19 +134,19 @@ public class TransactionConsumeData {
|
||||
@Data
|
||||
public static class Amount {
|
||||
/**
|
||||
* The Total.
|
||||
* 订单总金额,单位为分。
|
||||
*/
|
||||
private Integer total;
|
||||
/**
|
||||
* The Payer total.
|
||||
* 用户支付金额,单位为分。
|
||||
*/
|
||||
private Integer payerTotal;
|
||||
/**
|
||||
* The Currency.
|
||||
* CNY:人民币,境内商户号仅支持人民币。
|
||||
*/
|
||||
private String currency;
|
||||
/**
|
||||
* The Payer currency.
|
||||
* 用户支付币种
|
||||
*/
|
||||
private String payerCurrency;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user