支付优化

This commit is contained in:
2024-11-19 17:08:16 +08:00
parent f6f759110f
commit 4d756d5624
4 changed files with 23 additions and 18 deletions

View File

@@ -18,7 +18,7 @@ public interface PaymentInfoService extends IService<PaymentInfo> {
void createPaymentInfoForAliPayHK(AlipayHKCallbackDTO alipayHKCallbackDTO);
String createPaymentInfoForStripe(Invoice invoice);
PaymentInfo createPaymentInfoForStripe(Invoice invoice);
PaymentInfo getPaymentInfoByOrderId(String orderId);

View File

@@ -176,7 +176,7 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
@Value("${stripe.private-key}")
private String privateKey;
public String createPaymentInfoForStripe(Invoice invoice){
public PaymentInfo createPaymentInfoForStripe(Invoice invoice){
Stripe.apiKey = privateKey;
// 获取transactionId,从sessionId更改为invoiceId
String invoiceId = invoice.getId();
@@ -221,9 +221,8 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
paymentInfo.setNotified(0);
baseMapper.insert(paymentInfo);
return orderNo;
}
return null;
return paymentInfo;
}

View File

@@ -298,11 +298,12 @@ public class StripeServiceImpl implements StripeService {
Invoice invoice = (Invoice) stripeObject;
if (event.getType().equals("invoice.paid")) {
// 新增支付成功的信息,返回orderNo表示该回调第一次被记录
String orderNo = paymentInfoService.createPaymentInfoForStripe(invoice);
PaymentInfo paymentInfo = paymentInfoService.createPaymentInfoForStripe(invoice);
if (!StringUtil.isNullOrEmpty(orderNo)) {
// 当前支付没有被通知时才需要发送通知邮件
if (paymentInfo.getNotified().equals(0)) {
// 更新t_order_info中的total_fee,记录该订单的累计付款金额
orderInfoService.updateTotalFeeByOrderNo(orderNo);
orderInfoService.updateTotalFeeByOrderNo(paymentInfo.getOrderNo());
// 邮件通知商家和用户
if (invoice.getBillingReason().equals("subscription_create")){
response = sendEmail(invoice.getSubscription(), "new");
@@ -614,8 +615,8 @@ public class StripeServiceImpl implements StripeService {
}
}
HashMap<String, String> resp = new HashMap<>();
resp.put("paymentMethod", null);
resp.put("last4", null);
resp.put("paymentMethod", "N/A");
resp.put("last4", "N/A");
return resp;
} catch (StripeException e) {
throw new RuntimeException(e);
@@ -697,6 +698,7 @@ public class StripeServiceImpl implements StripeService {
com.ai.da.mapper.primary.entity.Account account = accountMapper.selectById(subscriptionInfo.getAccountId());
String userName = account.getUserName();
String language = account.getLanguage();
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(subscriptionInfo.getOrderNo());
emailParamsDTO.setUsername(userName);
emailParamsDTO.setOrderId(paymentInfo.getId().toString());
@@ -708,7 +710,7 @@ public class StripeServiceImpl implements StripeService {
emailParamsDTO.setPaymentMethod(subscriptionInfo.getPaymentMethod());
emailParamsDTO.setSubscriptionId(subscriptionInfo.getId().toString());
emailParamsDTO.setSubscriptionType(subscriptionInfo.getType());
emailParamsDTO.setStartDate(changeTimeStampFormat(subscriptionInfo.getCreateTime()));
emailParamsDTO.setStartDate(changeTimeStampFormat(orderByOrderNo.getCreateTime()));
emailParamsDTO.setNextPayDate(changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy));
emailParamsDTO.setRenewalTime(changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy));