feat: 退款功能
This commit is contained in:
@@ -22,7 +22,6 @@ import com.alipay.api.domain.AlipayTradeOrderSettleModel;
|
|||||||
import com.alipay.api.domain.AlipayTradePayModel;
|
import com.alipay.api.domain.AlipayTradePayModel;
|
||||||
import com.alipay.api.domain.AlipayTradePrecreateModel;
|
import com.alipay.api.domain.AlipayTradePrecreateModel;
|
||||||
import com.alipay.api.domain.AlipayTradeQueryModel;
|
import com.alipay.api.domain.AlipayTradeQueryModel;
|
||||||
import com.alipay.api.domain.AlipayTradeRefundModel;
|
|
||||||
import com.alipay.api.domain.Participant;
|
import com.alipay.api.domain.Participant;
|
||||||
import com.alipay.api.internal.util.AlipaySignature;
|
import com.alipay.api.internal.util.AlipaySignature;
|
||||||
import com.alipay.api.response.AlipayFundAuthOrderFreezeResponse;
|
import com.alipay.api.response.AlipayFundAuthOrderFreezeResponse;
|
||||||
@@ -386,23 +385,9 @@ public class AliPayController extends AbstractAliPayApiController {
|
|||||||
* 退款
|
* 退款
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = "/tradeRefund")
|
@PostMapping(value = "/tradeRefund")
|
||||||
public String tradeRefund(@RequestParam(required = false, name = "outTradeNo") String outTradeNo, @RequestParam(required = false, name = "tradeNo") String tradeNo) {
|
public String tradeRefund(@RequestParam Long orderId) {
|
||||||
|
|
||||||
try {
|
return aliPayService.tradeRefund(orderId);
|
||||||
AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
|
||||||
if (StringUtils.isNotEmpty(outTradeNo)) {
|
|
||||||
model.setOutTradeNo(outTradeNo);
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotEmpty(tradeNo)) {
|
|
||||||
model.setTradeNo(tradeNo);
|
|
||||||
}
|
|
||||||
model.setRefundAmount("0.01");
|
|
||||||
model.setRefundReason("正常退款");
|
|
||||||
return AliPayApi.tradeRefundToResponse(model).getBody();
|
|
||||||
} catch (AlipayApiException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,4 +15,6 @@ public interface IAliPayService {
|
|||||||
void wapPay(HttpServletResponse response, Long orderId, String returnUrl, String notifyUrl);
|
void wapPay(HttpServletResponse response, Long orderId, String returnUrl, String notifyUrl);
|
||||||
|
|
||||||
String notifyUrl(HttpServletRequest request, String publicKey);
|
String notifyUrl(HttpServletRequest request, String publicKey);
|
||||||
|
|
||||||
|
String tradeRefund(Long orderId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package org.wfc.payment.pay.alipay.service.impl;
|
package org.wfc.payment.pay.alipay.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alipay.api.AlipayApiException;
|
import com.alipay.api.AlipayApiException;
|
||||||
import com.alipay.api.domain.AlipayTradePagePayModel;
|
import com.alipay.api.domain.AlipayTradePagePayModel;
|
||||||
|
import com.alipay.api.domain.AlipayTradeRefundModel;
|
||||||
import com.alipay.api.domain.AlipayTradeWapPayModel;
|
import com.alipay.api.domain.AlipayTradeWapPayModel;
|
||||||
import com.alipay.api.internal.util.AlipaySignature;
|
import com.alipay.api.internal.util.AlipaySignature;
|
||||||
import com.ijpay.alipay.AliPayApi;
|
import com.ijpay.alipay.AliPayApi;
|
||||||
@@ -33,12 +36,10 @@ public class AliPayServiceImpl implements IAliPayService {
|
|||||||
@Override
|
@Override
|
||||||
public void pcPay(HttpServletResponse response, Long orderId, String returnUrl, String notifyUrl) {
|
public void pcPay(HttpServletResponse response, Long orderId, String returnUrl, String notifyUrl) {
|
||||||
try {
|
try {
|
||||||
R<UOrderVo> orderRes = remoteUUserService.getOrderById(orderId);
|
String totalAmount = getAmountByOrder(orderId);
|
||||||
UOrderVo orderVo = orderRes.getData();
|
if (StrUtil.isBlank(totalAmount)) {
|
||||||
if (orderVo == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String totalAmount = orderVo.getOrderAmount().setScale(2, RoundingMode.HALF_UP).toString();
|
|
||||||
log.info("pc outTradeNo>" + orderId);
|
log.info("pc outTradeNo>" + orderId);
|
||||||
|
|
||||||
AlipayTradePagePayModel model = new AlipayTradePagePayModel();
|
AlipayTradePagePayModel model = new AlipayTradePagePayModel();
|
||||||
@@ -56,14 +57,21 @@ public class AliPayServiceImpl implements IAliPayService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private String getAmountByOrder(Long orderId) {
|
||||||
public void wapPay(HttpServletResponse response, Long orderId, String returnUrl, String notifyUrl) {
|
|
||||||
R<UOrderVo> orderRes = remoteUUserService.getOrderById(orderId);
|
R<UOrderVo> orderRes = remoteUUserService.getOrderById(orderId);
|
||||||
UOrderVo orderVo = orderRes.getData();
|
UOrderVo orderVo = orderRes.getData();
|
||||||
if (orderVo == null) {
|
if (orderVo == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return orderVo.getOrderAmount().setScale(2, RoundingMode.HALF_UP).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void wapPay(HttpServletResponse response, Long orderId, String returnUrl, String notifyUrl) {
|
||||||
|
String totalAmount = getAmountByOrder(orderId);
|
||||||
|
if (StrUtil.isBlank(totalAmount)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String totalAmount = orderVo.getOrderAmount().setScale(2, RoundingMode.HALF_UP).toString();
|
|
||||||
|
|
||||||
String body = "WANFI WAP PAY";
|
String body = "WANFI WAP PAY";
|
||||||
String subject = "WANFI PAY";
|
String subject = "WANFI PAY";
|
||||||
@@ -108,4 +116,25 @@ public class AliPayServiceImpl implements IAliPayService {
|
|||||||
return "failure";
|
return "failure";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String tradeRefund(Long orderId) {
|
||||||
|
try {
|
||||||
|
String totalAmount = getAmountByOrder(orderId);
|
||||||
|
if (StrUtil.isBlank(totalAmount)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
||||||
|
if (ObjectUtil.isNotNull(orderId)) {
|
||||||
|
model.setOutTradeNo(orderId.toString());
|
||||||
|
}
|
||||||
|
model.setRefundAmount(totalAmount);
|
||||||
|
model.setRefundReason("normal refund");
|
||||||
|
return AliPayApi.tradeRefundToResponse(model).getBody();
|
||||||
|
} catch (AlipayApiException e) {
|
||||||
|
log.error("alipay refund error", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user