mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 19:15:35 +08:00
update 汇付退款添加merchantKey
This commit is contained in:
@@ -660,7 +660,7 @@ public class AdapayMemberService {
|
||||
* 创建交易撤销请求
|
||||
* 延迟分账未确认, 调交易撤销接口退款
|
||||
*/
|
||||
public PaymentReverseResponse createPaymentReverseRequest(String paymentId, BigDecimal reverseAmt) {
|
||||
public PaymentReverseResponse createPaymentReverseRequest(String paymentId, BigDecimal reverseAmt, String merchantKey) {
|
||||
PaymentReverseResponse response;
|
||||
// 延迟分账未确认调撤销调撤销接口退款
|
||||
Map<String, Object> reverseParams = Maps.newHashMap();
|
||||
@@ -671,7 +671,7 @@ public class AdapayMemberService {
|
||||
reverseParams.put("notify_url", ADAPAY_CALLBACK_URL);
|
||||
Map<String, Object> paymentReverse = null;
|
||||
try {
|
||||
paymentReverse = PaymentReverse.create(reverseParams);
|
||||
paymentReverse = PaymentReverse.create(reverseParams, merchantKey);
|
||||
} catch (BaseAdaPayException e) {
|
||||
log.error("汇付支付创建交易撤销对象error", e);
|
||||
}
|
||||
|
||||
@@ -41,4 +41,9 @@ public class ApplyRefundDTO {
|
||||
* memberId 数组(批量退款)
|
||||
*/
|
||||
private List<String> memberIdList;
|
||||
|
||||
/**
|
||||
* 汇付需要merchantKey,取小程序appId传给它
|
||||
*/
|
||||
private String merchantKey;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public interface PileMerchantInfoMapper {
|
||||
|
||||
/**
|
||||
* 通过ids查询信息列表
|
||||
* @param ids
|
||||
* @param deptIds
|
||||
* @return
|
||||
*/
|
||||
List<PileMerchantInfo> queryInfoListByIds(@Param("deptIds") List<String> deptIds);
|
||||
|
||||
@@ -22,7 +22,9 @@ public interface IPileMerchantInfoService {
|
||||
*/
|
||||
public PileMerchantInfo selectPileMerchantInfoById(Long id);
|
||||
|
||||
/**
|
||||
PileMerchantInfo selectPileMerchantInfoById(String merchantId);
|
||||
|
||||
/**
|
||||
* 查询充电桩运营商信息列表
|
||||
*
|
||||
* @param pileMerchantInfo 充电桩运营商信息
|
||||
|
||||
@@ -927,18 +927,23 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
memberBasicInfoService.updateMemberBalance(updateMemberBalanceDTO);
|
||||
} else if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) { // 微信支付
|
||||
// 微信退款逻辑
|
||||
ApplyRefundDTO weChatRefundDTO = new ApplyRefundDTO();
|
||||
weChatRefundDTO.setOrderCode(orderCode);
|
||||
weChatRefundDTO.setRefundType(Constants.ONE);
|
||||
weChatRefundDTO.setRefundAmount(residue);
|
||||
ApplyRefundDTO applyRefundDTO = new ApplyRefundDTO();
|
||||
applyRefundDTO.setOrderCode(orderCode);
|
||||
applyRefundDTO.setRefundType(Constants.ONE);
|
||||
applyRefundDTO.setRefundAmount(residue);
|
||||
|
||||
// 查到该笔订单付款金额到哪里了
|
||||
MemberTransactionRecord transactionRecord = memberTransactionRecordService.selectByOrderCode(orderCode, ActionTypeEnum.FORWARD.getValue());
|
||||
logger.info("查到该笔订单付款金额到哪里了:{}", JSON.toJSONString(transactionRecord));
|
||||
if (StringUtils.equals(transactionRecord.getPaymentInstitutions(), PaymentInstitutionsEnum.WECHAT_PAY.getValue())) {
|
||||
this.weChatRefund(weChatRefundDTO);
|
||||
this.weChatRefund(applyRefundDTO);
|
||||
} else if (StringUtils.equals(transactionRecord.getPaymentInstitutions(), PaymentInstitutionsEnum.ADAPAY.getValue())) {
|
||||
this.refundOrderWithAdapay(weChatRefundDTO);
|
||||
// 汇付退款需要一级运营商的小程序appId, 否则会退款失败
|
||||
PileMerchantInfo pileMerchantInfo = pileMerchantInfoService.selectPileMerchantInfoById(orderBasicInfo.getMerchantId());
|
||||
if (pileMerchantInfo != null) {
|
||||
applyRefundDTO.setMerchantKey(pileMerchantInfo.getAppId());
|
||||
}
|
||||
this.refundOrderWithAdapay(applyRefundDTO);
|
||||
}
|
||||
// 订单支付记录
|
||||
OrderPayRecord orderPayRecord = payRecordList.get(0);
|
||||
@@ -2388,7 +2393,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
adapayMemberService.createRefundRequest(paymentId, refundAmount);
|
||||
} else {
|
||||
// 延迟分账未确认调撤销调撤销接口退款
|
||||
PaymentReverseResponse response = adapayMemberService.createPaymentReverseRequest(paymentId, refundAmount);
|
||||
PaymentReverseResponse response = adapayMemberService.createPaymentReverseRequest(paymentId, refundAmount, dto.getMerchantKey());
|
||||
if (response != null) {
|
||||
MemberAdapayRecord record = memberAdapayRecordService.selectByPaymentId(paymentId);
|
||||
BigDecimal reverseAmt = new BigDecimal(response.getReverse_amt());
|
||||
@@ -2431,7 +2436,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
BigDecimal deductionAmount = vo.getDeductionAmount();
|
||||
|
||||
// 调汇付的交易撤销接口
|
||||
adapayMemberService.createPaymentReverseRequest(paymentId, deductionAmount);
|
||||
adapayMemberService.createPaymentReverseRequest(paymentId, deductionAmount, dto.getMerchantKey());
|
||||
|
||||
// 更新这笔交易的剩余金额
|
||||
MemberAdapayRecord record = memberAdapayRecordService.selectByPaymentId(paymentId);
|
||||
@@ -2692,6 +2697,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
weChatRefundDTO = new ApplyRefundDTO();
|
||||
weChatRefundDTO.setOrderCode(refundOrder.getOrderCode());
|
||||
weChatRefundDTO.setRefundAmount(new BigDecimal(refundOrder.getRefundAmount()));
|
||||
// TODO 2023年8月17日这个接口不能用了,需要给DTO设置merchantKey
|
||||
this.refundOrderWithAdapay(weChatRefundDTO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 充电桩运营商信息Service业务层处理
|
||||
@@ -56,6 +57,11 @@ public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService {
|
||||
return pileMerchantInfoMapper.selectPileMerchantInfoById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PileMerchantInfo selectPileMerchantInfoById(String merchantId) {
|
||||
return selectPileMerchantInfoById(Long.parseLong(merchantId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询充电桩运营商信息列表
|
||||
* 带权限校验
|
||||
@@ -334,4 +340,42 @@ public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService {
|
||||
public List<PileMerchantInfo> queryFirstLevelMerchant() {
|
||||
return pileMerchantInfoMapper.queryFirstLevelMerchant();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过merchantId查询appId
|
||||
*/
|
||||
public String queryAppIdByMerchantId(String merchantId) {
|
||||
/*
|
||||
一般情况下新建的运营商appId都是有值的,某些早前建的运营商appId可能为空
|
||||
一级运营商就是自己的appId, 二级运营商使用一级运营商的appId
|
||||
*/
|
||||
PileMerchantInfo pileMerchantInfo = selectPileMerchantInfoById(Long.parseLong(merchantId));
|
||||
if (pileMerchantInfo == null) {
|
||||
return null;
|
||||
}
|
||||
String appId = pileMerchantInfo.getAppId();
|
||||
if (StringUtils.isNotBlank(appId)) {
|
||||
return appId;
|
||||
}
|
||||
// 如果appId为空,则查询父级(一级运营商的appId)
|
||||
PileMerchantInfo parent = selectPileMerchantInfoById(Long.parseLong(pileMerchantInfo.getParentId()));
|
||||
if (parent == null) {
|
||||
return null;
|
||||
}
|
||||
appId = parent.getAppId();
|
||||
if (StringUtils.isNotBlank(appId)) {
|
||||
// 异步方法 把appId更新到二级运营商
|
||||
String finalAppId = appId;
|
||||
CompletableFuture.runAsync(() -> {
|
||||
PileMerchantInfo update = new PileMerchantInfo();
|
||||
update.setId(Long.parseLong(merchantId));
|
||||
update.setAppId(finalAppId);
|
||||
updatePileMerchantInfo(update);
|
||||
});
|
||||
return appId;
|
||||
}
|
||||
return appId;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user