支付优化

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

@@ -782,7 +782,8 @@ 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 kimEmail = "kimwong@code-create.com.hk"; // String merchantEmail = "kimwong@code-create.com.hk";
String merchantEmail = "xupei3360@163.com";
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();
@@ -798,7 +799,7 @@ public class SendEmailUtil {
user.setDestination(new String[]{receiverAddress}); user.setDestination(new String[]{receiverAddress});
SendEmailRequest merchant = new SendEmailRequest(); SendEmailRequest merchant = new SendEmailRequest();
merchant.setFromEmailAddress(SEND_ADDRESS); merchant.setFromEmailAddress(SEND_ADDRESS);
merchant.setDestination(new String[]{kimEmail}); merchant.setDestination(new String[]{merchantEmail});
Template templateUser = new Template(); Template templateUser = new Template();
Template templateMerchant = new Template(); Template templateMerchant = new Template();
switch (type) { switch (type) {
@@ -848,12 +849,15 @@ public class SendEmailUtil {
templateMerchant.setTemplateData(JSON.toJSONString(subscriptionEmailParamsDTO)); templateMerchant.setTemplateData(JSON.toJSONString(subscriptionEmailParamsDTO));
merchant.setTemplate(templateMerchant); merchant.setTemplate(templateMerchant);
// 返回的resp是一个SendEmailResponse的实例与请求对象对应 if (!type.equals("cancel")){
SendEmailResponse respUser = client.SendEmail(user); // 返回的resp是一个SendEmailResponse的实例与请求对象对应
// todo 暂时先不发商家邮件 SendEmailResponse respUser = client.SendEmail(user);
// SendEmailResponse respMerchant = client.SendEmail(merchant); log.info("邮件发送结果toUser###{}", SendEmailResponse.toJsonString(respUser));
log.info("邮件发送结果toUser###{}", SendEmailResponse.toJsonString(respUser)); }
// log.info("邮件发送结果toMerchant###{}", SendEmailResponse.toJsonString(respMerchant)); if (!type.equals("reminder")){
SendEmailResponse respMerchant = client.SendEmail(merchant);
log.info("邮件发送结果toMerchant###{}", SendEmailResponse.toJsonString(respMerchant));
}
} catch (TencentCloudSDKException e) { } catch (TencentCloudSDKException e) {
log.info("邮件发送失败###{}", e.toString()); log.info("邮件发送失败###{}", e.toString());
throw new BusinessException("failed.to.send.mail"); throw new BusinessException("failed.to.send.mail");

View File

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

View File

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

View File

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