From 58af5c557059fbd95d7cfc1d589c2a8cf44f8c25 Mon Sep 17 00:00:00 2001 From: xupei Date: Mon, 28 Apr 2025 14:56:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=BC=98=E6=83=A0=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/da/service/impl/StripeServiceImpl.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java b/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java index 5290b097..d8219bdb 100644 --- a/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java @@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.google.gson.Gson; import com.stripe.Stripe; +import com.stripe.exception.InvalidRequestException; import com.stripe.exception.SignatureVerificationException; import com.stripe.exception.StripeException; import com.stripe.model.*; @@ -1171,6 +1172,13 @@ public class StripeServiceImpl implements StripeService { emailParamsDTO.setFailMessage(orderByOrderNo.getNote()); emailParamsDTO.setSubscriptionType(subscriptionInfo.getType()); emailParamsDTO.setStartDate(DateUtil.changeTimeStampFormat(orderByOrderNo.getCreateTime())); + if (subscriptionInfo.getType().equals("month")){ + emailParamsDTO.setRenewalFee(String.valueOf(500)); + } else if (subscriptionInfo.getType().equals("year")){ + emailParamsDTO.setRenewalFee(String.valueOf(5000)); + } else { + emailParamsDTO.setRenewalFee(emailParamsDTO.getTotalFee()); + } if (subscriptionInfo.getStatus().equals("active")){ if (language.equals("ENGLISH")){ emailParamsDTO.setEndDate("When cancelled"); @@ -1408,6 +1416,7 @@ public class StripeServiceImpl implements StripeService { CouponCreateParams.Builder couponParams = CouponCreateParams.builder() // 任何客户只能用一次这个优惠券 .setDuration(CouponCreateParams.Duration.ONCE) + // percent_off 与 amount_off 不能同时设置 .setPercentOff(BigDecimal.valueOf(createCouponDTO.getPercentOff())); if (Objects.nonNull(createCouponDTO.getTimestamp())){ couponParams.setRedeemBy(createCouponDTO.getTimestamp()); @@ -1605,4 +1614,22 @@ public class StripeServiceImpl implements StripeService { return productCouponsMapper.selectPage(new Page<>(queryCouponsPageDTO.getPage(), queryCouponsPageDTO.getSize()), queryWrapper); } + + @Transactional + public void deleteCoupon(Long id){ + Stripe.apiKey = privateKey; + ProductCoupons productCoupons = productCouponsMapper.selectById(id); + if (Objects.isNull(productCoupons)){ + throw new BusinessException("unknown promotion code"); + } + try { + Coupon coupon = Coupon.retrieve(productCoupons.getCouponId()); + coupon.delete(); + log.info("coupon {} 删除成功", productCoupons.getCouponId()); + productCouponsMapper.deleteById(id); + } catch (StripeException e) { + log.error("未知coupons,无法通过couponId: {} 获得Coupons", productCoupons.getCouponId()); + } + } + }