#jojilede
1 messages ยท Page 1 of 1 (latest)
Hello
First, please redact your secret key above immediately
Even though it is your test key it gives access to your account
Recommend rolling it too
i see
Next, let's back up and first talk about what you are trying to accomplish? Can you explain what you are trying to do?
I want to charge the customer for an initial payment and subscribe them to a later date.
because they are renting properties and we want to take initial payment then schedule to start their subscription when their check-in starts.
Got it so you are first taking a one-off payment
yes ๐
Then want a Subscription in the future
yes again ๐
Then yes as far as I can tell your code looks good and a Sub Schedule is the right thing to use! Have you tried testing this yet?
Instead of a picture of code can you provide the code between three backticks like this
It is much easier for us to read and work with like that
oh ok
const webhookHandler = async (req, res) => {
if (req.method === 'POST') {
const buf = await buffer(req);
const signature = req.headers['stripe-signature'];
const webhookSecret = process.env.STRIPE_WEBHOOK_SIGNING_SECRET;
let event;
try {
if(!signature || !webhookSecret) return
event = stripe.webhooks.constructEvent(buf, signature, webhookSecret);
switch(event.type) {
case 'checkout.session.expired':
// Handle the checkout.session.expired event
res.redirect('/');
break;
case 'charge.succeeded':
// Handle the charge.succeeded event
const subscriptionSchedule = await stripe.subscriptionSchedules.create({
customer: 'cus_MBUbxhQStirO4q',
start_date: 1673541069,
end_behavior: 'release',
phases: [
{
items: [
{
price: 'price_1MMwbTDTISXyBnp6jxGjMEQt',
quantity: 1,
},
],
iterations: 12,
},
],
});
}
} catch(error){
console.log(error)
return res.status(400).send(`Webhook Error: ${error.message}`);
}
console.log('event', event)
res.status(200).send()
} else {
res.setHeader('Allow', 'POST');
res.status(405).end('Method Not Allowed');
}
};
export default cors(webhookHandler)
Okay
And are you sure your webhook handler is getting hit at all?
Next step would be to add some logs in your handler
I'd add one right at the beginning of the endpoint and then another within your charge.succeeded case
I'm using stripe vscode extension
so if my folder structure is like this:
I should forward it to localhost:3000/api/payment/webhooks right?
That should depend on what you are using for your Server and how your endpoint is set up in your project
you know what? I'm just dumb I panic
it's a scheduled subscription so it should be on the scheduled tab! I'm so sorry!
I'm sorry for wasting your time sir!
thank you so much!