Merge remote-tracking branch 'origin/dev/dev' into dev/dev

This commit is contained in:
shahaibo
2025-02-07 10:25:20 +08:00
12 changed files with 118 additions and 66 deletions

View File

@@ -51,7 +51,7 @@ public class MyTaskScheduler {
// 定时任务,每十五天执行一次 // 定时任务,每十五天执行一次
// @Scheduled(cron = "0 0 0 ? * MON") // @Scheduled(cron = "0 0 0 ? * MON")
// @Scheduled(cron = "0 0 0 */15 * ?") @Scheduled(cron = "0 0 0 */15 * ?")
public void checkExpiry() { public void checkExpiry() {
// 检测正式用户是否快要过期 // 检测正式用户是否快要过期
QueryWrapper<Account> qw = new QueryWrapper<>(); QueryWrapper<Account> qw = new QueryWrapper<>();
@@ -85,7 +85,7 @@ public class MyTaskScheduler {
} }
} }
} }
// @Scheduled(cron = "0 0 9 * * ?") @Scheduled(cron = "0 0 9 * * ?")
public void sendTrialOrderExcelToManagements() { public void sendTrialOrderExcelToManagements() {
// 获取前一天日期 // 获取前一天日期
LocalDate yesterday = LocalDate.now().minusDays(1); LocalDate yesterday = LocalDate.now().minusDays(1);

View File

@@ -31,14 +31,14 @@ public class AccountTask {
accountService.refreshCreditsWeekly(); accountService.refreshCreditsWeekly();
} }
// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes
public void getPaidUser() { public void getPaidUser() {
// 获取code-create 表中 指定日期之后 订单状态为wc-processing的订单 // 获取code-create 表中 指定日期之后 订单状态为wc-processing的订单
accountService.extendValidityForCC(); accountService.extendValidityForCC();
} }
// 每天凌晨0点执行一次 // 每天凌晨0点执行一次
// @Scheduled(cron = "0 0 0 * * ?") @Scheduled(cron = "0 0 0 * * ?")
public void cancelActivityBenefits() { public void cancelActivityBenefits() {
// 1、查询当前所有参与了活动且过期的用户 // 1、查询当前所有参与了活动且过期的用户
List<Account> accountList = accountService.getExpiredUserBySystemUser(4); List<Account> accountList = accountService.getExpiredUserBySystemUser(4);
@@ -51,7 +51,7 @@ public class AccountTask {
} }
// 每天检测正式用户到期情况每天凌晨0点执行 // 每天检测正式用户到期情况每天凌晨0点执行
// @Scheduled(cron = "0 0 0 * * ?") @Scheduled(cron = "0 0 0 * * ?")
public void paidUserToVisitor() { public void paidUserToVisitor() {
// 1、查询当前已过期正式用户或试用用户 // 1、查询当前已过期正式用户或试用用户
List<Account> accountList = accountService.getExpiredUserBySystemUser(1); List<Account> accountList = accountService.getExpiredUserBySystemUser(1);
@@ -68,7 +68,7 @@ public class AccountTask {
/** /**
* 将Code-Create上注册的用户添加为AiDA的游客 * 将Code-Create上注册的用户添加为AiDA的游客
*/ */
// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes
public void registerUserToVisitor() { public void registerUserToVisitor() {
accountService.registerUserToVisitor(); accountService.registerUserToVisitor();
} }

View File

@@ -45,7 +45,7 @@ public class PaymentTask {
@Resource @Resource
private PayPalCheckoutService payPalCheckoutService; private PayPalCheckoutService payPalCheckoutService;
// @Scheduled(cron = "0/30 * * * * ?") @Scheduled(cron = "0/30 * * * * ?")
public void orderConfirmForPaypal() throws SerializeException { public void orderConfirmForPaypal() throws SerializeException {
// log.info("PayPal orderConfirm 被执行......"); // log.info("PayPal orderConfirm 被执行......");

View File

@@ -635,8 +635,10 @@ public class SendEmailUtil {
SendEmailResponse resp = client.SendEmail(req); SendEmailResponse resp = client.SendEmail(req);
log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp)); log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp));
} catch (TencentCloudSDKException e) { } catch (TencentCloudSDKException e) {
log.info("邮件发送失败###{}", e.toString()); log.info("邮件发送至{} 发送失败###{}", receiverAddress, e.toString());
throw new BusinessException("failed.to.send.mail"); log.error(e.getMessage());
// 这里不再抛出异常 失败就不发,保证后续正常运行
// throw new BusinessException("failed.to.send.mail");
} }
} }
@@ -835,9 +837,9 @@ public class SendEmailUtil {
public static void subscriptionEmailReminder(String type, SubscriptionEmailParamsDTO subscriptionEmailParamsDTO, String language, String receiverAddress) { public static void subscriptionEmailReminder(String type, SubscriptionEmailParamsDTO subscriptionEmailParamsDTO, String language, String receiverAddress) {
try { try {
// String merchantEmail = "kimwong@code-create.com.hk"; String merchantEmail = "kimwong@code-create.com.hk";
String developer = "xupei3360@163.com"; String developer = "xupei3360@163.com";
String[] receiverEmail = {/*merchantEmail, */developer}; String[] receiverEmail = {merchantEmail, developer};
Credential cred = new Credential(SECRET_ID, SECRET_KEy); Credential cred = new Credential(SECRET_ID, SECRET_KEy);
// 实例化一个http选项可选的没有特殊需求可以跳过 // 实例化一个http选项可选的没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile(); HttpProfile httpProfile = new HttpProfile();
@@ -1010,7 +1012,7 @@ public class SendEmailUtil {
template.setTemplateID(CREDITS_PURCHASE_MERCHANT); template.setTemplateID(CREDITS_PURCHASE_MERCHANT);
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
// 设置试用订单相关数据 // 设置试用订单相关数据
jsonObject.put("userName", username); jsonObject.put("username", username);
jsonObject.put("quantity", quantity); jsonObject.put("quantity", quantity);
jsonObject.put("totalFee", amount); jsonObject.put("totalFee", amount);

View File

@@ -220,7 +220,7 @@ public interface AccountService extends IService<Account> {
Boolean unbindGoogle(); Boolean unbindGoogle();
void updateAccountValidity(Long accountId, Long currentPeriodEnd); boolean updateAccountValidity(Long accountId, Long currentPeriodEnd);
void updateUserRoleAndCredits(Long accountId, String type); void updateUserRoleAndCredits(Long accountId, String type);

View File

@@ -36,4 +36,6 @@ public interface CreditsService extends IService<CreditsDetail> {
void preInsert(Long accountId, String changeEventName, String taskId, Boolean isPreInsert, String changedCredits); void preInsert(Long accountId, String changeEventName, String taskId, Boolean isPreInsert, String changedCredits);
void updateChangedCredits(String accountId, String taskId); void updateChangedCredits(String accountId, String taskId);
CreditsDetail queryDetailByTaskId(String taskId);
} }

View File

@@ -1335,7 +1335,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
config.addDataSourceProperty("cachePrepStmts", "true"); config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("maxLifetime", 300000); config.addDataSourceProperty("maxLifetime", 50000);
dataSource = new HikariDataSource(config); dataSource = new HikariDataSource(config);
} }
@@ -2745,12 +2745,16 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
return result; return result;
} }
public void updateAccountValidity(Long accountId, Long currentPeriodEnd){ public boolean updateAccountValidity(Long accountId, Long currentPeriodEnd){
// 不管当前用户的账号是否到期,都根据付款信息重置账号到期时间 // 不管当前用户的账号是否到期,都根据付款信息重置账号到期时间
Account account = accountMapper.selectById(accountId); Account account = accountMapper.selectById(accountId);
account.setValidEndTime(currentPeriodEnd * 1000); if (account.getValidEndTime().equals(currentPeriodEnd * 1000)){
return false;
accountMapper.updateById(account); }else {
account.setValidEndTime(currentPeriodEnd * 1000);
accountMapper.updateById(account);
}
return true;
} }
public void updateUserRoleAndCredits(Long accountId, String type){ public void updateUserRoleAndCredits(Long accountId, String type){

View File

@@ -76,9 +76,9 @@ public class AffiliateServiceImpl extends ServiceImpl<AffiliateMapper, Affiliate
affiliate.setPromotionMethod(promotionMethod); affiliate.setPromotionMethod(promotionMethod);
baseMapper.insert(affiliate); baseMapper.insert(affiliate);
// 邮件通知审批者 // 邮件通知审批者
// String merchantEmail = "kimwong@code-create.com.hk"; String merchantEmail = "kimwong@code-create.com.hk";
String developer = "xupei3360@163.com"; String developer = "xupei3360@163.com";
String[] receiverEmail = {/*merchantEmail, */developer}; String[] receiverEmail = {merchantEmail, developer};
SendEmailUtil.affiliateEmailReminder(receiverEmail, new AffiliateEmailParamsDTO(userHolder.getUsername(), promotionMethod), "new"); SendEmailUtil.affiliateEmailReminder(receiverEmail, new AffiliateEmailParamsDTO(userHolder.getUsername(), promotionMethod), "new");
}else { }else {
throw new BusinessException("You have registered an Affiliate", ResultEnum.PROMPT.getCode()); throw new BusinessException("You have registered an Affiliate", ResultEnum.PROMPT.getCode());
@@ -313,9 +313,9 @@ public class AffiliateServiceImpl extends ServiceImpl<AffiliateMapper, Affiliate
affiliateEmailParamsDTO.setUnpaidEarnings(totalCommission.toString()); affiliateEmailParamsDTO.setUnpaidEarnings(totalCommission.toString());
affiliateEmailParamsDTO.setPaidEarnings("0"); affiliateEmailParamsDTO.setPaidEarnings("0");
// String merchantEmail = "kimwong@code-create.com.hk"; String merchantEmail = "kimwong@code-create.com.hk";
String developer = "xupei3360@163.com"; String developer = "xupei3360@163.com";
String[] receiverEmail = {/*merchantEmail, */developer}; String[] receiverEmail = {merchantEmail, developer};
// 邮件通知 // 邮件通知
SendEmailUtil.affiliateEmailReminder(receiverEmail, affiliateEmailParamsDTO, "summary"); SendEmailUtil.affiliateEmailReminder(receiverEmail, affiliateEmailParamsDTO, "summary");
} }

View File

@@ -318,4 +318,10 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
} }
public CreditsDetail queryDetailByTaskId(String taskId) {
QueryWrapper<CreditsDetail> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("task_id", taskId);
return baseMapper.selectOne(queryWrapper);
}
} }

View File

@@ -9,10 +9,7 @@ import com.ai.da.common.utils.SendEmailUtil;
import com.ai.da.mapper.primary.AccountMapper; import com.ai.da.mapper.primary.AccountMapper;
import com.ai.da.mapper.primary.PaymentInfoMapper; import com.ai.da.mapper.primary.PaymentInfoMapper;
import com.ai.da.mapper.primary.SubscriptionInfoMapper; import com.ai.da.mapper.primary.SubscriptionInfoMapper;
import com.ai.da.mapper.primary.entity.OrderInfo; import com.ai.da.mapper.primary.entity.*;
import com.ai.da.mapper.primary.entity.PaymentInfo;
import com.ai.da.mapper.primary.entity.RefundInfo;
import com.ai.da.mapper.primary.entity.SubscriptionInfo;
import com.ai.da.model.dto.ProductPurchaseDTO; import com.ai.da.model.dto.ProductPurchaseDTO;
import com.ai.da.model.dto.SubscriptionEmailParamsDTO; import com.ai.da.model.dto.SubscriptionEmailParamsDTO;
import com.ai.da.service.*; import com.ai.da.service.*;
@@ -24,6 +21,7 @@ import com.stripe.Stripe;
import com.stripe.exception.SignatureVerificationException; import com.stripe.exception.SignatureVerificationException;
import com.stripe.exception.StripeException; import com.stripe.exception.StripeException;
import com.stripe.model.*; import com.stripe.model.*;
import com.stripe.model.Product;
import com.stripe.model.checkout.Session; import com.stripe.model.checkout.Session;
import com.stripe.net.Webhook; import com.stripe.net.Webhook;
import com.stripe.param.*; import com.stripe.param.*;
@@ -42,6 +40,7 @@ import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@SuppressWarnings("LoggingSimilarMessage") @SuppressWarnings("LoggingSimilarMessage")
@Service @Service
@@ -140,6 +139,9 @@ public class StripeServiceImpl implements StripeService {
// one-time 手动创建发票;订阅会自动创建invoice // one-time 手动创建发票;订阅会自动创建invoice
sessionBuilder.setInvoiceCreation(SessionCreateParams.InvoiceCreation.builder().setEnabled(Boolean.TRUE).build()); sessionBuilder.setInvoiceCreation(SessionCreateParams.InvoiceCreation.builder().setEnabled(Boolean.TRUE).build());
} }
// sessionBuilder.setPaymentMethodConfiguration("pmc_1QIKyq02n1TEydyNKVEYvhW7");
// sessionBuilder.addPaymentMethodType(SessionCreateParams.PaymentMethodType.ALIPAY);
// sessionBuilder.addPaymentMethodType(SessionCreateParams.PaymentMethodType.CARD);
sessionBuilder.setCustomer(customerId); sessionBuilder.setCustomer(customerId);
sessionBuilder.setSuccessUrl(productPurchaseDTO.getReturnUrl());//可自定义成功页面 sessionBuilder.setSuccessUrl(productPurchaseDTO.getReturnUrl());//可自定义成功页面
sessionBuilder.setLocale(account.getLanguage().equals("CHINESE_SIMPLIFIED") ? SessionCreateParams.Locale.ZH : SessionCreateParams.Locale.EN); sessionBuilder.setLocale(account.getLanguage().equals("CHINESE_SIMPLIFIED") ? SessionCreateParams.Locale.ZH : SessionCreateParams.Locale.EN);
@@ -151,7 +153,12 @@ public class StripeServiceImpl implements StripeService {
sessionBuilder.putMetadata("orderId", orderId); //通过订单号关联用于检索支付信息(可选) sessionBuilder.putMetadata("orderId", orderId); //通过订单号关联用于检索支付信息(可选)
Session session = Session.create(sessionBuilder.build()); Session session = Session.create(sessionBuilder.build());
log.info("sessionId:" + session.getId()); //退款方式1拿到sessionId入库退款的时候根据这个id找到PaymentIntent的id然后发起退款 List<String> paymentMethodTypes = session.getPaymentMethodTypes();
log.info("paymentMethodTypes: {}", paymentMethodTypes);
Session.PaymentMethodConfigurationDetails paymentMethodConfigurationDetails = session.getPaymentMethodConfigurationDetails();
log.info("paymentMethodConfigurationDetails ID: {}", paymentMethodConfigurationDetails.getId());
log.info("sessionId:{}", session.getId()); //退款方式1拿到sessionId入库退款的时候根据这个id找到PaymentIntent的id然后发起退款
// 更新order信息 // 更新order信息
orderInfoService.updateOrderNoById(orderInfo.getId(), orderId); orderInfoService.updateOrderNoById(orderInfo.getId(), orderId);
@@ -350,6 +357,11 @@ public class StripeServiceImpl implements StripeService {
// 发送续订失败邮件 // 发送续订失败邮件
response = sendRenewalFailEmail(invoice.getId(), null, paymentInfo.getOrderNo()); response = sendRenewalFailEmail(invoice.getId(), null, paymentInfo.getOrderNo());
}else {
// 新增支付信息
PaymentInfo paymentInfoFail = paymentInfoService.createOrUpdatePaymentInfoForStripe(invoice);
// 发送新订阅失败邮件
response = sendEmail(paymentInfoFail.getOrderNo());
} }
} }
}else if (stripeObject instanceof Charge) { }else if (stripeObject instanceof Charge) {
@@ -387,22 +399,26 @@ public class StripeServiceImpl implements StripeService {
// 当订单状态处于未支付或超时已关闭时,更新订单状态,其他状态均不更新订单状态 // 当订单状态处于未支付或超时已关闭时,更新订单状态,其他状态均不更新订单状态
if (!OrderStatusEnum.NOT_PAY.getType().equals(orderStatus) && !OrderStatusEnum.TIMEOUT_CLOSED.getType().equals(orderStatus)) { if (!OrderStatusEnum.NOT_PAY.getType().equals(orderStatus) && !OrderStatusEnum.TIMEOUT_CLOSED.getType().equals(orderStatus)) {
log.info("订单状态 : {}", orderStatus); log.info("订单状态 : {}", orderStatus);
return; }else {
//更新订单状态
orderInfoService.updateStatusByOrderNo(orderId, OrderStatusEnum.SUCCESS);
log.info("Stripe 订单:{} 状态更新成功", orderId);
} }
//更新订单状态
orderInfoService.updateStatusByOrderNo(orderId, OrderStatusEnum.SUCCESS);
log.info("Stripe 订单:{} 状态更新成功", orderId);
if (orderByOrderNo.getTitle().startsWith("积分购买")){ if (orderByOrderNo.getTitle().startsWith("积分购买")){
float quantity = totalAmount / ProductEnum.CreditsProduct.getPrice(); // 查询当前订单的积分是否已添加
// 更新积分 CreditsDetail creditsDetail = creditsService.queryDetailByTaskId(orderId);
creditsService.buyCredits(orderByOrderNo.getAccountId(), quantity); if (Objects.isNull(creditsDetail)){
// 添加积分变更记录 float quantity = totalAmount / ProductEnum.CreditsProduct.getPrice();
creditsService.insertToCreditsDetail(orderByOrderNo.getAccountId(), // 更新积分
CreditsEventsEnum.BUY_CREDITS.getName() + "--Stripe", creditsService.buyCredits(orderByOrderNo.getAccountId(), quantity);
String.valueOf((Long.parseLong(CreditsEventsEnum.BUY_CREDITS.getValue()) * quantity)), // 添加积分变更记录
"positive", orderId); creditsService.insertToCreditsDetail(orderByOrderNo.getAccountId(),
log.info("用户:{} 积分信息更新成功", orderByOrderNo.getAccountId()); CreditsEventsEnum.BUY_CREDITS.getName() + "--Stripe",
String.valueOf((Long.parseLong(CreditsEventsEnum.BUY_CREDITS.getValue()) * quantity)),
"positive", orderId);
log.info("用户:{} 积分信息更新成功", orderByOrderNo.getAccountId());
}
} }
} catch (Exception e) { } catch (Exception e) {
log.info(e.getMessage()); log.info(e.getMessage());
@@ -468,11 +484,13 @@ public class StripeServiceImpl implements StripeService {
subscriptionInfo.setCreateTime(LocalDateTime.now()); subscriptionInfo.setCreateTime(LocalDateTime.now());
subscriptionInfoMapper.insert(subscriptionInfo); subscriptionInfoMapper.insert(subscriptionInfo);
// 更新账号到期时间 if (subscriptionInfo.getStatus().equals("active")){
accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd()); log.info("创建订阅更新账号信息");
// 更新账号到期时间
// 更新账号身份和积分 boolean b = accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), interval); // 更新账号身份和积分
if (b) accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), interval);
}
} }
return subscriptionInfo; return subscriptionInfo;
} }
@@ -498,7 +516,7 @@ public class StripeServiceImpl implements StripeService {
public SubscriptionInfo getLatestSubscriptionInfoByAccountId(Long accountId){ public SubscriptionInfo getLatestSubscriptionInfoByAccountId(Long accountId){
QueryWrapper<SubscriptionInfo> qw = new QueryWrapper<>(); QueryWrapper<SubscriptionInfo> qw = new QueryWrapper<>();
qw.eq("account_id", accountId); qw.eq("account_id", accountId).orderByDesc("id");
List<SubscriptionInfo> subscriptionInfos = subscriptionInfoMapper.selectList(qw); List<SubscriptionInfo> subscriptionInfos = subscriptionInfoMapper.selectList(qw);
if (subscriptionInfos.isEmpty()){ if (subscriptionInfos.isEmpty()){
return null; return null;
@@ -524,6 +542,7 @@ public class StripeServiceImpl implements StripeService {
if (!subscriptionInfo.getCurrentPeriodEnd().equals(subscription.getCurrentPeriodEnd())){ if (!subscriptionInfo.getCurrentPeriodEnd().equals(subscription.getCurrentPeriodEnd())){
subscriptionInfo.setCurrentPeriodEnd(subscription.getCurrentPeriodEnd()); subscriptionInfo.setCurrentPeriodEnd(subscription.getCurrentPeriodEnd());
subscriptionInfo.setNextPayDate(DateUtil.changeTimeStampFormat(subscription.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy_EEEE)); subscriptionInfo.setNextPayDate(DateUtil.changeTimeStampFormat(subscription.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy_EEEE));
log.info("更新订阅更新账号信息");
// 更新账号到期时间 // 更新账号到期时间
accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd()); accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
// 更新账号身份和积分 // 更新账号身份和积分
@@ -531,6 +550,12 @@ public class StripeServiceImpl implements StripeService {
log.info("更新 {} 账号到期时间为:{}", subscriptionInfo.getAccountId(), DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy_EEEE)); log.info("更新 {} 账号到期时间为:{}", subscriptionInfo.getAccountId(), DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy_EEEE));
flag = true; flag = true;
} }
if (subscriptionInfo.getStatus().equals("active")){
// 更新账号到期时间
boolean b = accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
// 更新账号身份和积分
if (b) accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), subscriptionInfo.getType());
}
if (flag){ if (flag){
subscriptionInfo.setUpdateTime(LocalDateTime.now()); subscriptionInfo.setUpdateTime(LocalDateTime.now());
subscriptionInfoMapper.updateById(subscriptionInfo); subscriptionInfoMapper.updateById(subscriptionInfo);
@@ -541,8 +566,8 @@ public class StripeServiceImpl implements StripeService {
// 取消连续订阅 将订阅从pause状态转为cancel状态使用定时器定期检索DB中过期且不续订的订阅 // 取消连续订阅 将订阅从pause状态转为cancel状态使用定时器定期检索DB中过期且不续订的订阅
public void cancelSubscription(String subscriptionId, String cancelReason) { public void cancelSubscription(String subscriptionId, String cancelReason) {
Stripe.apiKey = privateKey; Stripe.apiKey = privateKey;
log.info("cancel subscription");
Long accountId = UserContext.getUserHolder().getId(); Long accountId = UserContext.getUserHolder().getId();
log.info("用户 {} 申请取消连续订阅 {}", accountId, subscriptionId);
com.ai.da.mapper.primary.entity.Account account = accountMapper.selectById(accountId); com.ai.da.mapper.primary.entity.Account account = accountMapper.selectById(accountId);
List<Subscription> subscriptions = getSubscription(account.getUserName(), account.getUserEmail()); List<Subscription> subscriptions = getSubscription(account.getUserName(), account.getUserEmail());
// 获取status = active的订阅 // 获取status = active的订阅
@@ -551,7 +576,7 @@ public class StripeServiceImpl implements StripeService {
try { try {
Subscription cancel = subscription.cancel(); Subscription cancel = subscription.cancel();
cancel.getStatus(); cancel.getStatus();
log.info("用户 {} 申请取消连续订阅 {}", accountId, subscriptionId);
// 更新数据库 // 更新数据库
updateCancelReason(subscriptionId, cancelReason); updateCancelReason(subscriptionId, cancelReason);
} catch (StripeException e) { } catch (StripeException e) {
@@ -809,10 +834,20 @@ public class StripeServiceImpl implements StripeService {
SubscriptionEmailParamsDTO emailParamsDTO = new SubscriptionEmailParamsDTO(); SubscriptionEmailParamsDTO emailParamsDTO = new SubscriptionEmailParamsDTO();
QueryWrapper<SubscriptionInfo> qwSI = new QueryWrapper<>(); QueryWrapper<SubscriptionInfo> qwSI = new QueryWrapper<>();
qwSI.eq("subscription_id", subscriptionId); qwSI.eq("subscription_id", subscriptionId);
SubscriptionInfo subscriptionInfo = subscriptionInfoMapper.selectOne(qwSI); List<SubscriptionInfo> subscriptionInfoList = subscriptionInfoMapper.selectList(qwSI);
if (Objects.isNull(subscriptionInfo)) { SubscriptionInfo subscriptionInfo;
if (subscriptionInfoList.isEmpty()){
return false; return false;
}else {
List<SubscriptionInfo> activeSubscriptions = subscriptionInfoList.stream()
.filter(subscription -> "active".equals(subscription.getStatus()))
.collect(Collectors.toList());
if (activeSubscriptions.isEmpty()){
return false;
}
subscriptionInfo = activeSubscriptions.get(0);
} }
QueryWrapper<PaymentInfo> qwPI = new QueryWrapper<>(); QueryWrapper<PaymentInfo> qwPI = new QueryWrapper<>();
qwPI.eq("order_no", subscriptionInfo.getOrderNo()).orderByDesc("id"); qwPI.eq("order_no", subscriptionInfo.getOrderNo()).orderByDesc("id");
List<PaymentInfo> paymentInfos = paymentInfoMapper.selectList(qwPI); List<PaymentInfo> paymentInfos = paymentInfoMapper.selectList(qwPI);

View File

@@ -2,7 +2,7 @@
#spring.profiles.active=test #spring.profiles.active=test
#<23><><EFBFBD><EFBFBD>application-prod<6F>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) #<23><><EFBFBD><EFBFBD>application-prod<6F>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
#spring.profiles.active=prod spring.profiles.active=prod
#<23><><EFBFBD><EFBFBD>application-dev<65>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) #<23><><EFBFBD><EFBFBD>application-dev<65>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
spring.profiles.active=prod #spring.profiles.active=dev

View File

@@ -1,12 +1,12 @@
##### PayPal ##### PayPal
# developer-sandbox-xp # developer-sandbox-xp
paypal.client-id=ATbaebYi7-GXWRWJqwRLYMzKEbwjh4BFRqD4Y13i4lZq0rplWIM_IpPrtPKpdkAt_KrPXd6IJTwsDqa5 #paypal.client-id=ATbaebYi7-GXWRWJqwRLYMzKEbwjh4BFRqD4Y13i4lZq0rplWIM_IpPrtPKpdkAt_KrPXd6IJTwsDqa5
paypal.client-secret=EHWWJqGmmbfjLXqCUpGrvxRYBPPtWvA3hR5ZaAyHlGSVJiHoQPS8skbNaJ9h39VObnchUbgiY2pPu__s #paypal.client-secret=EHWWJqGmmbfjLXqCUpGrvxRYBPPtWvA3hR5ZaAyHlGSVJiHoQPS8skbNaJ9h39VObnchUbgiY2pPu__s
paypal.receiver.email=sb-ukxfk29608925@business.example.com #paypal.receiver.email=sb-ukxfk29608925@business.example.com
paypal.mode=sandbox #paypal.mode=sandbox
## local ## local
paypal.webhook_id=31797347YC028794L #paypal.webhook_id=31797347YC028794L
# dev # dev
#paypal.webhook_id=51V87014T6406322F #paypal.webhook_id=51V87014T6406322F
@@ -18,17 +18,17 @@ paypal.webhook_id=31797347YC028794L
#paypal.webhook_id=1WH327112B602422N #paypal.webhook_id=1WH327112B602422N
# aida-live-kim # aida-live-kim
#paypal.client-id=ASWSIZ3MXJU5w5VOeOHeigWcSw6iinl30ZCipruziKpHclxP0ryf8-7VKG1Ba2VwZwa2DMvGEzTfCTgz paypal.client-id=ASWSIZ3MXJU5w5VOeOHeigWcSw6iinl30ZCipruziKpHclxP0ryf8-7VKG1Ba2VwZwa2DMvGEzTfCTgz
#paypal.client-secret=EHQg_K5PSqmp4FJlzEcOEH_kFkmq4aBzaI7jridw53L6cOQRULBAnfv2KakRfrsqaU1PDSkO4Co9Vyxc paypal.client-secret=EHQg_K5PSqmp4FJlzEcOEH_kFkmq4aBzaI7jridw53L6cOQRULBAnfv2KakRfrsqaU1PDSkO4Co9Vyxc
#paypal.receiver.email=kimwong@code-create.com.hk paypal.receiver.email=kimwong@code-create.com.hk
#paypal.mode=live paypal.mode=live
#paypal.webhook_id=1D107312EX592781K paypal.webhook_id=1D107312EX592781K
##### Stripe ##### Stripe
# developer # developer
stripe.private-key=sk_test_51P4ZZL02n1TEydyN8qQHjOA9imsFU7Oxs2HMHGy2urHnnQgSHnZuu5vVP6pKhEACwUpsKNyrbZpdcg5TJWJLRHcY008dEO1fn2 #stripe.private-key=sk_test_51P4ZZL02n1TEydyN8qQHjOA9imsFU7Oxs2HMHGy2urHnnQgSHnZuu5vVP6pKhEACwUpsKNyrbZpdcg5TJWJLRHcY008dEO1fn2
stripe.webhook-sign-secret=whsec_e0dBiJngx6qqgJj6yPyJ2A9ouh1Cjv5w #stripe.webhook-sign-secret=whsec_e0dBiJngx6qqgJj6yPyJ2A9ouh1Cjv5w
#stripe.webhook-sign-secret=whsec_TJcMSnAkh4uktrNY1M6Iy8XaVze4Rzqm #stripe.webhook-sign-secret=whsec_TJcMSnAkh4uktrNY1M6Iy8XaVze4Rzqm
# kim - test # kim - test
@@ -36,5 +36,8 @@ stripe.webhook-sign-secret=whsec_e0dBiJngx6qqgJj6yPyJ2A9ouh1Cjv5w
#stripe.webhook-sign-secret=whsec_GoyVEAaBtuGD5Rt55z83JnPnLDAZTN3u #stripe.webhook-sign-secret=whsec_GoyVEAaBtuGD5Rt55z83JnPnLDAZTN3u
# kim - live # kim - live
#stripe.private-key=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 stripe.private-key=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
#stripe.webhook-sign-secret=whsec_hhGDgdelQRHSg4LmChtQe41crj41eb11 # 正式支付环境下生产分支端点
stripe.webhook-sign-secret=whsec_hhGDgdelQRHSg4LmChtQe41crj41eb11
# 正式支付环境下测试分支端点
#stripe.webhook-sign-secret=whsec_cFUtjUOo8wnrIKZmt4GNvt7ZY1bOfrYr