Skip to content

Commit

Permalink
registro de pago en la BD
Browse files Browse the repository at this point in the history
  • Loading branch information
RyuDSora committed Aug 11, 2024
1 parent 454d2d2 commit 4ec38c9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
1 change: 1 addition & 0 deletions client/src/SubscriptionPlans.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const SubscriptionPlans = () => {

const stripe = await stripePromise;
try {
sessionStorage.setItem('priceId',priceId);
const response = await axios.post(`${url}/stripe/create-checkout-session`, { priceId });
const sessionId = response.data.id;
const { error } = await stripe.redirectToCheckout({ sessionId });
Expand Down
55 changes: 31 additions & 24 deletions client/src/SuccessPage.jsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
import { useEffect } from 'react';
import { useNavigate, Link } from 'react-router-dom';
import axios from 'axios';
import { Button } from 'react-bootstrap';
import { encryptionKey,decryptValue } from './components/hashes';
import Cookies from 'js-cookie';
import { URLsuscription } from './components/Urls';

const SuccessPage = () => {
const navigate = useNavigate();
const saveSubs = async() =>{
const user_id = parseInt(decryptValue(Cookies.get('#gt156'),encryptionKey));
const plan_id = sessionStorage.getItem('priceId');
const subscription_date = new Date();
const status = true;

useEffect(() => {
const handlePageLoad = async () => {
try {
// Obtener el token de autenticación del usuario
const token = localStorage.getItem('token');

// Enviar una solicitud al servidor para limpiar el carrito y registrar la orden
await axios.get(`${import.meta.env.VITE_API_URL}/success`, {
headers: {
Authorization: token,
},
});
} catch (error) {
console.error('Error al procesar la orden:', error);
}
};

handlePageLoad();
}, [navigate]);
const response = await fetch(URLsuscription, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ user_id, plan_id, subscription_date, status }),
});

if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || 'Error al registrar usuario');
}
try {

} catch (error) {
console.log(error);

}
navigate('/')
}
return (
<main className="grid min-h-full place-items-center bg-white px-6 py-24 sm:py-32 lg:px-8">
<div className="text-center">
Expand All @@ -35,13 +42,13 @@ const SuccessPage = () => {
¡Tu pago se ha realizado con éxito! Gracias por tu compra.
</h1>
<div className="mt-10 flex items-center justify-center gap-x-6">
<Link
to="/"
<Button
onClick={() => saveSubs()}
className="rounded-md px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-green-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2"
style={{ backgroundColor: '#336A41', fontFamily: 'Clear Sans Light, sans-serif' }}
>
Ir al inicio
</Link>
</Button>
</div>
</div>
</main>
Expand Down

0 comments on commit 4ec38c9

Please sign in to comment.