|
@@ -17,11 +17,14 @@ import com.alipay.api.AlipayApiException;
|
|
|
import com.alipay.api.AlipayConfig;
|
|
|
import com.alipay.api.AlipayResponse;
|
|
|
import com.alipay.api.DefaultAlipayClient;
|
|
|
+import com.alipay.api.domain.AlipayTradeFastpayRefundQueryModel;
|
|
|
import com.alipay.api.domain.AlipayTradeQueryModel;
|
|
|
import com.alipay.api.domain.AlipayTradeRefundModel;
|
|
|
import com.alipay.api.internal.util.AlipaySignature;
|
|
|
+import com.alipay.api.request.AlipayTradeFastpayRefundQueryRequest;
|
|
|
import com.alipay.api.request.AlipayTradeQueryRequest;
|
|
|
import com.alipay.api.request.AlipayTradeRefundRequest;
|
|
|
+import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
|
|
|
import com.alipay.api.response.AlipayTradeQueryResponse;
|
|
|
import com.alipay.api.response.AlipayTradeRefundResponse;
|
|
|
import lombok.SneakyThrows;
|
|
@@ -29,6 +32,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.function.Supplier;
|
|
@@ -102,7 +106,7 @@ public abstract class AbstractAlipayPayClient extends AbstractPayClient<AlipayPa
|
|
|
|
|
|
// 2.1 执行请求
|
|
|
AlipayTradeQueryResponse response = client.execute(request);
|
|
|
- if (!response.isSuccess()) {
|
|
|
+ if (!response.isSuccess()) { // 不成功,例如说订单不存在
|
|
|
return PayOrderRespDTO.closedOf(response.getSubCode(), response.getSubMsg(),
|
|
|
outTradeNo, response);
|
|
|
}
|
|
@@ -142,16 +146,15 @@ public abstract class AbstractAlipayPayClient extends AbstractPayClient<AlipayPa
|
|
|
request.setBizModel(model);
|
|
|
|
|
|
// 2.1 执行请求
|
|
|
- AlipayTradeRefundResponse response = client.execute(request);
|
|
|
+ AlipayTradeRefundResponse response = client.execute(request);
|
|
|
+ if (!response.isSuccess()) {
|
|
|
+ return PayRefundRespDTO.failureOf(reqDTO.getOutRefundNo(), response);
|
|
|
+ }
|
|
|
// 2.2 创建返回结果
|
|
|
// 支付宝只要退款调用返回 success,就认为退款成功,不需要回调。具体可见 parseNotify 方法的说明。
|
|
|
// 另外,支付宝没有退款单号,所以不用设置
|
|
|
- if (response.isSuccess()) {
|
|
|
- return PayRefundRespDTO.successOf(null, LocalDateTimeUtil.of(response.getGmtRefundPay()),
|
|
|
- reqDTO.getOutRefundNo(), response);
|
|
|
- } else {
|
|
|
- return PayRefundRespDTO.failureOf(reqDTO.getOutRefundNo(), response);
|
|
|
- }
|
|
|
+ return PayRefundRespDTO.successOf(null, LocalDateTimeUtil.of(response.getGmtRefundPay()),
|
|
|
+ reqDTO.getOutRefundNo(), response);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -164,6 +167,35 @@ public abstract class AbstractAlipayPayClient extends AbstractPayClient<AlipayPa
|
|
|
throw new UnsupportedOperationException("支付宝无退款回调");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ protected PayRefundRespDTO doGetRefund(String outTradeNo, String outRefundNo) throws AlipayApiException {
|
|
|
+ // 1.1 构建 AlipayTradeFastpayRefundQueryModel 请求
|
|
|
+ AlipayTradeFastpayRefundQueryModel model = new AlipayTradeFastpayRefundQueryModel();
|
|
|
+ model.setOutTradeNo(outTradeNo);
|
|
|
+ model.setOutRequestNo(outRefundNo);
|
|
|
+ model.setQueryOptions(Collections.singletonList("gmt_refund_pay"));
|
|
|
+ // 1.2 构建 AlipayTradeFastpayRefundQueryRequest 请求
|
|
|
+ AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest();
|
|
|
+ request.setBizModel(model);
|
|
|
+
|
|
|
+ // 2.1 执行请求
|
|
|
+ AlipayTradeFastpayRefundQueryResponse response = client.execute(request);
|
|
|
+ if (!response.isSuccess()) {
|
|
|
+ // 明确不存在的情况,应该就是失败,可进行关闭
|
|
|
+ if (ObjectUtils.equalsAny(response.getSubCode(), "TRADE_NOT_EXIST", "ACQ.TRADE_NOT_EXIST")) {
|
|
|
+ return PayRefundRespDTO.failureOf(outRefundNo, response);
|
|
|
+ }
|
|
|
+ // 可能存在“ACQ.SYSTEM_ERROR”系统错误等情况,所以返回 WAIT 继续等待
|
|
|
+ return PayRefundRespDTO.waitingOf(null, outRefundNo, response);
|
|
|
+ }
|
|
|
+ // 2.2 创建返回结果
|
|
|
+ if (Objects.equals(response.getRefundStatus(), "REFUND_SUCCESS")) {
|
|
|
+ return PayRefundRespDTO.successOf(null, LocalDateTimeUtil.of(response.getGmtRefundPay()),
|
|
|
+ outRefundNo, response);
|
|
|
+ }
|
|
|
+ return PayRefundRespDTO.waitingOf(null, outRefundNo, response);
|
|
|
+ }
|
|
|
+
|
|
|
// ========== 各种工具方法 ==========
|
|
|
|
|
|
protected String formatAmount(Integer amount) {
|