|
|
@@ -3,9 +3,11 @@ package com.izouma.nineth.service;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
|
import com.alipay.api.AlipayClient;
|
|
|
+import com.alipay.api.request.AlipayTradeCancelRequest;
|
|
|
import com.alipay.api.request.AlipayTradePrecreateRequest;
|
|
|
import com.alipay.api.request.AlipayTradeQueryRequest;
|
|
|
import com.alipay.api.request.AlipayTradeRefundRequest;
|
|
|
+import com.alipay.api.response.AlipayTradeCancelResponse;
|
|
|
import com.alipay.api.response.AlipayTradePrecreateResponse;
|
|
|
import com.alipay.api.response.AlipayTradeQueryResponse;
|
|
|
import com.alipay.api.response.AlipayTradeRefundResponse;
|
|
|
@@ -28,7 +30,7 @@ import java.util.Objects;
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
@Slf4j
|
|
|
-public class AlipayService {
|
|
|
+public class AlipayService implements IPayService {
|
|
|
|
|
|
private final AlipayProperties alipayProperties;
|
|
|
private final AlipayClient alipayClient;
|
|
|
@@ -60,7 +62,31 @@ public class AlipayService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void close(String id) {
|
|
|
+ log.info("支付宝关闭订单:{}", id);
|
|
|
+ AlipayTradeCancelRequest request = new AlipayTradeCancelRequest();
|
|
|
+ JSONObject bizContent = new JSONObject();
|
|
|
+ bizContent.put("out_trade_no", id);
|
|
|
+ request.setBizContent(bizContent.toString());
|
|
|
+ AlipayTradeCancelResponse response = null;
|
|
|
+ try {
|
|
|
+ response = alipayClient.execute(request);
|
|
|
+ } catch (AlipayApiException e) {
|
|
|
+ log.error("支付宝关闭订单失败", e);
|
|
|
+ throw new BusinessException("关闭订单失败");
|
|
|
+ }
|
|
|
+ if (response.isSuccess() && "10000".equals(response.getCode())) {
|
|
|
+ log.info("支付宝关闭订单成功 {}", id);
|
|
|
+ } else {
|
|
|
+ log.error("支付宝关闭订单失败 code={} msg={} subMsg={}", response.getCode(), response.getMsg(), response.getSubMsg());
|
|
|
+ throw new BusinessException(response.getMsg() + ";" + response.getSubMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void refund(String orderId, BigDecimal amount) {
|
|
|
+ log.info("支付宝退款开始 orderId={} amount={}", orderId, amount);
|
|
|
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
|
|
JSONObject bizContent = new JSONObject();
|
|
|
bizContent.put("out_trade_no", orderId);
|
|
|
@@ -79,6 +105,7 @@ public class AlipayService {
|
|
|
if (response.isSuccess() && "10000".equals(response.getCode())) {
|
|
|
log.info("支付宝退款成功");
|
|
|
} else {
|
|
|
+ log.error("支付宝退款失败 code={} msg={} subMsg={}", response.getCode(), response.getMsg(), response.getSubMsg());
|
|
|
throw new BusinessException(response.getMsg() + ";" + response.getSubMsg());
|
|
|
}
|
|
|
}
|
|
|
@@ -96,6 +123,7 @@ public class AlipayService {
|
|
|
return null;
|
|
|
}
|
|
|
PayQuery query = new PayQuery(Constants.PayChannel.ALI);
|
|
|
+ query.setPayService(this);
|
|
|
query.setOrderId(orderId);
|
|
|
if (response.isSuccess() && "10000".equals(response.getCode())) {
|
|
|
query.setExist(true);
|