feat: 微信支付V3新的退款查询退款API

- 在WechatDirectPayApi中增加新的微信支付V3退款API
- 在WechatDirectPayApi中增加新的微信支付V3查询单笔退款API
This commit is contained in:
felord.cn
2021-02-03 11:41:49 +08:00
committed by felord.cn
parent 2bbe9a80cd
commit 581851e672
13 changed files with 256 additions and 11 deletions

View File

@@ -11,7 +11,7 @@
<dependency>
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot-starter</artifactId>
<version>1.0.5.RELEASE</version>
<version>1.0.6.RELEASE</version>
</dependency>
```

View File

@@ -34,7 +34,7 @@
<dependency>
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot-starter</artifactId>
<version>1.0.5.RELEASE</version>
<version>1.0.6.RELEASE</version>
</dependency>
```
## 采用技术

View File

@@ -4,7 +4,7 @@
<dependency>
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot-starter</artifactId>
<version>1.0.5.RELEASE</version>
<version>1.0.6.RELEASE</version>
</dependency>
```
> 基于 **Spring Boot 2.x**

View File

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

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.enumeration;
/**
* @author felord.cn
* @since 1.0.6.RELEASE
*/
public enum RefundStatus {
}

View File

@@ -93,17 +93,29 @@ public enum WechatPayV3Type {
*/
CLOSE(HttpMethod.POST, "%s/v3/pay/transactions/out-trade-no/{out_trade_no}/close"),
/**
* 微信支付订单号查询.
* 微信支付订单号查询API.
*
* @since 1.0.0.RELEASE
*/
TRANSACTION_TRANSACTION_ID(HttpMethod.GET, "%s/v3/pay/transactions/id/{transaction_id}"),
/**
* 商户订单号查询.
* 商户订单号查询API.
*
* @since 1.0.0.RELEASE
*/
TRANSACTION_OUT_TRADE_NO(HttpMethod.GET, "%s/v3/pay/transactions/out-trade-no/{out_trade_no}"),
/**
* 申请退款API.
*
* @since 1.0.6.RELEASE
*/
REFUND(HttpMethod.POST, "%s/v3/refund/domestic/refunds"),
/**
* 查询退款API.
*
* @since 1.0.6.RELEASE
*/
QUERY_REFUND(HttpMethod.GET, "%s/v3/refund/domestic/refunds/{out_refund_no}"),
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -19,6 +19,7 @@
package cn.felord.payment.wechat.v3;
import cn.felord.payment.wechat.v2.WechatPayRedpackApi;
import cn.felord.payment.wechat.v2.WechatPayRefundApi;
import cn.felord.payment.wechat.v2.WechatPayTransfersApi;
import cn.felord.payment.wechat.v2.WechatV2Client;
@@ -122,6 +123,22 @@ public class WechatApiProvider {
return new WechatPayCallback(wechatPayClient.signatureProvider(), tenantId);
}
/**
* 退款基于V2
*
* @param tenantId the tenant id
* @return the wechat pay refund api
* @since 1.0.6.RELEASE
*/
@Deprecated
public WechatPayRefundApi refund(String tenantId) {
WechatMetaBean wechatMeta = wechatPayClient.signatureProvider()
.wechatMetaContainer()
.getWechatMeta(tenantId);
WechatV2Client wechatV2Client = new WechatV2Client(wechatMeta);
return new WechatPayRefundApi(wechatV2Client);
}
/**
* 现金红包基于V2
*

View File

@@ -23,6 +23,7 @@ import cn.felord.payment.wechat.WechatPayProperties;
import cn.felord.payment.wechat.enumeration.WeChatServer;
import cn.felord.payment.wechat.enumeration.WechatPayV3Type;
import cn.felord.payment.wechat.v3.model.PayParams;
import cn.felord.payment.wechat.v3.model.RefundParams;
import cn.felord.payment.wechat.v3.model.TransactionQueryParams;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.springframework.http.RequestEntity;
@@ -265,4 +266,47 @@ public class WechatDirectPayApi extends AbstractApi {
return Post(uri, queryParams);
}
/**
* 申请退款API
*
* @param refundParams the refund params
* @return the wechat response entity
* @since 1.0.6.RELEASE
*/
public WechatResponseEntity<ObjectNode> refund(RefundParams refundParams) {
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
this.client().withType(WechatPayV3Type.REFUND, refundParams)
.function(((type, params) -> {
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
.build()
.toUri();
return Post(uri, params);
}))
.consumer(wechatResponseEntity::convert)
.request();
return wechatResponseEntity;
}
/**
* 查询单笔退款API
*
* @param outRefundNo the out refund no
* @return the wechat response entity
* @since 1.0.6.RELEASE
*/
public WechatResponseEntity<ObjectNode> queryRefundInfo(String outRefundNo) {
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
this.client().withType(WechatPayV3Type.QUERY_REFUND, outRefundNo)
.function(((type, param) -> {
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
.build()
.expand(param)
.toUri();
return Get(uri);
}))
.consumer(wechatResponseEntity::convert)
.request();
return wechatResponseEntity;
}
}

View File

@@ -323,6 +323,8 @@ public class WechatMarketingFavorApi extends AbstractApi {
* 查询代金券详情API
* <p>
* 通过此接口可查询代金券信息,包括代金券的基础信息、状态。如代金券已核销,会包括代金券核销的订单信息(订单号、单品信息等)。
* <p>
* 2021-1 微信侧不再返回{@code consume_information}字段
*
* @param params the params
* @return the wechat response entity

View File

@@ -0,0 +1,53 @@
/*
* 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.v3.model;
import lombok.Data;
/**
* 退款订单的商品信息
*
* @author felord.cn
* @since 1.0.6.RELEASE
*/
@Data
public class RefundGoodsDetail {
/**
* 商户侧商品编码
*/
private String merchantGoodsId;
/**
* 微信侧商品编码
*/
private String wechatpayGoodsId;
/**
* 商品名称
*/
private String goodsName;
/**
* 商品单价金额,单位为分。
*/
private Integer unitPrice;
/**
* 商品退款金额,单位为分。
*/
private Integer refundAmount;
/**
* 单品的退款数量。
*/
private Integer refundQuantity;
}

View File

@@ -0,0 +1,92 @@
/*
*
* 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.v3.model;
import lombok.Data;
import java.util.List;
/**
* 退款请求参数
*
* @author felord.cn
* @since 1.0.6.RELEASE
*/
@Data
public class RefundParams {
/**
* 微信支付订单号,同{@link RefundParams#outTradeNo} 二选一
*/
private String transactionId;
/**
* 商户订单号,同{@link RefundParams#transactionId} 二选一
*/
private String outTradeNo;
/**
* 商户退款单号
*/
private String outRefundNo;
/**
* 退款原因
*/
private String reason;
/**
* 退款结果回调url
*/
private String notifyUrl;
/**
* 退款资金来源,若传递此参数则使用对应的资金账户退款,否则默认使用未结算资金退款(仅对老资金流商户适用)。
* 枚举值:
* <ul>
* <li>AVAILABLE可用余额账户</li>
* </ul>
*/
private String fundsAccount;
/**
* 退款订单金额信息
*/
private RefundAmount amount;
/**
* 退款订单的商品信息
*/
private List<RefundGoodsDetail> goodsDetail;
/**
* 退款订单金额信息
*
* @author felord.cn
* @since 1.0.6.RELEASE
*/
@Data
public static class RefundAmount {
/**
* 原订单金额,币种的最小单位,只能为整数,不能超过原订单支付金额。
*/
private Integer total;
/**
* 符合ISO 4217标准的三位字母代码目前只支持人民币CNY。
*/
private String currency = "CNY";
/**
* 退款金额,币种的最小单位,只能为整数,不能超过原订单支付金额。
*/
private Integer refund;
}
}

View File

@@ -5,11 +5,11 @@
<parent>
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot</artifactId>
<version>1.0.5.RELEASE</version>
<version>1.0.6.RELEASE</version>
</parent>
<artifactId>payment-spring-boot-starter</artifactId>
<version>1.0.5.RELEASE</version>
<version>1.0.6.RELEASE</version>
<packaging>jar</packaging>
<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">
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot</artifactId>
<version>1.0.5.RELEASE</version>
<version>1.0.6.RELEASE</version>
<packaging>pom</packaging>
<modelVersion>4.0.0</modelVersion>
@@ -30,7 +30,7 @@
</developers>
<scm>
<tag>payment-spring-boot-1.0.5.RELEASE</tag>
<tag>payment-spring-boot-1.0.6.RELEASE</tag>
<url>https://github.com/NotFound403/payment-spring-boot</url>
<connection>scm:git:https://github.com/NotFound403/payment-spring-boot.git</connection>
<developerConnection>scm:git:https://github.com/NotFound403/payment-spring-boot.git</developerConnection>