payermax-回调-返回vo
This commit is contained in:
@@ -12,6 +12,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -19,6 +20,10 @@ public class PayermaxService {
|
||||
|
||||
private final String SPILT_PREFIX = "-";
|
||||
|
||||
public Map<String, Object> returnSuccess(){
|
||||
return Map.of("code", "SUCCESS", "msg", "Success");
|
||||
}
|
||||
|
||||
public TradePayOrderResponse createOrder(CreateOrderParams params) {
|
||||
checkCreateOrderParams(params);
|
||||
|
||||
|
@@ -8,6 +8,7 @@ import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.payment.constant.PayConstant;
|
||||
import com.accompany.payment.model.ChargeRecord;
|
||||
import com.accompany.payment.payermax.PayermaxService;
|
||||
import com.accompany.payment.payermax.params.PayCallbackReqVo;
|
||||
import com.accompany.payment.service.ChargeRecordService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -21,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@@ -40,14 +42,16 @@ public class PayermaxPayController {
|
||||
private ChargeService chargeService;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
@Autowired
|
||||
private PayermaxService payermaxService;
|
||||
|
||||
@PostMapping("/callback")
|
||||
public BusiResult<Void> callback(@RequestHeader("sign") String sign, @RequestBody String paramsString) {
|
||||
public Map<String, Object> callback(@RequestHeader("sign") String sign, @RequestBody String paramsString) {
|
||||
log.info("[payermax] 接受回调参数为:{}",paramsString);
|
||||
|
||||
if (!DefaultPayermaxClient.getInstance().verifyNotification(paramsString, sign)) {
|
||||
log.error("[payermax] 验签失败 sign {} body {}", sign, paramsString);
|
||||
return BusiResult.success();
|
||||
return payermaxService.returnSuccess();
|
||||
}
|
||||
|
||||
PayCallbackReqVo payCallbackReqVo = JSON.parseObject(paramsString, PayCallbackReqVo.class);
|
||||
@@ -56,7 +60,7 @@ public class PayermaxPayController {
|
||||
|
||||
if (!PayCallbackReqVo.Status.SUCCESS.equals(order.getStatus())) {
|
||||
log.warn("[payermax] 支付回调 订单 {} 支付状态不是成功,忽略。", chargeRecordId);
|
||||
return BusiResult.success();
|
||||
return payermaxService.returnSuccess();
|
||||
}
|
||||
|
||||
String lockKey = RedisKey.lock_pay_callback_notify.getKey(chargeRecordId);
|
||||
@@ -72,19 +76,19 @@ public class PayermaxPayController {
|
||||
ChargeRecord chargeRecord = chargeRecordService.getChargeRecordById(chargeRecordId);
|
||||
if (null == chargeRecord || !Constant.ChargeRecordStatus.create.equals(chargeRecord.getChargeStatus())) {
|
||||
log.warn("[payermax] 支付回调 订单 {} 不存在", chargeRecordId);
|
||||
return BusiResult.success();
|
||||
return payermaxService.returnSuccess();
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(order.getCurrency()) || !order.getCurrency().equalsIgnoreCase(chargeRecord.getLocalCurrencyCode())) {
|
||||
log.warn("[payermax] 支付回调 回调的货币代码为空或与订单 {} 中的 {} 不匹配", chargeRecordId, chargeRecord.getLocalCurrencyCode());
|
||||
return BusiResult.success();
|
||||
return payermaxService.returnSuccess();
|
||||
}
|
||||
Long payAmount = BigDecimal.valueOf(order.getTotalAmount()).multiply(PayConstant.HUNDRED).longValue();
|
||||
// 校验金额
|
||||
boolean validateAmount = payAmount.equals(chargeRecord.getLocalAmount());
|
||||
if (!validateAmount) {
|
||||
log.warn("[payermax] 支付回调 订单 {} 金额 {} 校验失败", chargeRecordId, payAmount);
|
||||
return BusiResult.success();
|
||||
return payermaxService.returnSuccess();
|
||||
}
|
||||
chargeRecord.setCountry(order.getCountry());
|
||||
chargeRecord.setLocalCurrencyCode(order.getCurrency());
|
||||
@@ -95,10 +99,10 @@ public class PayermaxPayController {
|
||||
|
||||
chargeService.updateAppPayData(chargeRecord);
|
||||
|
||||
return BusiResult.success();
|
||||
return payermaxService.returnSuccess();
|
||||
} catch (Exception e) {
|
||||
log.error("[payermax] 回调异常", e);
|
||||
return BusiResult.fail(BusiStatus.SERVERERROR);
|
||||
throw new ServiceException(BusiStatus.SERVERERROR);
|
||||
} finally {
|
||||
if (isLocked || lock.isLocked()){
|
||||
lock.unlock();
|
||||
|
Reference in New Issue
Block a user