Stripe 添加一次订阅服务(默认关闭自动续订功能)

This commit is contained in:
2025-02-17 17:14:30 +08:00
parent d2d5eebe12
commit 37ff60fcfb
12 changed files with 207 additions and 68 deletions

View File

@@ -1,5 +1,6 @@
package com.ai.da.common.utils;
import com.ai.da.common.constant.CommonConstant;
import lombok.extern.slf4j.Slf4j;
import java.text.ParseException;
@@ -96,7 +97,7 @@ public class DateUtil {
}
public static String changeTimeStampFormat(LocalDateTime localDate){
return localDate.format(DateTimeFormatter.ofPattern("MMM. dd, yyyy, EEEE", Locale.US));
return localDate.format(DateTimeFormatter.ofPattern(CommonConstant.TIME_FORMAT_MMM_dd_yyyy_EEEE, Locale.US));
}
}

View File

@@ -841,7 +841,7 @@ public class SendEmailUtil {
try {
String merchantEmail = "kimwong@code-create.com.hk";
String developer = "xupei3360@163.com";
String[] receiverEmail = {merchantEmail, developer};
String[] receiverEmail = {/*merchantEmail, */developer};
Credential cred = new Credential(SECRET_ID, SECRET_KEy);
// 实例化一个http选项可选的没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
@@ -1008,7 +1008,7 @@ public class SendEmailUtil {
req.setFromEmailAddress(SEND_ADDRESS);
String merchantEmail = "kimwong@code-create.com.hk";
String developerEmail = "xupei@code-create.com.hk";
req.setDestination(new String[]{merchantEmail, developerEmail});
req.setDestination(new String[]{/*merchantEmail,*/ developerEmail});
Template template = new Template();
req.setSubject("New Credit Purchase Order");
template.setTemplateID(CREDITS_PURCHASE_MERCHANT);

View File

@@ -23,6 +23,8 @@ public class OrderInfo extends BaseEntity{
private String note;
private byte autoRenewal;
private String paymentType;//支付方式
// 可用于标记用户订单是否首次订阅

View File

@@ -42,6 +42,8 @@ public class SubscriptionEmailParamsDTO {
// 订阅开始时间
private String startDate;
private String endDate;
// 下一个支付日期
private String nextPayDate;

View File

@@ -15,7 +15,8 @@ public interface OrderInfoService extends IService<OrderInfo> {
OrderInfo createOrderByProductId(Integer productId, String paymentType, HttpServletRequest request);
OrderInfo createOrderByProductId(Integer amount, String paymentType, ProductEnum product, HttpServletRequest request);
OrderInfo createOrderByProductId(Integer amount, String paymentType, ProductEnum product,
HttpServletRequest request, byte autoRenewal);
void saveCodeUrl(String orderNo, String codeUrl);

View File

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

View File

@@ -89,7 +89,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
}
}
public OrderInfo createOrderByProductId(Integer amount, String paymentType, ProductEnum product, HttpServletRequest request) {
public OrderInfo createOrderByProductId(Integer amount, String paymentType, ProductEnum product,
HttpServletRequest request, byte autoRenewal) {
//获取商品信息
// Product product = productMapper.selectById(amount);

View File

@@ -236,14 +236,16 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
if (Objects.isNull(paymentInfo)){
String orderNo;
try {
if (invoice.getBillingReason().equals("manual")){
// 手动创建的发票针对one-time支付
orderNo = invoice.getLines().getData().get(0).getPrice().getMetadata().get("orderId");
}else {
String subscriptionId = invoice.getSubscription();
// 从subscription中获取orderNo
orderNo = Subscription.retrieve(subscriptionId).getDescription().replace("AiDA - ", "");
}
String chargeId = invoice.getCharge();
orderNo = Charge.retrieve(chargeId).getDescription().replace("AiDA - ", "");
// if (invoice.getBillingReason().equals("manual")){
// // 手动创建的发票针对one-time支付
//// orderNo = invoice.getLines().getData().get(0).getPrice().getMetadata().get("orderId");
// }else {
// String subscriptionId = invoice.getSubscription();
// // 从subscription中获取orderNo
// orderNo = Subscription.retrieve(subscriptionId).getDescription().replace("AiDA - ", "");
// }
} catch (StripeException e) {
throw new RuntimeException(e);
}

View File

@@ -39,6 +39,7 @@ import java.math.RoundingMode;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
@@ -95,9 +96,9 @@ public class StripeServiceImpl implements StripeService {
case "Year":
productEnum = ProductEnum.AnnualSubscription;
break;
/*case "Day":
case "Day":
productEnum = ProductEnum.DailySubscription;
break;*/
break;
default:
throw new BusinessException("unknown subscription type");
}
@@ -106,14 +107,17 @@ public class StripeServiceImpl implements StripeService {
throw new BusinessException("unknown product type");
}
log.info("生成订单");
OrderInfo orderInfo = orderInfoService.createOrderByProductId(productPurchaseDTO.getQuantity(),
PayTypeEnum.STRIPE.getType(), productEnum, request);
String payType;
byte autoRenewal;
if (productPurchaseDTO.getAutoRenewal()){
payType = "recurring";
autoRenewal = 1;
}else {
payType = "one_time";
autoRenewal = 0;
}
OrderInfo orderInfo = orderInfoService.createOrderByProductId(productPurchaseDTO.getQuantity(),
PayTypeEnum.STRIPE.getType(), productEnum, request, autoRenewal);
try {
Long id = UserContext.getUserHolder().getId();
@@ -139,7 +143,10 @@ public class StripeServiceImpl implements StripeService {
// one-time 手动创建发票;订阅会自动创建invoice
sessionBuilder.setInvoiceCreation(SessionCreateParams.InvoiceCreation.builder().setEnabled(Boolean.TRUE).build());
}
// developer test
// sessionBuilder.setPaymentMethodConfiguration("pmc_1QIKyq02n1TEydyNKVEYvhW7");
// kim test
sessionBuilder.setPaymentMethodConfiguration("pmc_1LywTWH7nPZ8bkrN6FvdCUWG");
// sessionBuilder.addPaymentMethodType(SessionCreateParams.PaymentMethodType.ALIPAY);
// sessionBuilder.addPaymentMethodType(SessionCreateParams.PaymentMethodType.CARD);
sessionBuilder.setCustomer(customerId);
@@ -276,17 +283,17 @@ public class StripeServiceImpl implements StripeService {
return Boolean.FALSE;
}
log.info("stripe验签成功");
Boolean response = Boolean.TRUE;
boolean response = Boolean.TRUE;
log.info("回调事件 {}", event.getType());
if (stripeObject instanceof Session){
Session session = (Session) stripeObject;
if (event.getType().equals("checkout.session.completed")) {
processOrder(session);
response = processOrder(session);
}else if (event.getType().equals("checkout.session.expired")){
String orderNo = session.getMetadata().get("orderId");
// 会话过期 未支付 且之后没有支付成功的订单
processExpiredOrder(orderNo);
response = processExpiredOrder(orderNo);
}
} else if (stripeObject instanceof Subscription){
Subscription subscription = (Subscription) stripeObject;
@@ -299,7 +306,7 @@ public class StripeServiceImpl implements StripeService {
SubscriptionInfo subscriptionInfo = updateSubscription(subscription);
log.info("订阅更新");
if (subscription.getStatus().equals("active")){
response = sendEmail(subscription.getId(), null);
response = sendEmail(subscription.getId(), null, null);
}
// 续订支付失败,邮件通知用户
if (subscription.getStatus().equals("past_due")){
@@ -312,9 +319,14 @@ public class StripeServiceImpl implements StripeService {
log.info("用户 {} 取消连续订阅 {}", subscriptionInfo.getAccountId(), subscription.getId());
if (subscriptionInfo.getCancelNotified() == (byte)0){
log.info("取消订阅 邮件通知商家");
response = sendEmail(subscription.getId(), "cancel");
subscriptionInfo.setCancelNotified((byte)1);
subscriptionInfoMapper.updateById(subscriptionInfo);
response = sendEmail(subscription.getId(), "cancel", null);
if (response){
subscriptionInfo.setCancelNotified((byte)1);
subscriptionInfoMapper.updateById(subscriptionInfo);
// 更新订单信息
OrderInfo orderInfo = orderInfoService.getOrderByOrderNo(subscriptionInfo.getOrderNo());
orderInfo.setAutoRenewal((byte)0);
}
}
}/* else if (event.getType().equals("customer.subscription.paused")){
@@ -334,10 +346,20 @@ public class StripeServiceImpl implements StripeService {
// 更新t_order_info中的total_fee,记录该订单的累计付款金额
orderInfoService.updateTotalFeeByOrderNo(paymentInfo.getOrderNo());
// 邮件通知商家和用户
if (invoice.getBillingReason().equals("subscription_create")){
response = sendEmail(invoice.getSubscription(), "new");
} else if (invoice.getBillingReason().equals("subscription_cycle")){
response = sendEmail(invoice.getSubscription(), "renewal");
String billingReason = invoice.getBillingReason();
switch (billingReason) {
case "subscription_create":
response = sendEmail(invoice.getSubscription(), "new", null);
break;
case "subscription_cycle":
response = sendEmail(invoice.getSubscription(), "renewal", null);
break;
case "manual":
boolean b = invoice.getLines().getData().get(0).getDescription().endsWith("Subscription");
if (b) {
response = sendEmail(invoice.getSubscription(), "new", null);
}
break;
}
}
} else if (event.getType().equals("invoice.payment_failed")) {
@@ -386,28 +408,30 @@ public class StripeServiceImpl implements StripeService {
return response;
}
public void processOrder(Session session) {
String orderId = session.getMetadata().get("orderId");
public boolean processOrder(Session session) {
Stripe.apiKey = privateKey;
String orderNo = session.getMetadata().get("orderId");
float totalAmount = new BigDecimal(session.getAmountTotal()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).floatValue();
boolean resp = true;
try {
//处理重复通知
//接口调用的幂等性:无论接口被调用多少次,以下业务执行一次
// String orderStatus = orderInfoService.getOrderStatus(orderNo);
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderId);
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderNo);
String orderStatus = orderByOrderNo.getOrderStatus();
// 当订单状态处于未支付或超时已关闭时,更新订单状态,其他状态均不更新订单状态
if (!OrderStatusEnum.NOT_PAY.getType().equals(orderStatus) && !OrderStatusEnum.TIMEOUT_CLOSED.getType().equals(orderStatus)) {
log.info("订单状态 : {}", orderStatus);
}else {
//更新订单状态
orderInfoService.updateStatusByOrderNo(orderId, OrderStatusEnum.SUCCESS);
log.info("Stripe 订单:{} 状态更新成功", orderId);
orderInfoService.updateStatusByOrderNo(orderNo, OrderStatusEnum.SUCCESS);
log.info("Stripe 订单:{} 状态更新成功", orderNo);
}
if (orderByOrderNo.getTitle().startsWith("积分购买")){
// 查询当前订单的积分是否已添加
CreditsDetail creditsDetail = creditsService.queryDetailByTaskId(orderId);
CreditsDetail creditsDetail = creditsService.queryDetailByTaskId(orderNo);
if (Objects.isNull(creditsDetail)){
float quantity = totalAmount / ProductEnum.CreditsProduct.getPrice();
// 更新积分
@@ -416,21 +440,36 @@ public class StripeServiceImpl implements StripeService {
creditsService.insertToCreditsDetail(orderByOrderNo.getAccountId(),
CreditsEventsEnum.BUY_CREDITS.getName() + "--Stripe",
String.valueOf((Long.parseLong(CreditsEventsEnum.BUY_CREDITS.getValue()) * quantity)),
"positive", orderId);
"positive", orderNo);
log.info("用户:{} 积分信息更新成功", orderByOrderNo.getAccountId());
}
}else if (orderByOrderNo.getTitle().endsWith("Subscription") && orderByOrderNo.getAutoRenewal() == (byte)0){
String invoiceId = session.getInvoice();
Invoice invoice = Invoice.retrieve(invoiceId);
InvoiceLineItem invoiceLineItem = invoice.getLines().getData().get(0);
String description = invoiceLineItem.getDescription();
Long amount = invoiceLineItem.getAmount();
boolean b = createSubscriptionAndUpdateAccount(orderNo, orderByOrderNo.getAccountId(), description, amount);
// 邮件通知用户
if (b){
resp = sendEmail(null, "new", orderNo);
}
log.info("单次订阅订单:{} 处理完成", orderNo);
}
} catch (Exception e) {
log.info(e.getMessage());
resp = false;
}
return resp;
}
private void processExpiredOrder(String orderNo) {
private boolean processExpiredOrder(String orderNo) {
// 支付失败 通知商家的条件 1、会话过期 2、支付失败 3、这个用户在这个支付失败后再无支付成功的订阅
// 1、获取当前订单的支付状态
// String orderNo = session.getMetadata().get("orderId");
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderNo);
// 2、确认订单状态为支付失败
boolean resp = true;
if (orderByOrderNo.getOrderStatus().equals(OrderStatusEnum.FAILURE.getType())) {
// 3、判断失败订单之后再无成功的订单
QueryWrapper<OrderInfo> queryWrapper = new QueryWrapper<>();
@@ -448,13 +487,14 @@ public class StripeServiceImpl implements StripeService {
if (Objects.isNull(subscriptionInfo)
|| subscriptionInfo.getStatus().equals("incomplete")
|| subscriptionInfo.getStatus().equals("incomplete_expired")) {
sendEmail(orderNo);
resp = sendEmail(orderNo);
}else {
// todo 续订失败 应该不会走这里
sendEmail(subscriptionInfo.getSubscriptionId(), "fail_renewal");
resp = sendEmail(subscriptionInfo.getSubscriptionId(), "fail_renewal", null);
}
}
}
return resp;
}
@@ -497,6 +537,60 @@ public class StripeServiceImpl implements StripeService {
return subscriptionInfo;
}
/**
* 非自动续订订阅
* Stripe不会自动创建Subscription,所以没有subscription相关的回调无法触发订阅相关的处理代码
*/
public boolean createSubscriptionAndUpdateAccount(String orderNo, Long accountId, String description, Long amount){
QueryWrapper<SubscriptionInfo> qw = new QueryWrapper<>();
qw.eq("order_no", orderNo);
SubscriptionInfo subscriptionInfo = subscriptionInfoMapper.selectOne(qw);
if (Objects.isNull(subscriptionInfo)) {
String interval;
// 获取当前时间戳(秒级)
long currentPeriodStart = Instant.now().getEpochSecond();;
long currentPeriodEnd;
// InvoiceLineItem invoiceLineItem = invoice.getLines().getData().get(0);
if (description.equals(ProductEnum.DailySubscription.getName())
&& amount.equals(ProductEnum.DailySubscription.getPrice() * 100)){
interval = "day";
// 获取一天后的时间戳(秒级)
currentPeriodEnd = Instant.now().plus(1, ChronoUnit.DAYS).getEpochSecond();
}else if (description.equals(ProductEnum.MonthlySubscription.getName())
&& amount.equals(ProductEnum.MonthlySubscription.getPrice() * 100)){
interval = "month";
// 获取一天后的时间戳(秒级)
currentPeriodEnd = Instant.now().plus(1, ChronoUnit.MONTHS).getEpochSecond();
}else if (description.equals(ProductEnum.AnnualSubscription.getName())
&& amount.equals(ProductEnum.AnnualSubscription.getPrice() * 100)){
interval = "year";
// 获取一天后的时间戳(秒级)
currentPeriodEnd = Instant.now().plus(1, ChronoUnit.YEARS).getEpochSecond();
}else {
log.error("未知订阅类型");
return false;
}
subscriptionInfo = new SubscriptionInfo();
subscriptionInfo.setAccountId(accountId);
subscriptionInfo.setOrderNo(orderNo);
subscriptionInfo.setType(interval);
subscriptionInfo.setStatus("canceled");
subscriptionInfo.setCurrentPeriodStart(currentPeriodStart);
subscriptionInfo.setCurrentPeriodEnd(currentPeriodEnd);
subscriptionInfo.setCreateTime(LocalDateTime.now());
subscriptionInfoMapper.insertIgnore(subscriptionInfo);
log.info("创建订阅更新账号信息");
// 更新账号到期时间
boolean b = accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
// 更新账号身份和积分
if (b) accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), interval);
return true;
}
return true;
}
public SubscriptionInfo getSubscriptionInfoBySubId(String subId){
QueryWrapper<SubscriptionInfo> qw = new QueryWrapper<>();
qw.eq("subscription_id", subId);
@@ -704,7 +798,8 @@ public class StripeServiceImpl implements StripeService {
try {
customerId = getCustomer(username, userEmail);
SubscriptionCollection list = Subscription.list(SubscriptionListParams.builder()
.setCustomer(customerId).build());
.setCustomer(customerId).setLimit(20L)
.build());
return list.getData();
} catch (StripeException e) {
throw new RuntimeException(e);
@@ -832,28 +927,42 @@ public class StripeServiceImpl implements StripeService {
// return null;
}
public boolean sendEmail(String subscriptionId, String type) {
SubscriptionEmailParamsDTO emailParamsDTO = new SubscriptionEmailParamsDTO();
QueryWrapper<SubscriptionInfo> qwSI = new QueryWrapper<>();
qwSI.eq("subscription_id", subscriptionId);
List<SubscriptionInfo> subscriptionInfoList = subscriptionInfoMapper.selectList(qwSI);
public boolean sendEmail(String subscriptionId, String type, String orderNo) {
SubscriptionInfo subscriptionInfo;
if (subscriptionInfoList.isEmpty()){
return false;
}else {
List<SubscriptionInfo> activeSubscriptions = subscriptionInfoList.stream()
.filter(subscription -> "active".equals(subscription.getStatus()))
.collect(Collectors.toList());
if (activeSubscriptions.isEmpty()){
QueryWrapper<SubscriptionInfo> qwSI = new QueryWrapper<>();
if (!StringUtil.isNullOrEmpty(subscriptionId)) {
qwSI.eq("subscription_id", subscriptionId);
List<SubscriptionInfo> subscriptionInfoList = subscriptionInfoMapper.selectList(qwSI);
if (subscriptionInfoList.isEmpty()){
log.info("不发送邮件原因【subscriptionInfoList 为空】");
return false;
}else {
List<SubscriptionInfo> activeSubscriptions = subscriptionInfoList.stream()
.filter(subscription -> "active".equals(subscription.getStatus()))
.collect(Collectors.toList());
if (!StringUtil.isNullOrEmpty(type) && type.equals("cancel")){
subscriptionInfo = subscriptionInfoList.get(0);
}else if (activeSubscriptions.isEmpty()){
log.info("不发送邮件,原因:【当前邮件类型:{}, 但是状态为active的subscriptionInfo为空】", type);
return false;
}else {
subscriptionInfo = activeSubscriptions.get(0);
}
}
subscriptionInfo = activeSubscriptions.get(0);
}else if (!StringUtil.isNullOrEmpty(orderNo)) {
qwSI.eq("order_no", orderNo);
subscriptionInfo = subscriptionInfoMapper.selectOne(qwSI);
}else {
log.info("不发送邮件原因【入参中的subscriptionIdorderNo均为空】");
return false;
}
QueryWrapper<PaymentInfo> qwPI = new QueryWrapper<>();
qwPI.eq("order_no", subscriptionInfo.getOrderNo()).orderByDesc("id");
List<PaymentInfo> paymentInfos = paymentInfoMapper.selectList(qwPI);
if (paymentInfos.isEmpty()) {
log.info("不发送邮件原因【根据order_no:{},查询到的paymentInfos为空】", orderNo);
return false;
}
PaymentInfo paymentInfo = paymentInfos.get(0);
@@ -864,6 +973,7 @@ public class StripeServiceImpl implements StripeService {
}
if (!type.equals("reminder") && !type.equals("cancel") && paymentInfo.getNotified() == 1){
// 已经邮件通知过,直接返回
log.info("不发送邮件原因【type为{}order_no为{},且已经已经进行邮件通知】", type, orderNo);
return true;
}
@@ -872,6 +982,7 @@ public class StripeServiceImpl implements StripeService {
String language = account.getLanguage();
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(subscriptionInfo.getOrderNo());
SubscriptionEmailParamsDTO emailParamsDTO = new SubscriptionEmailParamsDTO();
emailParamsDTO.setUsername(userName);
emailParamsDTO.setOrderId(paymentInfo.getId().toString());
emailParamsDTO.setOrderRef("\"" + orderListLink + paymentInfo.getId().toString() + "\"");
@@ -880,7 +991,7 @@ public class StripeServiceImpl implements StripeService {
emailParamsDTO.setTotalFee(paymentInfo.getPayerTotal().toString());
emailParamsDTO.setLastOrderDate(DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodStart(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy));
emailParamsDTO.setEndOfPrepaidTerm(DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy));
setSubscriptionParams(paymentInfo, subscriptionInfo, orderByOrderNo, emailParamsDTO);
setSubscriptionParams(paymentInfo, subscriptionInfo, orderByOrderNo, emailParamsDTO, language);
SendEmailUtil.subscriptionEmailReminder(type, emailParamsDTO, language, account.getUserEmail());
@@ -906,6 +1017,7 @@ public class StripeServiceImpl implements StripeService {
qwPI.eq("order_no", orderNo);
List<PaymentInfo> paymentInfos = paymentInfoMapper.selectList(qwPI);
if (paymentInfos.isEmpty()) {
log.info("不发送邮件原因【根据order_no:{},查询到的paymentInfos为空】", orderNo);
return false;
}
PaymentInfo paymentInfo = paymentInfos.get(0);
@@ -976,7 +1088,7 @@ public class StripeServiceImpl implements StripeService {
emailParamsDTO.setCreateDate(String.valueOf(paymentInfo.getCreateTime()).replace("T", " "));
emailParamsDTO.setQuantity(String.valueOf(1));
emailParamsDTO.setTotalFee(paymentInfo.getPayerTotal().toString());
setSubscriptionParams(paymentInfo, subscriptionInfo, orderByOrderNo, emailParamsDTO);
setSubscriptionParams(paymentInfo, subscriptionInfo, orderByOrderNo, emailParamsDTO, language);
// 4、发邮件
SendEmailUtil.subscriptionEmailReminder("fail_renewal", emailParamsDTO, language, account.getUserEmail());
@@ -989,14 +1101,28 @@ public class StripeServiceImpl implements StripeService {
return true;
}
private void setSubscriptionParams(PaymentInfo paymentInfo, SubscriptionInfo subscriptionInfo, OrderInfo orderByOrderNo, SubscriptionEmailParamsDTO emailParamsDTO) {
private void setSubscriptionParams(PaymentInfo paymentInfo, SubscriptionInfo subscriptionInfo, OrderInfo orderByOrderNo,
SubscriptionEmailParamsDTO emailParamsDTO, String language) {
emailParamsDTO.setPaymentMethod(paymentInfo.getPaymentMethod());
emailParamsDTO.setLast4(paymentInfo.getLast4());
emailParamsDTO.setSubscriptionId(subscriptionInfo.getId().toString());
emailParamsDTO.setFailMessage(orderByOrderNo.getNote());
emailParamsDTO.setSubscriptionType(subscriptionInfo.getType());
emailParamsDTO.setStartDate(DateUtil.changeTimeStampFormat(orderByOrderNo.getCreateTime()));
emailParamsDTO.setNextPayDate(DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy));
if (subscriptionInfo.getStatus().equals("active")){
if (language.equals("ENGLISH")){
emailParamsDTO.setEndDate("When cancelled");
}else {
emailParamsDTO.setEndDate("手动取消订阅时");
}
}else {
emailParamsDTO.setEndDate(DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy_EEEE));
}
if (StringUtil.isNullOrEmpty(subscriptionInfo.getNextPayDate())){
emailParamsDTO.setNextPayDate("N/A");
} else {
emailParamsDTO.setNextPayDate(DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy));
}
emailParamsDTO.setRenewalTime(DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy));
}
@@ -1016,7 +1142,7 @@ public class StripeServiceImpl implements StripeService {
List<SubscriptionInfo> subscriptionInfos = subscriptionInfoMapper.selectList(qw);
for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
boolean b = sendEmail(subscriptionInfo.getSubscriptionId(), "reminder");
boolean b = sendEmail(subscriptionInfo.getSubscriptionId(), "reminder", null);
if (b) log.info("提前7天向用户 {} 发送续订通知邮件", subscriptionInfo.getAccountId());
}
}
@@ -1040,7 +1166,7 @@ public class StripeServiceImpl implements StripeService {
public String createSubscriptionTemp(String name, String email){
Stripe.apiKey = privateKey;
try {
OrderInfo orderInfo = orderInfoService.createOrderByProductId(1, PayTypeEnum.STRIPE.getType(), ProductEnum.DailySubscription, null);
OrderInfo orderInfo = orderInfoService.createOrderByProductId(1, PayTypeEnum.STRIPE.getType(), ProductEnum.DailySubscription, null, (byte)0);
// String customerId = getCustomer(name, email);
String paymentMethodCode = "pm_card_mastercard";