// Fetch price data. const pricesDiv = document.querySelector('#price-list'); fetch('/config') .then((response) => response.json()) .then((data) => { pricesDiv.innerHTML = ''; if(!data.prices) { pricesDiv.innerHTML = `

No prices found

This sample requires two prices, one with the lookup_key sample_basic and another with the lookup_key sample_premium

You can create these through the API or with the Stripe CLI using the provided seed.json fixture file with: stripe fixtures seed.json ` } data.prices.forEach((price) => { pricesDiv.innerHTML += `

${price.unit_amount / 100} / ${price.currency} / ${price.recurring.interval}
`; }); }) .catch((error) => { console.error('Error:', error); }); const createSubscription = (priceId) => { return fetch('/create-subscription', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ priceId: priceId, }), }) .then((response) => response.json()) .then((data) => { window.sessionStorage.setItem('subscriptionId', data.subscriptionId); window.sessionStorage.setItem('clientSecret', data.clientSecret); window.location.href = '/subscribe.html'; }) .catch((error) => { console.error('Error:', error); }); }