update 优化请求汇付API

This commit is contained in:
2023-08-11 11:29:43 +08:00
parent 6a2ea94ba4
commit 7e1117f873
3 changed files with 92 additions and 29 deletions

View File

@@ -271,8 +271,7 @@ public class PayController extends BaseController {
} }
/** /**
* 汇付支付退款 * 汇付支付退款/汇付支付余额退款/用户余额退款
* 用户余额退款
* https://api.jsowellcloud.com/uniapp/pay/refundBalance * https://api.jsowellcloud.com/uniapp/pay/refundBalance
*/ */
@PostMapping("/refundBalance") @PostMapping("/refundBalance")

View File

@@ -69,6 +69,12 @@ public class AdapayMemberService {
@Autowired @Autowired
private ClearingBillInfoService clearingBillInfoService; private ClearingBillInfoService clearingBillInfoService;
/**
* 创建结算账户
* @param dto
* @throws BaseAdaPayException
* @throws BusinessException
*/
public void createSettleAccount(SettleAccountDTO dto) throws BaseAdaPayException, BusinessException { public void createSettleAccount(SettleAccountDTO dto) throws BaseAdaPayException, BusinessException {
String bankAcctType = dto.getBankAcctType(); String bankAcctType = dto.getBankAcctType();
if (StringUtils.equals(bankAcctType, Constants.ONE)) { if (StringUtils.equals(bankAcctType, Constants.ONE)) {
@@ -628,4 +634,40 @@ public class AdapayMemberService {
log.info("创建支付确认撤销param:{}, result:{}", JSON.toJSONString(confirmReverseParams), JSON.toJSONString(confirmReverseResult)); log.info("创建支付确认撤销param:{}, result:{}", JSON.toJSONString(confirmReverseParams), JSON.toJSONString(confirmReverseResult));
} }
/**
* 创建退款请求
*/
public void createRefundRequest(String paymentId, String refundAmt) {
// 延迟分账确认的调退款接口
Map<String, Object> refundParams = Maps.newHashMap();
refundParams.put("refund_amt", AdapayUtil.formatAmount(refundAmt));
refundParams.put("refund_order_no", IdUtils.fastSimpleUUID());
refundParams.put("notify_url", ADAPAY_CALLBACK_URL);
try {
Map<String, Object> response = Refund.create(paymentId, refundParams);
log.info("汇付支付创建退款对象:{}", JSON.toJSONString(response));
} catch (BaseAdaPayException e) {
log.error("汇付支付创建退款对象error", e);
}
}
/**
* 创建交易撤销请求
* 延迟分账未确认, 调交易撤销接口退款
*/
public void createPaymentReverseRequest(String paymentId, String reverseAmt) {
// 延迟分账未确认调撤销调撤销接口退款
Map<String, Object> reverseParams = Maps.newHashMap();
reverseParams.put("app_id", ADAPAY_APP_ID);
reverseParams.put("payment_id", paymentId);
reverseParams.put("reverse_amt", AdapayUtil.formatAmount(reverseAmt));
reverseParams.put("order_no", IdUtils.fastSimpleUUID());
reverseParams.put("notify_url", ADAPAY_CALLBACK_URL);
try {
Map<String, Object> paymentReverse = PaymentReverse.create(reverseParams);
log.info("汇付支付创建交易撤销对象:{}", JSON.toJSONString(paymentReverse));
} catch (BaseAdaPayException e) {
log.error("汇付支付创建交易撤销对象error", e);
}
}
} }

View File

@@ -12,8 +12,6 @@ import com.google.common.collect.Sets;
import com.huifu.adapay.core.exception.BaseAdaPayException; import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Payment; import com.huifu.adapay.model.Payment;
import com.huifu.adapay.model.PaymentConfirm; import com.huifu.adapay.model.PaymentConfirm;
import com.huifu.adapay.model.PaymentReverse;
import com.huifu.adapay.model.Refund;
import com.jsowell.adapay.common.CreateAdaPaymentParam; import com.jsowell.adapay.common.CreateAdaPaymentParam;
import com.jsowell.adapay.common.DivMember; import com.jsowell.adapay.common.DivMember;
import com.jsowell.adapay.response.BalancePaymentResponse; import com.jsowell.adapay.response.BalancePaymentResponse;
@@ -1173,9 +1171,8 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
/** /**
* 计算余额扣除金额 * 计算余额扣除金额
*
* @param memberId 会员id * @param memberId 会员id
* @param amount 消费金额 * @param amount 消费金额/退款金额
*/ */
@Override @Override
public List<BalanceDeductionAmountVO> calculateTheBalanceDeductionAmount(String memberId, BigDecimal amount) { public List<BalanceDeductionAmountVO> calculateTheBalanceDeductionAmount(String memberId, BigDecimal amount) {
@@ -2340,30 +2337,32 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
String payMode = "delay"; String payMode = "delay";
if (StringUtils.equals("", payMode)) { if (StringUtils.equals("", payMode)) {
// 延迟分账确认的调退款接口 // 延迟分账确认的调退款接口
Map<String, Object> refundParams = Maps.newHashMap(); adapayMemberService.createRefundRequest(id, amount);
refundParams.put("refund_amt", amount); // Map<String, Object> refundParams = Maps.newHashMap();
refundParams.put("refund_order_no", snowflakeId); // refundParams.put("refund_amt", amount);
refundParams.put("notify_url", ADAPAY_CALLBACK_URL); // refundParams.put("refund_order_no", snowflakeId);
try { // refundParams.put("notify_url", ADAPAY_CALLBACK_URL);
Map<String, Object> response = Refund.create(id, refundParams); // try {
logger.info("汇付支付创建退款对象:{}", JSON.toJSONString(response)); // Map<String, Object> response = Refund.create(id, refundParams);
} catch (BaseAdaPayException e) { // logger.info("汇付支付创建退款对象:{}", JSON.toJSONString(response));
logger.error("汇付支付创建退款对象error", e); // } catch (BaseAdaPayException e) {
} // logger.error("汇付支付创建退款对象error", e);
// }
} else { } else {
// 延迟分账未确认调撤销调撤销接口退款 // 延迟分账未确认调撤销调撤销接口退款
Map<String, Object> reverseParams = Maps.newHashMap(); adapayMemberService.createPaymentReverseRequest(id, amount);
reverseParams.put("app_id", ADAPAY_APP_ID); // Map<String, Object> reverseParams = Maps.newHashMap();
reverseParams.put("payment_id", id); // reverseParams.put("app_id", ADAPAY_APP_ID);
reverseParams.put("reverse_amt", amount); // reverseParams.put("payment_id", id);
reverseParams.put("order_no", snowflakeId); // reverseParams.put("reverse_amt", amount);
reverseParams.put("notify_url", ADAPAY_CALLBACK_URL); // reverseParams.put("order_no", snowflakeId);
try { // reverseParams.put("notify_url", ADAPAY_CALLBACK_URL);
Map<String, Object> paymentReverse = PaymentReverse.create(reverseParams); // try {
logger.info("汇付支付创建交易撤销对象:{}", JSON.toJSONString(paymentReverse)); // Map<String, Object> paymentReverse = PaymentReverse.create(reverseParams);
} catch (BaseAdaPayException e) { // logger.info("汇付支付创建交易撤销对象:{}", JSON.toJSONString(paymentReverse));
logger.error("汇付支付创建交易撤销对象error", e); // } catch (BaseAdaPayException e) {
} // logger.error("汇付支付创建交易撤销对象error", e);
// }
} }
} }
@@ -2374,6 +2373,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
if (memberVO == null) { if (memberVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_MEMBER_NOT_FOUND_ERROR); throw new BusinessException(ReturnCodeEnum.CODE_MEMBER_NOT_FOUND_ERROR);
} }
// 校验退款金额 // 校验退款金额
BigDecimal principalBalance = memberVO.getPrincipalBalance(); BigDecimal principalBalance = memberVO.getPrincipalBalance();
BigDecimal refundAmount = dto.getRefundAmount(); BigDecimal refundAmount = dto.getRefundAmount();
@@ -2382,8 +2382,30 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
} }
// 查询用户充值余额订单 过滤掉已经退款的充值订单 // 查询用户充值余额订单 过滤掉已经退款的充值订单
List<BalanceDeductionAmountVO> list = calculateTheBalanceDeductionAmount(dto.getMemberId(), refundAmount);
for (BalanceDeductionAmountVO vo : list) {
String paymentId = vo.getPaymentId();
BigDecimal deductionAmount = vo.getDeductionAmount();
// 也许需要多笔支付订单才够退款 // 调汇付的交易撤销接口
// adapayMemberService.
// 调汇付的分账接口 确认交易
// PaymentConfirmResponse paymentConfirmResponse = adapayMemberService.createPaymentConfirmRequest(paymentId, adapayMemberAccount, deductionAmount, orderCode);
// if (paymentConfirmResponse != null) {
// confirmAmt = confirmAmt.add(new BigDecimal(paymentConfirmResponse.getConfirmed_amt()));
// feeAmt = feeAmt.add(new BigDecimal(paymentConfirmResponse.getFee_amt()));
// status = paymentConfirmResponse.getStatus();
// description = paymentConfirmResponse.getDescription();
// }
// 更新这笔交易的剩余金额
MemberAdapayRecord record = memberAdapayRecordService.selectByPaymentId(paymentId);
// 更新此笔交易单的消费金额 = 历史消费金额 + 本次消费金额
record.setSpendAmt(record.getSpendAmt().add(deductionAmount));
// 更新此笔交易单的剩余金额 = 支付金额 - 累计退款金额 - 累计消费金额
record.setBalanceAmt(record.getPayAmt().subtract(record.getRefundAmt()).subtract(record.getSpendAmt()));
memberAdapayRecordService.updateByPrimaryKeySelective(record);
}
} }
/** /**