Merge branch 'dev/dev_xp' into dev/dev
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.*;
|
||||||
@@ -140,6 +138,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 +152,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);
|
||||||
@@ -387,22 +393,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());
|
||||||
|
|||||||
Reference in New Issue
Block a user