汇付支付 执行退款

This commit is contained in:
2023-05-27 16:01:27 +08:00
parent 35413920d3
commit 6cba1f84c5
9 changed files with 83 additions and 7 deletions

View File

@@ -13,6 +13,8 @@ public interface AdapayCallbackRecordMapper {
AdapayCallbackRecord selectByPrimaryKey(Integer id);
AdapayCallbackRecord selectByOrderCode(String orderCode);
int updateByPrimaryKeySelective(AdapayCallbackRecord record);
int updateByPrimaryKey(AdapayCallbackRecord record);

View File

@@ -4,4 +4,6 @@ import com.jsowell.pile.domain.AdapayCallbackRecord;
public interface AdapayCallbackRecordService {
void saveAdapayCallbackRecord(AdapayCallbackRecord callbackRecord);
AdapayCallbackRecord selectByOrderCode(String orderCode);
}

View File

@@ -1,5 +1,6 @@
package com.jsowell.pile.service;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
import com.jsowell.pile.domain.OrderBasicInfo;
@@ -261,7 +262,7 @@ public interface IOrderBasicInfoService {
* 汇付支付 订单退款
* @param dto
*/
void refundForOrderWithAdapay(WeChatRefundDTO dto);
void refundForOrderWithAdapay(WeChatRefundDTO dto) throws BaseAdaPayException;
/**
* 汇付支付 余额退款

View File

@@ -3,9 +3,11 @@ package com.jsowell.pile.service.impl;
import com.jsowell.pile.domain.AdapayCallbackRecord;
import com.jsowell.pile.mapper.AdapayCallbackRecordMapper;
import com.jsowell.pile.service.AdapayCallbackRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class AdapayCallbackRecordServiceImpl implements AdapayCallbackRecordService {
@@ -16,4 +18,15 @@ public class AdapayCallbackRecordServiceImpl implements AdapayCallbackRecordServ
public void saveAdapayCallbackRecord(AdapayCallbackRecord callbackRecord) {
adapayCallbackRecordMapper.insert(callbackRecord);
}
@Override
public AdapayCallbackRecord selectByOrderCode(String orderCode) {
AdapayCallbackRecord record = null;
try {
record = adapayCallbackRecordMapper.selectByOrderCode(orderCode);
} catch (Exception e) {
log.error("查询汇付支付回调记录失败", e);
}
return record;
}
}

View File

@@ -2,11 +2,14 @@ package com.jsowell.pile.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Refund;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
@@ -16,6 +19,7 @@ import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.MemberWalletEnum;
import com.jsowell.common.enums.ykc.*;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.AdapayUtil;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.SecurityUtils;
import com.jsowell.common.util.StringUtils;
@@ -87,6 +91,9 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
@Autowired
private WxpayCallbackRecordService wxpayCallbackRecordService;
@Autowired
private AdapayCallbackRecordService adapayCallbackRecordService;
@Autowired
private WechatPayService wechatPayService;
@@ -1729,13 +1736,34 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
}
@Override
public void refundForOrderWithAdapay(WeChatRefundDTO dto) {
public void refundForOrderWithAdapay(WeChatRefundDTO dto) throws BaseAdaPayException {
// 查出来原来的支付信息
AdapayCallbackRecord record = adapayCallbackRecordService.selectByOrderCode(dto.getOrderCode());
if (Objects.isNull(record)) {
logger.error("orderCode:{}, 订单退款处理逻辑, 查询订单微信支付记录为空!", dto.getOrderCode());
throw new BusinessException(ReturnCodeEnum.CODE_REFUND_ORDER_CALLBACK_RECORD_ERROR);
}
// 判断支付金额和退款金额
BigDecimal refundAmount = dto.getRefundAmount();
BigDecimal payAmt = record.getPayAmt();
if (refundAmount.compareTo(payAmt) > 0) {
logger.error("订单号:{}, 退款金额:{}(元),大于可退金额{}(元), 抛出异常", dto.getOrderCode(), refundAmount, payAmt);
throw new BusinessException(ReturnCodeEnum.CODE_REFUND_ORDER_AMOUNT_ERROR);
}
// 创建汇付退款对象
// 创建汇付退款对象 在完成初始化设置情况下,调用方法,获取 Refund对象
String id = record.getPaymentId();
Map<String, Object> refundParams = Maps.newHashMap();
refundParams.put("refund_amt", AdapayUtil.formatAmount(dto.getRefundAmount()));
refundParams.put("refund_order_no", SnowflakeIdWorker.getSnowflakeId());
Map<String, Object> response = Refund.create(id, refundParams);
logger.info("创建退款对象:{}", JSON.toJSONString(response));
if (response != null && !response.isEmpty()) {
JSONObject jsonObject = JSONObject.parseObject(response.get("expend").toString());
JSONObject pay_info = jsonObject.getJSONObject("pay_info");
Map<String, Object> resultMap = JSONObject.parseObject(pay_info.toJSONString(), new TypeReference<Map<String, Object>>() {});
}
}
@Override