mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
update 优化请求汇付API
This commit is contained in:
@@ -69,6 +69,12 @@ public class AdapayMemberService {
|
||||
@Autowired
|
||||
private ClearingBillInfoService clearingBillInfoService;
|
||||
|
||||
/**
|
||||
* 创建结算账户
|
||||
* @param dto
|
||||
* @throws BaseAdaPayException
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public void createSettleAccount(SettleAccountDTO dto) throws BaseAdaPayException, BusinessException {
|
||||
String bankAcctType = dto.getBankAcctType();
|
||||
if (StringUtils.equals(bankAcctType, Constants.ONE)) {
|
||||
@@ -628,4 +634,40 @@ public class AdapayMemberService {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ 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.huifu.adapay.model.Refund;
|
||||
import com.jsowell.adapay.common.CreateAdaPaymentParam;
|
||||
import com.jsowell.adapay.common.DivMember;
|
||||
import com.jsowell.adapay.response.BalancePaymentResponse;
|
||||
@@ -1173,9 +1171,8 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
|
||||
/**
|
||||
* 计算余额扣除金额
|
||||
*
|
||||
* @param memberId 会员id
|
||||
* @param amount 消费金额
|
||||
* @param amount 消费金额/退款金额
|
||||
*/
|
||||
@Override
|
||||
public List<BalanceDeductionAmountVO> calculateTheBalanceDeductionAmount(String memberId, BigDecimal amount) {
|
||||
@@ -2340,30 +2337,32 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
String payMode = "delay";
|
||||
if (StringUtils.equals("", payMode)) {
|
||||
// 延迟分账确认的调退款接口
|
||||
Map<String, Object> refundParams = Maps.newHashMap();
|
||||
refundParams.put("refund_amt", amount);
|
||||
refundParams.put("refund_order_no", snowflakeId);
|
||||
refundParams.put("notify_url", ADAPAY_CALLBACK_URL);
|
||||
try {
|
||||
Map<String, Object> response = Refund.create(id, refundParams);
|
||||
logger.info("汇付支付创建退款对象:{}", JSON.toJSONString(response));
|
||||
} catch (BaseAdaPayException e) {
|
||||
logger.error("汇付支付创建退款对象error", e);
|
||||
}
|
||||
adapayMemberService.createRefundRequest(id, amount);
|
||||
// Map<String, Object> refundParams = Maps.newHashMap();
|
||||
// refundParams.put("refund_amt", amount);
|
||||
// refundParams.put("refund_order_no", snowflakeId);
|
||||
// refundParams.put("notify_url", ADAPAY_CALLBACK_URL);
|
||||
// try {
|
||||
// Map<String, Object> response = Refund.create(id, refundParams);
|
||||
// logger.info("汇付支付创建退款对象:{}", JSON.toJSONString(response));
|
||||
// } catch (BaseAdaPayException e) {
|
||||
// logger.error("汇付支付创建退款对象error", e);
|
||||
// }
|
||||
} else {
|
||||
// 延迟分账未确认调撤销调撤销接口退款
|
||||
Map<String, Object> reverseParams = Maps.newHashMap();
|
||||
reverseParams.put("app_id", ADAPAY_APP_ID);
|
||||
reverseParams.put("payment_id", id);
|
||||
reverseParams.put("reverse_amt", amount);
|
||||
reverseParams.put("order_no", snowflakeId);
|
||||
reverseParams.put("notify_url", ADAPAY_CALLBACK_URL);
|
||||
try {
|
||||
Map<String, Object> paymentReverse = PaymentReverse.create(reverseParams);
|
||||
logger.info("汇付支付创建交易撤销对象:{}", JSON.toJSONString(paymentReverse));
|
||||
} catch (BaseAdaPayException e) {
|
||||
logger.error("汇付支付创建交易撤销对象error", e);
|
||||
}
|
||||
adapayMemberService.createPaymentReverseRequest(id, amount);
|
||||
// Map<String, Object> reverseParams = Maps.newHashMap();
|
||||
// reverseParams.put("app_id", ADAPAY_APP_ID);
|
||||
// reverseParams.put("payment_id", id);
|
||||
// reverseParams.put("reverse_amt", amount);
|
||||
// reverseParams.put("order_no", snowflakeId);
|
||||
// reverseParams.put("notify_url", ADAPAY_CALLBACK_URL);
|
||||
// try {
|
||||
// Map<String, Object> paymentReverse = PaymentReverse.create(reverseParams);
|
||||
// logger.info("汇付支付创建交易撤销对象:{}", JSON.toJSONString(paymentReverse));
|
||||
// } catch (BaseAdaPayException e) {
|
||||
// logger.error("汇付支付创建交易撤销对象error", e);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2374,6 +2373,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
if (memberVO == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_MEMBER_NOT_FOUND_ERROR);
|
||||
}
|
||||
|
||||
// 校验退款金额
|
||||
BigDecimal principalBalance = memberVO.getPrincipalBalance();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user