update 实时分账

This commit is contained in:
2023-08-25 16:07:15 +08:00
parent 18548fb83d
commit 033ddb40e7
8 changed files with 141 additions and 44 deletions

View File

@@ -99,15 +99,12 @@ public class AdapayService {
if (memberBasicInfo == null) {
throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
}
String openId =memberBasicInfo.getOpenId();
// String openId = wxAppletRemoteService.getOpenIdByCode(dto.getCode());
// if (StringUtils.isBlank(openId)) {
// throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
// }
String openId = memberBasicInfo.getOpenId();
// 封装对象
String amount = AdapayUtil.formatAmount(dto.getPayAmount()); // 用户支付金额
String payMode = Constants.ADAPAY_PAY_MODE_DELAY; // 汇付延时分账
// String payMode = Constants.ADAPAY_PAY_MODE_DELAY; // 汇付延时分账
String payMode = pileMerchantInfoService.getDelayModeByWechatAppId(dto.getWechatAppId());
CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam();
createAdaPaymentParam.setOrder_no(dto.getOrderCode());
createAdaPaymentParam.setPay_amt(amount);
@@ -126,14 +123,17 @@ public class AdapayService {
createAdaPaymentParam.setExpend(JSONObject.toJSONString(ImmutableMap.of("open_id", openId)));
// 延时分账
createAdaPaymentParam.setPay_mode(payMode);
if (StringUtils.isNotBlank(payMode)) {
createAdaPaymentParam.setPay_mode(payMode);
}
try {
log.info("创建汇付支付参数:{}", JSONObject.toJSONString(createAdaPaymentParam));
Map<String, Object> response = Payment.create(BeanMap.create(createAdaPaymentParam), config.getWechatAppId());
if (response != null && !response.isEmpty()) {
JSONObject expend = JSONObject.parseObject(response.get("expend").toString());
JSONObject pay_info = expend.getJSONObject("pay_info");
Map<String, Object> resultMap = JSONObject.parseObject(pay_info.toJSONString(), new TypeReference<Map<String, Object>>() {});
Map<String, Object> resultMap = JSONObject.parseObject(pay_info.toJSONString(), new TypeReference<Map<String, Object>>() {
});
if (resultMap != null) {
// 请求参数放入缓存15分钟以内返回同一个支付参数
redisCache.setCacheObject(redisKey, resultMap, 15, TimeUnit.MINUTES);
@@ -666,7 +666,7 @@ public class AdapayService {
// 发送提现申请
Map<String, Object> settleCountParams = Maps.newHashMap();
String orderNo = "drawcash_" + dto.getMerchantId() + "_" +System.currentTimeMillis();
String orderNo = "drawcash_" + dto.getMerchantId() + "_" + System.currentTimeMillis();
settleCountParams.put("order_no", orderNo);
settleCountParams.put("cash_amt", AdapayUtil.formatAmount(cashAmt));
settleCountParams.put("member_id", adapayAccountBalanceVO.getAdapayMemberId());
@@ -710,6 +710,7 @@ public class AdapayService {
/**
* 查询取现对象
*
* @param orderNo 请求订单号
*/
public DrawCashDetailVO queryDrawCashDetail(String orderNo, String wechatAppId) throws BaseAdaPayException {
@@ -877,15 +878,30 @@ public class AdapayService {
/**
* 创建退款请求
*/
public RefundResponse createRefundRequest(String paymentId, BigDecimal refundAmt) {
// 延迟分账确认的调退款接口
public RefundResponse createRefundRequest(String paymentId, BigDecimal refundAmt, String wechatAppId, String memberId, String scenarioType, String orderCode) {
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
// 实时分账的调退款接口
Map<String, Object> refundParams = Maps.newHashMap();
refundParams.put("refund_amt", AdapayUtil.formatAmount(refundAmt));
refundParams.put("refund_order_no", IdUtils.fastSimpleUUID());
// expand 为扩展域
Map<String, String> expendMap = Maps.newHashMap();
expendMap.put("memberId", memberId);
expendMap.put("scenarioType", scenarioType);
if (StringUtils.isNotBlank(orderCode)) {
expendMap.put("orderCode", orderCode);
}
refundParams.put("expand", expendMap);
refundParams.put("reason", expendMap);
refundParams.put("notify_url", ADAPAY_CALLBACK_URL);
Map<String, Object> resultResponse = null;
try {
resultResponse = Refund.create(paymentId, refundParams);
resultResponse = Refund.create(paymentId, refundParams, config.getWechatAppId());
} catch (BaseAdaPayException e) {
log.error("汇付支付创建退款对象error", e);
}
@@ -897,10 +913,10 @@ public class AdapayService {
/**
* 创建交易撤销请求
* 延迟分账未确认, 调交易撤销接口退款
*
* @param wechatAppId 微信小程序appId
*/
public PaymentReverseResponse createPaymentReverseRequest(String paymentId, BigDecimal reverseAmt, String wechatAppId, String memberId, String scenarioType, String orderCode) {
PaymentReverseResponse response;
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);