mirror of
https://github.com/dromara/payment-spring-boot.git
synced 2026-03-13 21:33:41 +08:00
feat: 微信支付V3新的退款退款通知
- 增加退款通知事件 - 增加解密逻辑
This commit is contained in:
@@ -18,10 +18,7 @@
|
||||
package cn.felord.payment.wechat.v3;
|
||||
|
||||
import cn.felord.payment.PayException;
|
||||
import cn.felord.payment.wechat.v3.model.CallbackParams;
|
||||
import cn.felord.payment.wechat.v3.model.CouponConsumeData;
|
||||
import cn.felord.payment.wechat.v3.model.ResponseSignVerifyParams;
|
||||
import cn.felord.payment.wechat.v3.model.TransactionConsumeData;
|
||||
import cn.felord.payment.wechat.v3.model.*;
|
||||
import cn.felord.payment.wechat.v3.model.busifavor.BusiFavorReceiveConsumeData;
|
||||
import cn.felord.payment.wechat.v3.model.combine.CombineTransactionConsumeData;
|
||||
import cn.felord.payment.wechat.v3.model.discountcard.DiscountCardAcceptedConsumeData;
|
||||
@@ -272,6 +269,34 @@ public class WechatPayCallback {
|
||||
return Collections.singletonMap("code", "SUCCESS");
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款结果通知API
|
||||
* <p>
|
||||
* 退款状态改变后,微信会把相关退款结果发送给商户。
|
||||
*
|
||||
* @param params the params
|
||||
* @param consumeDataConsumer the consume data consumer
|
||||
* @return map
|
||||
*/
|
||||
@SneakyThrows
|
||||
public Map<String, ?> refundCallback(ResponseSignVerifyParams params, Consumer<RefundConsumeData> consumeDataConsumer) {
|
||||
CallbackParams callbackParams = resolve(params);
|
||||
String eventType = callbackParams.getEventType();
|
||||
|
||||
if (!Objects.equals(eventType, EventType.REFUND_CLOSED.event)||
|
||||
!Objects.equals(eventType,EventType.REFUND_ABNORMAL.event)||
|
||||
!Objects.equals(eventType,EventType.REFUND_SUCCESS.event)) {
|
||||
log.error("wechat pay event type is not matched, callbackParams {}", callbackParams);
|
||||
throw new PayException(" wechat pay event type is not matched");
|
||||
}
|
||||
String data = this.decrypt(callbackParams);
|
||||
RefundConsumeData consumeData = MAPPER.readValue(data, RefundConsumeData.class);
|
||||
|
||||
consumeDataConsumer.accept(consumeData);
|
||||
return Collections.singletonMap("code", "SUCCESS");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback.
|
||||
*
|
||||
@@ -403,7 +428,28 @@ public class WechatPayCallback {
|
||||
*
|
||||
* @since 1.0.0.RELEASE
|
||||
*/
|
||||
TRANSACTION("TRANSACTION.SUCCESS");
|
||||
TRANSACTION("TRANSACTION.SUCCESS"),
|
||||
|
||||
/**
|
||||
* 退款成功事件.
|
||||
*
|
||||
* @since 1.0.6.RELEASE
|
||||
*/
|
||||
REFUND_SUCCESS("REFUND.SUCCESS"),
|
||||
|
||||
/**
|
||||
* 退款异常事件.
|
||||
*
|
||||
* @since 1.0.6.RELEASE
|
||||
*/
|
||||
REFUND_ABNORMAL("REFUND.ABNORMAL"),
|
||||
|
||||
/**
|
||||
* 退款关闭事件.
|
||||
*
|
||||
* @since 1.0.6.RELEASE
|
||||
*/
|
||||
REFUND_CLOSED("REFUND.CLOSED");
|
||||
|
||||
/**
|
||||
* The Event.
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2019-2020 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.v3.model;
|
||||
|
||||
import cn.felord.payment.wechat.enumeration.RefundStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
/**
|
||||
* 微信支付退款结果通知解密
|
||||
*
|
||||
* @author felord.cn
|
||||
* @since 1.0.6.RELEASE
|
||||
*/
|
||||
@Data
|
||||
public class RefundConsumeData {
|
||||
/**
|
||||
* 直连商户号
|
||||
*/
|
||||
private String mchid;
|
||||
/**
|
||||
* 商户订单号
|
||||
*/
|
||||
private String outTradeNo;
|
||||
/**
|
||||
* 微信订单号
|
||||
*/
|
||||
private String transactionId;
|
||||
/**
|
||||
* 商户退款单号
|
||||
*/
|
||||
private String outRefundNo;
|
||||
/**
|
||||
* 微信退款单号
|
||||
*/
|
||||
private String refundId;
|
||||
/**
|
||||
* 退款状态
|
||||
*/
|
||||
private RefundStatus refundStatus;
|
||||
/**
|
||||
* 退款成功时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss", timezone = "GMT+8")
|
||||
private OffsetDateTime successTime;
|
||||
/**
|
||||
* 退款入账账户
|
||||
*/
|
||||
private String userReceivedAccount;
|
||||
|
||||
/**
|
||||
* 微信支付退款金额信息
|
||||
*
|
||||
* @author felord.cn
|
||||
* @since 1.0.6.RELEASE
|
||||
*/
|
||||
@Data
|
||||
public static class Amount {
|
||||
/**
|
||||
* 订单金额,单位为分
|
||||
*/
|
||||
private Integer total;
|
||||
/**
|
||||
* 退款金额,单位为分
|
||||
*/
|
||||
private Integer refund;
|
||||
/**
|
||||
* 用户实际支付金额,单位为分
|
||||
*/
|
||||
|
||||
private Integer payerTotal;
|
||||
/**
|
||||
* 退款给用户的金额,单位为分,不包含所有优惠券金额
|
||||
*/
|
||||
private Integer payerRefund;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user