mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
优化订单退款逻辑
This commit is contained in:
@@ -0,0 +1,84 @@
|
|||||||
|
package com.jsowell.adapay.response;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付撤销对象
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class PaymentReverseResponse {
|
||||||
|
/**
|
||||||
|
* Adapay生成的支付撤销对象id
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付撤销对象,payment_reverse
|
||||||
|
*/
|
||||||
|
private String object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前支付撤销状态,参见 状态 说明
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* true是prod模式,false是mock模式
|
||||||
|
*/
|
||||||
|
private String prod_mode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求订单号,只能为英文、数字或者下划线的一种或多种组合,保证在app_id下唯一
|
||||||
|
*/
|
||||||
|
private String order_no;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 原支付交易id
|
||||||
|
*/
|
||||||
|
private String payment_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 控制台 主页面应用的app_id
|
||||||
|
*/
|
||||||
|
private String app_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 撤销金额,必须大于0,保留两位小数点,如0.10、100.05等
|
||||||
|
*/
|
||||||
|
private String reverse_amt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 原支付对象已撤销金额,包括已撤销完成金额和撤销处理中的金额
|
||||||
|
*/
|
||||||
|
private String reversed_amt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前支付对象已确认金额
|
||||||
|
*/
|
||||||
|
private String confirmed_amt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前支付确认对象已退款金额,包括已退款完成金额和退款处理中的金额
|
||||||
|
*/
|
||||||
|
private String refunded_amt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间戳
|
||||||
|
*/
|
||||||
|
private String created_time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 撤销成功时间戳
|
||||||
|
*/
|
||||||
|
private String succeed_time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫码收银台返回的退款交易流水号
|
||||||
|
*/
|
||||||
|
private String channel_no;
|
||||||
|
}
|
||||||
@@ -10,10 +10,7 @@ import com.jsowell.adapay.common.DivMember;
|
|||||||
import com.jsowell.adapay.dto.SettleAccountDTO;
|
import com.jsowell.adapay.dto.SettleAccountDTO;
|
||||||
import com.jsowell.adapay.dto.UpdateAccountConfigDTO;
|
import com.jsowell.adapay.dto.UpdateAccountConfigDTO;
|
||||||
import com.jsowell.adapay.dto.WithdrawDTO;
|
import com.jsowell.adapay.dto.WithdrawDTO;
|
||||||
import com.jsowell.adapay.response.BalancePaymentResponse;
|
import com.jsowell.adapay.response.*;
|
||||||
import com.jsowell.adapay.response.PaymentConfirmResponse;
|
|
||||||
import com.jsowell.adapay.response.QueryCorpMemberResponse;
|
|
||||||
import com.jsowell.adapay.response.QueryMemberResponse;
|
|
||||||
import com.jsowell.adapay.vo.AdapayAccountBalanceVO;
|
import com.jsowell.adapay.vo.AdapayAccountBalanceVO;
|
||||||
import com.jsowell.adapay.vo.AdapayCorpMemberVO;
|
import com.jsowell.adapay.vo.AdapayCorpMemberVO;
|
||||||
import com.jsowell.adapay.vo.AdapayMemberInfoVO;
|
import com.jsowell.adapay.vo.AdapayMemberInfoVO;
|
||||||
@@ -637,7 +634,7 @@ public class AdapayMemberService {
|
|||||||
/**
|
/**
|
||||||
* 创建退款请求
|
* 创建退款请求
|
||||||
*/
|
*/
|
||||||
public void createRefundRequest(String paymentId, String refundAmt) {
|
public void createRefundRequest(String paymentId, BigDecimal refundAmt) {
|
||||||
// 延迟分账确认的调退款接口
|
// 延迟分账确认的调退款接口
|
||||||
Map<String, Object> refundParams = Maps.newHashMap();
|
Map<String, Object> refundParams = Maps.newHashMap();
|
||||||
refundParams.put("refund_amt", AdapayUtil.formatAmount(refundAmt));
|
refundParams.put("refund_amt", AdapayUtil.formatAmount(refundAmt));
|
||||||
@@ -655,7 +652,8 @@ public class AdapayMemberService {
|
|||||||
* 创建交易撤销请求
|
* 创建交易撤销请求
|
||||||
* 延迟分账未确认, 调交易撤销接口退款
|
* 延迟分账未确认, 调交易撤销接口退款
|
||||||
*/
|
*/
|
||||||
public void createPaymentReverseRequest(String paymentId, String reverseAmt) {
|
public PaymentReverseResponse createPaymentReverseRequest(String paymentId, BigDecimal reverseAmt) {
|
||||||
|
PaymentReverseResponse response;
|
||||||
// 延迟分账未确认调撤销调撤销接口退款
|
// 延迟分账未确认调撤销调撤销接口退款
|
||||||
Map<String, Object> reverseParams = Maps.newHashMap();
|
Map<String, Object> reverseParams = Maps.newHashMap();
|
||||||
reverseParams.put("app_id", ADAPAY_APP_ID);
|
reverseParams.put("app_id", ADAPAY_APP_ID);
|
||||||
@@ -663,11 +661,14 @@ public class AdapayMemberService {
|
|||||||
reverseParams.put("reverse_amt", AdapayUtil.formatAmount(reverseAmt));
|
reverseParams.put("reverse_amt", AdapayUtil.formatAmount(reverseAmt));
|
||||||
reverseParams.put("order_no", IdUtils.fastSimpleUUID());
|
reverseParams.put("order_no", IdUtils.fastSimpleUUID());
|
||||||
reverseParams.put("notify_url", ADAPAY_CALLBACK_URL);
|
reverseParams.put("notify_url", ADAPAY_CALLBACK_URL);
|
||||||
|
Map<String, Object> paymentReverse = null;
|
||||||
try {
|
try {
|
||||||
Map<String, Object> paymentReverse = PaymentReverse.create(reverseParams);
|
paymentReverse = PaymentReverse.create(reverseParams);
|
||||||
log.info("汇付支付创建交易撤销对象:{}", JSON.toJSONString(paymentReverse));
|
|
||||||
} catch (BaseAdaPayException e) {
|
} catch (BaseAdaPayException e) {
|
||||||
log.error("汇付支付创建交易撤销对象error", e);
|
log.error("汇付支付创建交易撤销对象error", e);
|
||||||
}
|
}
|
||||||
|
String jsonString = JSON.toJSONString(paymentReverse);
|
||||||
|
log.info("汇付支付创建交易撤销对象param:{}, result:{}", JSON.toJSONString(reverseParams), jsonString);
|
||||||
|
return JSONObject.parseObject(jsonString, PaymentReverseResponse.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2329,40 +2329,15 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 创建汇付退款对象 在完成初始化设置情况下,调用方法,获取 Refund对象
|
// 创建汇付退款对象 在完成初始化设置情况下,调用方法,获取 Refund对象
|
||||||
String id = record.getPaymentId(); //
|
|
||||||
String snowflakeId = SnowflakeIdWorker.getSnowflakeId();
|
|
||||||
String amount = AdapayUtil.formatAmount(dto.getRefundAmount());
|
|
||||||
|
|
||||||
// TODO 拿orderCode查询清分状态
|
// TODO 拿orderCode查询清分状态
|
||||||
String payMode = "delay";
|
String payMode = "delay";
|
||||||
if (StringUtils.equals("", payMode)) {
|
if (StringUtils.equals("", payMode)) {
|
||||||
// 延迟分账确认的调退款接口
|
// 延迟分账确认的调退款接口
|
||||||
adapayMemberService.createRefundRequest(id, amount);
|
adapayMemberService.createRefundRequest(record.getPaymentId(), dto.getRefundAmount());
|
||||||
// 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 {
|
} else {
|
||||||
// 延迟分账未确认调撤销调撤销接口退款
|
// 延迟分账未确认调撤销调撤销接口退款
|
||||||
adapayMemberService.createPaymentReverseRequest(id, amount);
|
adapayMemberService.createPaymentReverseRequest(record.getPaymentId(), dto.getRefundAmount());
|
||||||
// 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);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2388,15 +2363,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
|||||||
BigDecimal deductionAmount = vo.getDeductionAmount();
|
BigDecimal deductionAmount = vo.getDeductionAmount();
|
||||||
|
|
||||||
// 调汇付的交易撤销接口
|
// 调汇付的交易撤销接口
|
||||||
// adapayMemberService.
|
adapayMemberService.createPaymentReverseRequest(paymentId, deductionAmount);
|
||||||
// 调汇付的分账接口 确认交易
|
|
||||||
// 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);
|
MemberAdapayRecord record = memberAdapayRecordService.selectByPaymentId(paymentId);
|
||||||
|
|||||||
Reference in New Issue
Block a user