Skip to content

Commit

Permalink
feat: use customer secret
Browse files Browse the repository at this point in the history
  • Loading branch information
psincraian committed Jun 30, 2024
1 parent 83be23e commit 64dbdd7
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions app/pricing/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,35 @@ declare global {
}
}

async function getCustomerSecret() {
const res = await fetch(`/api/v3/user/subscription-portal/customer-session`, {
method: "POST",
headers: {
"X-Api-Key": process.env.PEPY_API_KEY!
}
});

const body = await res.json();
return body["customerSecret"];
}

export default function Home() {
const {user, error} = useUser();
const [customerSecret, setCustomerSecret] = useState<null|String>(null);

useEffect(() => {
if (user !== null) {
getCustomerSecret().then(secret => setCustomerSecret(secret));
}
}, [user]);

console.log(user);
console.log("Customer Secret", customerSecret)
const stripePricingTable = (
<>
<stripe-pricing-table
pricing-table-id="prctbl_1O3NjqLkhgcLjWWE4QWZ1F1G"
publishable-key="pk_live_fGp4vBPOGSP5uIvvM2qXoQyZ006F0MCL4G"
customer-email={user?.email}
customer-session-client-secret={customerSecret}
></stripe-pricing-table>
</>
);
Expand Down

0 comments on commit 64dbdd7

Please sign in to comment.