← back to NationalPaperHangers

scripts/stripe-events-binary.js

18 lines

const path=require('node:path');require('dotenv').config({path:path.resolve(__dirname,'..','.env')});
const Stripe=require('stripe');const s=new Stripe(process.env.STRIPE_SECRET_KEY,{apiVersion:'2024-10-28.acacia'});
const url='https://nationalpaperhangers.com/webhooks/stripe';
const events=['payment_intent.succeeded','payment_intent.payment_failed','payment_intent.canceled','checkout.session.completed','customer.subscription.created','customer.subscription.updated','customer.subscription.deleted','invoice.payment_succeeded','invoice.payment_failed','account.updated'];
(async()=>{
  for(let n=1;n<=events.length;n++){
    const sub=events.slice(0,n);
    try{
      const ep=await s.webhookEndpoints.create({url,enabled_events:sub});
      console.log(`OK n=${n}`,sub[n-1],'→',ep.id);
      await s.webhookEndpoints.del(ep.id);
    }catch(e){
      console.log(`FAIL n=${n}`,sub[n-1],'→',e.message.slice(0,150));
      break;
    }
  }
})();