forked from 77media/video-flow
adds alipay
This commit is contained in:
parent
bd3d8ea33a
commit
41f9f228b3
@ -30,6 +30,19 @@ function HomeModule5() {
|
|||||||
const [billingType, setBillingType] = useState<"month" | "year">("month");
|
const [billingType, setBillingType] = useState<"month" | "year">("month");
|
||||||
const [plans, setPlans] = useState<SubscriptionPlan[]>([]);
|
const [plans, setPlans] = useState<SubscriptionPlan[]>([]);
|
||||||
const [loadingPlan, setLoadingPlan] = useState<string | null>(null); // 跟踪哪个计划正在加载
|
const [loadingPlan, setLoadingPlan] = useState<string | null>(null); // 跟踪哪个计划正在加载
|
||||||
|
|
||||||
|
// 监听支付完成消息
|
||||||
|
useEffect(() => {
|
||||||
|
const handlePaymentResult = (ev: MessageEvent) => {
|
||||||
|
if (ev.data.type === 'payment-result') {
|
||||||
|
// 支付完成后清除loading状态
|
||||||
|
setLoadingPlan(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('message', handlePaymentResult);
|
||||||
|
return () => window.removeEventListener('message', handlePaymentResult);
|
||||||
|
}, []);
|
||||||
|
|
||||||
// 从后端获取订阅计划数据
|
// 从后端获取订阅计划数据
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -95,12 +108,13 @@ function HomeModule5() {
|
|||||||
if (!result.successful || !result.data) {
|
if (!result.successful || !result.data) {
|
||||||
throw new Error("create checkout session failed");
|
throw new Error("create checkout session failed");
|
||||||
}
|
}
|
||||||
window.opener?.postMessage({
|
// 通知当前窗口等待支付(显示loading模态框)
|
||||||
|
window.postMessage({
|
||||||
type: "waiting-payment",
|
type: "waiting-payment",
|
||||||
paymentType: "subscription"
|
paymentType: "subscription"
|
||||||
}, "*");
|
}, "*");
|
||||||
// 2. 直接跳转到Stripe托管页面(就这么简单!)
|
// 在新标签页中打开Stripe支付页面,保持当前定价页面不变
|
||||||
window.location.href = result.data.checkout_url;
|
window.open(result.data.checkout_url, '_blank');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setLoadingPlan(null); // 出错时清除加载状态
|
setLoadingPlan(null); // 出错时清除加载状态
|
||||||
throw new Error("create checkout session failed, please try again later");
|
throw new Error("create checkout session failed, please try again later");
|
||||||
|
|||||||
@ -182,11 +182,17 @@ export default function CallbackModal({
|
|||||||
paymentTime: res.data.pay_time,
|
paymentTime: res.data.pay_time,
|
||||||
subscription: res.data.subscription
|
subscription: res.data.subscription
|
||||||
})
|
})
|
||||||
|
// 通知定价页面支付成功
|
||||||
|
window.postMessage({ type: 'payment-result', success: true }, '*')
|
||||||
} else if (res.data.payment_status === 'fail') {
|
} else if (res.data.payment_status === 'fail') {
|
||||||
setPaymentStatus(PaymentStatus.FAILED)
|
setPaymentStatus(PaymentStatus.FAILED)
|
||||||
|
// 通知定价页面支付失败
|
||||||
|
window.postMessage({ type: 'payment-result', success: false }, '*')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setPaymentStatus(PaymentStatus.FAILED)
|
setPaymentStatus(PaymentStatus.FAILED)
|
||||||
|
// 通知定价页面支付失败
|
||||||
|
window.postMessage({ type: 'payment-result', success: false }, '*')
|
||||||
}
|
}
|
||||||
} else if (paymentType === 'token') {
|
} else if (paymentType === 'token') {
|
||||||
// Token购买状态查询
|
// Token购买状态查询
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user