diff --git a/README.md b/README.md index 41a1dbd..fcf43ac 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ cn.felord payment-spring-boot-starter - 1.0.5.RELEASE + 1.0.6.RELEASE ``` diff --git a/docs/README.md b/docs/README.md index 88d5236..75c3d26 100644 --- a/docs/README.md +++ b/docs/README.md @@ -34,7 +34,7 @@ cn.felord payment-spring-boot-starter - 1.0.5.RELEASE + 1.0.6.RELEASE ``` ## 采用技术 diff --git a/docs/quick_start.md b/docs/quick_start.md index 46b7816..5babf14 100644 --- a/docs/quick_start.md +++ b/docs/quick_start.md @@ -4,7 +4,7 @@ cn.felord payment-spring-boot-starter - 1.0.5.RELEASE + 1.0.6.RELEASE ``` > 基于 **Spring Boot 2.x** diff --git a/payment-spring-boot-autoconfigure/pom.xml b/payment-spring-boot-autoconfigure/pom.xml index 55bf50f..da229ea 100644 --- a/payment-spring-boot-autoconfigure/pom.xml +++ b/payment-spring-boot-autoconfigure/pom.xml @@ -5,11 +5,11 @@ cn.felord payment-spring-boot - 1.0.5.RELEASE + 1.0.6.RELEASE payment-spring-boot-autoconfigure - 1.0.5.RELEASE + 1.0.6.RELEASE jar 4.0.0 diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/RefundStatus.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/RefundStatus.java new file mode 100644 index 0000000..d3bc755 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/RefundStatus.java @@ -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 { +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java index 9c91773..07bc41c 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java @@ -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}"), //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatApiProvider.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatApiProvider.java index 65483aa..514b67c 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatApiProvider.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatApiProvider.java @@ -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 * diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java index 954b975..d25793a 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java @@ -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 refund(RefundParams refundParams) { + WechatResponseEntity 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 queryRefundInfo(String outRefundNo) { + WechatResponseEntity 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; + } + } diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java index c602b31..87d63fe 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java @@ -323,6 +323,8 @@ public class WechatMarketingFavorApi extends AbstractApi { * 查询代金券详情API *

* 通过此接口可查询代金券信息,包括代金券的基础信息、状态。如代金券已核销,会包括代金券核销的订单信息(订单号、单品信息等)。 + *

+ * 2021-1 微信侧不再返回{@code consume_information}字段 * * @param params the params * @return the wechat response entity diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/RefundGoodsDetail.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/RefundGoodsDetail.java new file mode 100644 index 0000000..48145d9 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/RefundGoodsDetail.java @@ -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; +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/RefundParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/RefundParams.java new file mode 100644 index 0000000..5adb83d --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/RefundParams.java @@ -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; + /** + * 退款资金来源,若传递此参数则使用对应的资金账户退款,否则默认使用未结算资金退款(仅对老资金流商户适用)。 + * 枚举值: + *

    + *
  • AVAILABLE:可用余额账户
  • + *
+ */ + private String fundsAccount; + /** + * 退款订单金额信息 + */ + private RefundAmount amount; + /** + * 退款订单的商品信息 + */ + private List 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; + } + +} \ No newline at end of file diff --git a/payment-spring-boot-starter/pom.xml b/payment-spring-boot-starter/pom.xml index 5cefbb4..0c947c3 100644 --- a/payment-spring-boot-starter/pom.xml +++ b/payment-spring-boot-starter/pom.xml @@ -5,11 +5,11 @@ cn.felord payment-spring-boot - 1.0.5.RELEASE + 1.0.6.RELEASE payment-spring-boot-starter - 1.0.5.RELEASE + 1.0.6.RELEASE jar 4.0.0 diff --git a/pom.xml b/pom.xml index fcda33b..019edda 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> cn.felord payment-spring-boot - 1.0.5.RELEASE + 1.0.6.RELEASE pom 4.0.0 @@ -30,7 +30,7 @@ - payment-spring-boot-1.0.5.RELEASE + payment-spring-boot-1.0.6.RELEASE https://github.com/NotFound403/payment-spring-boot scm:git:https://github.com/NotFound403/payment-spring-boot.git scm:git:https://github.com/NotFound403/payment-spring-boot.git