update pay function

This commit is contained in:
2025-11-20 08:33:26 +08:00
parent b0b227a5ef
commit 082e644534
3 changed files with 143 additions and 3 deletions

View File

@@ -270,6 +270,46 @@ export default function SubscriptionContentNew() {
try {
const price = priceInfo?.final_amount || getCurrentPrice(selectedPlan);
// 检查是否为免费升级(剩余价值足够抵扣新套餐价格)
if (price === 0 && priceInfo?.is_upgrade) {
const response = await fetch('/api/subscription/free-upgrade', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
credentials: 'include',
body: JSON.stringify({
plan_name: selectedPlan.name,
billing_cycle: selectedCycle,
}),
});
const data = await response.json();
if (data.success) {
subscriptionEvents.trackPaymentSuccessful({
planName: selectedPlan.name,
paymentMethod: 'free_upgrade',
amount: 0,
orderId: 'free_upgrade',
transactionId: 'free_upgrade',
});
toast({
title: '升级成功!',
description: data.message,
status: 'success',
duration: 5000,
isClosable: true,
});
onClose();
setTimeout(() => window.location.reload(), 2000);
return;
} else {
throw new Error(data.error || '免费升级失败');
}
}
subscriptionEvents.trackPaymentInitiated({
planName: selectedPlan.name,
paymentMethod: 'wechat_pay',
@@ -1122,7 +1162,9 @@ export default function SubscriptionContentNew() {
<HStack spacing={2}>
<Icon as={FaCheck} color="green.400" />
<Text color="green.400" fontSize="sm" fontWeight="medium">
{selectedPlan.displayName}
{priceInfo.final_amount === 0
? `恭喜!您的当前订阅剩余价值足够直接升级到${selectedPlan.displayName},无需支付额外费用!`
: `升级到${selectedPlan.displayName},立即生效!按差价补缴费用`}
</Text>
</HStack>
</Box>
@@ -1293,7 +1335,9 @@ export default function SubscriptionContentNew() {
bgGradient: 'linear-gradient(135deg, #F4E3A7, #D4AF37)',
}}
>
{priceInfo?.is_upgrade && priceInfo?.final_amount === 0
? '立即免费升级'
: '创建微信支付订单'}
</Button>
</VStack>
) : (