document.addEventListener('DOMContentLoaded', async () => { // Fetch the list of subscriptions for this customer. const {subscriptions} = await fetch('/subscriptions').then((r) => r.json()); // Construct and display each subscription, its status, last4 of the card // used, and the current period end. const subscriptionsDiv = document.querySelector('#subscriptions'); console.log(subscriptions); subscriptionsDiv.innerHTML = subscriptions.data.map((subscription) => { console.log(subscription); let last4 = subscription.default_payment_method?.card?.last4 || ''; return `
Status: ${subscription.status}
Card last4: ${last4}
If the last4 is blank, ensure webhooks are being handled. The default payment method is set in the webhook handler.Current period end: ${new Date(subscription.current_period_end * 1000)}
Update payment method