Skip to content

Commit

Permalink
cambios suscrip
Browse files Browse the repository at this point in the history
  • Loading branch information
carloquer committed Aug 2, 2024
1 parent d227eee commit 148a6fa
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions client/src/SubscriptionPlans.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import axios from 'axios';
import { loadStripe } from '@stripe/stripe-js';
import { url } from './components/Urls';
import Cookies from 'js-cookie';
import { decryptValue, encryptionKey } from './components/hashes';

// Asegúrate de que estas variables estén definidas en tu archivo .env o en variables de Vercel
const stripePromise = loadStripe(import.meta.env.VITE_STRIPE_PUBLIC_KEY);
Expand All @@ -17,11 +19,27 @@ const plans = [

const SubscriptionPlans = () => {
const navigate = useNavigate();
const [isLoggedIn, setIsLoggedIn] = useState(false);

useEffect(() => {
// Check if user is logged in
if (Cookies.get('$3s1.4')) {
const session = decryptValue(Cookies.get('$3s1.4'), encryptionKey);
if (session) {
setIsLoggedIn(true);
}
}
}, []);

const handleSelectPlan = async (priceId) => {
if (!isLoggedIn) {
navigate('/login');
return;
}

const stripe = await stripePromise;
try {
const response = await axios.post(`${url}/stripe/create-checkout-session`, {priceId });
const response = await axios.post(`${url}/stripe/create-checkout-session`, { priceId });
const sessionId = response.data.id;
const { error } = await stripe.redirectToCheckout({ sessionId });
if (error) {
Expand All @@ -40,7 +58,7 @@ const SubscriptionPlans = () => {
<div key={plan.plan} className="border p-6 rounded-lg shadow-lg">
<h2 className="text-xl font-semibold mb-4" style={{ color: '#336A41', fontFamily: 'Clear Sans Light, sans-serif' }}>{plan.name}</h2>
<p className="text-2xl mb-4">{plan.price}</p>
<ul className="mb-4">
<ul className="mb-4 list-disc list-inside" style={{ fontFamily: 'Clear Sans Light, sans-serif' }}>
{plan.features.map((feature, index) => (
<li key={index} className="mb-2">{feature}</li>
))}
Expand All @@ -52,7 +70,6 @@ const SubscriptionPlans = () => {
>
Seleccionar
</button>

</div>
))}
</div>
Expand Down

0 comments on commit 148a6fa

Please sign in to comment.