update 重试订单退款接口

This commit is contained in:
2023-08-17 14:25:45 +08:00
parent 9a9f0b9d16
commit 999b7a704c
6 changed files with 89 additions and 1 deletions

View File

@@ -290,4 +290,24 @@ public class TempController extends BaseController {
}
return response;
}
/**
* 重试订单退款接口
* http://localhost:8080/temp/retryRefundOrder
*/
@PostMapping("/retryRefundOrder")
public RestApiResponse<?> retryRefundOrder(@RequestBody ApplyRefundDTO dto) {
RestApiResponse<?> response;
try {
orderBasicInfoService.retryRefundOrder(dto.getOrderCode());
response = new RestApiResponse<>();
} catch (BusinessException e) {
logger.error("重试订单退款接口 error,", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) {
logger.error("重试订单退款接口 error,", e);
response = new RestApiResponse<>(e);
}
return response;
}
}

View File

@@ -695,4 +695,23 @@ public class AdapayMemberService {
log.info("汇付支付创建交易撤销对象param:{}, result:{}", JSON.toJSONString(reverseParams), jsonString);
return JSONObject.parseObject(jsonString, PaymentReverseResponse.class);
}
/**
* 查询支付撤销对象
*
* @return
*/
public List<PaymentReverse> queryPaymentReverse(String paymentId, String wechatAppId) throws BaseAdaPayException {
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
Map<String, Object> reverse = Maps.newHashMap();
reverse.put("payment_id", paymentId);
reverse.put("app_id", config.getAdapayAppId());
Map<String, Object> response = PaymentReverse.queryList(reverse, config.getWechatAppId());
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
List<PaymentReverse> payment_reverses = jsonObject.getList("payment_reverses", PaymentReverse.class);
return payment_reverses;
}
}

View File

@@ -335,4 +335,10 @@ public interface IOrderBasicInfoService {
* 2. 发送启动充电指令
*/
void payOrderSuccessCallback(PayOrderSuccessCallbackDTO dto);
/**
* 重试订单退款
* @param orderCode 订单编号
*/
void retryRefundOrder(String orderCode) throws BaseAdaPayException;
}

View File

@@ -96,4 +96,6 @@ public interface IPileMerchantInfoService {
* @return
*/
List<PileMerchantInfo> queryFirstLevelMerchant();
String queryAppIdByMerchantId(String merchantId);
}

View File

@@ -12,6 +12,7 @@ import com.google.common.collect.Sets;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Payment;
import com.huifu.adapay.model.PaymentConfirm;
import com.huifu.adapay.model.PaymentReverse;
import com.jsowell.adapay.common.CreateAdaPaymentParam;
import com.jsowell.adapay.common.DivMember;
import com.jsowell.adapay.config.AbstractAdapayConfig;
@@ -2412,7 +2413,6 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
}
memberAdapayRecordService.updateByPrimaryKeySelective(record);
}
}
}
@@ -2766,6 +2766,46 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
}
@Override
public void retryRefundOrder(String orderCode) throws BaseAdaPayException {
// 查询订单信息
OrderBasicInfo orderBasicInfo = getOrderInfoByOrderCode(orderCode);
if (orderBasicInfo == null) {
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_INFO_IS_NULL);
}
// 如果该订单是订单完成状态,并且是微信支付 存在需要退款金额,则进行后续操作
String orderStatus = orderBasicInfo.getOrderStatus();
if (StringUtils.equals(orderStatus, OrderStatusEnum.ORDER_COMPLETE.getValue())) {
throw new BusinessException("", "订单不是完成状态");
}
String payMode = orderBasicInfo.getPayMode();
if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) {
throw new BusinessException("", "订单不是微信支付");
}
// 查到原汇付支付id
AdapayCallbackRecord adapayCallbackRecord = adapayCallbackRecordService.selectByOrderCode(orderCode);
if (adapayCallbackRecord == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CALLBACK_IS_NULL_ERROR);
}
// 获取appId
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(orderBasicInfo.getMerchantId());
// 通过支付id查询退款记录
String paymentId = adapayCallbackRecord.getPaymentId();
String memberId = orderBasicInfo.getMemberId();
BigDecimal refundAmount = orderBasicInfo.getRefundAmount();
List<PaymentReverse> paymentReverses = adapayMemberService.queryPaymentReverse(paymentId, wechatAppId);
if (CollectionUtils.isEmpty(paymentReverses)) {
// 如果没有退款过,重新执行一遍退款
PaymentReverseResponse response = adapayMemberService.createPaymentReverseRequest(
paymentId, refundAmount, wechatAppId, memberId, ScenarioEnum.ORDER.getValue(),
orderCode);
}
}
/**
* 使用汇付支付
*

View File

@@ -344,6 +344,7 @@ public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService {
/**
* 通过merchantId查询appId
*/
@Override
public String queryAppIdByMerchantId(String merchantId) {
/*
一般情况下新建的运营商appId都是有值的某些早前建的运营商appId可能为空