BUGFIX: 续订失败没有发送邮件

This commit is contained in:
2026-05-07 11:45:49 +08:00
parent bd6ba95a25
commit 1680debd4b
2 changed files with 7 additions and 7 deletions

View File

@@ -135,13 +135,17 @@ public class StripeSubscriptionServiceImpl implements StripeSubscriptionService
// renewal 场景:从 InvoicePaidHandler 直接传入已更新的 SubscriptionInfo避免事务未提交导致查询不到 // renewal 场景:从 InvoicePaidHandler 直接传入已更新的 SubscriptionInfo避免事务未提交导致查询不到
if (passedInfo != null) { if (passedInfo != null) {
long now = Instant.now().getEpochSecond(); long now = Instant.now().getEpochSecond();
// 限制当前时间在订阅区间内,避免处理上个周期内的回调而重复发送邮件 boolean inPeriod = now > passedInfo.getCurrentPeriodStart() && now < passedInfo.getCurrentPeriodEnd();
if (now > passedInfo.getCurrentPeriodStart() && now < passedInfo.getCurrentPeriodEnd() // 续订失败的场景可能订单状态已被更新为past_due
&& "active".equals(passedInfo.getStatus())) { boolean validStatus = "fail_renewal".equals(type)
? ("past_due".equals(passedInfo.getStatus()) || "active".equals(passedInfo.getStatus()))
: "active".equals(passedInfo.getStatus());
if (inPeriod && validStatus) {
return passedInfo; return passedInfo;
} }
return null; return null;
} }
if (!StringUtil.isNullOrEmpty(orderNo)) { if (!StringUtil.isNullOrEmpty(orderNo)) {
long now = Instant.now().getEpochSecond(); long now = Instant.now().getEpochSecond();
List<SubscriptionInfo> infos = subscriptionInfoMapper.selectList( List<SubscriptionInfo> infos = subscriptionInfoMapper.selectList(

View File

@@ -96,10 +96,6 @@ public class CheckoutSessionExpiredHandler implements StripeEventHandler {
// 首次订阅失败 // 首次订阅失败
stripeSubscriptionService.sendFailedNewOrderEmail(orderNo); stripeSubscriptionService.sendFailedNewOrderEmail(orderNo);
log.info("[checkout.session.expired] 首次订阅失败邮件已发送orderNo={}", orderNo); log.info("[checkout.session.expired] 首次订阅失败邮件已发送orderNo={}", orderNo);
} else {
// 续费失败 todo 续费不走这里吧?
stripeSubscriptionService.sendSubscriptionEmail(null, "fail_renewal", subInfoList.getFirst().getOrderNo(), null);
log.info("[checkout.session.expired] 续费失败邮件已发送orderNo={}", orderNo);
} }
} }