#jojilede
1 messages ยท Page 1 of 1 (latest)
Hello! Can you provide more details? What exactly are you trying to do?
this is a propery rental app so we charge the customer the initial payment and subscribe them to a later date which is their check-in date, and I want their inputs to be passed to the webhook.
You should probably use metadata for that: https://stripe.com/docs/api/metadata
i see, how do I retrieve it on the webhook?
The object inside the Event set to the Webhook Endpoint will have the metadata in its metadata property.
So if:
event = stripe.webhooks.constructEvent(buf, signature, webhookSecret);
const metadata = event.metadata ?
No, it would be in event.data.object.metadata: https://stripe.com/docs/api/events/object#event_object-data-object
btw is webhook really the best way to do our method, webhook will listen to other's session too right?
What do you mean?
like for now Person 1 and Person 2 is checking out to the page, will Person 1 webhook listen to Person 2 webhook too?
You'll receive separate Events for each customer, yes.
Not what I exactly mean but I can ask that again later in another thread coz you already helped me with the metadata and I don't want to keep you this long. Thank you so much!
๐
I'm happy to help you further if I can! Can you explain more about your use case?
ooh thanks! yes.
I want to see if the webhook is really the best thing for us. I don't want to end up doing an anti-pattern. So here is our process, since we are a long-term rental property site we charge the renter on the date of booking for the first month of their rent then schedule a subscription based on the check-in date. Is listening to the charge.succeeded event on the webhook a good way to initiate a subscriptionSchedule?
or is there a better recommendation to where I trigger the subscriptionSchedule?
Why are you creating the Subscription Schedule?
sample case is:
Date of booking: Jan 6, 2023
Checkin Date: feb 1, 2023
Checkout Date: March 31, 2023
We take the initial payment for the month of feb on Date of booking which is Jan 6 and subscribe them on march 01 for the month of march
Hi there. Taking over for Rubeus as they have to step out. Give me a bit to catch up on context here
thank you ๐
Hm ok interesting use case. So I think your idea with the subscription schedule will work. Another option is to create the subscription schedule immediately and have the first payment be phase 1 and the rest of the schedule (phase 2) could start on March 1
You could make the price in phase 1 like a yearly price or something with a billing period > 1 month to avoid being charged again on Feb 1
Then that phase will just end on March 1 and the monthly billing (phase 2) will start at that point
wow what a brain
yeah I tried that honestly and I didn't think of making it 1 year on phase 1
that was so helpful LOL
well
I ended up with this approach coz I couldn't get pass that subscriptionSchedule phases LOL
I'm gonna try that again ๐
by the way can you check if this subscriptionSchedule object is the same to what you're thinking?
Sure thing. I'm referring to this: https://stripe.com/docs/api/subscription_schedules
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
const subscriptionSchedule = await stripe.subscriptionSchedules.create({
customer: 'cus_MBUbxhQStirO4q',
start_date: 1673550493,
end_behavior: 'release',
phases: [
{
items: [
{
price: 'price_1MMwbTDTISXyBnp6jxGjMEQt',
quantity: 1,
},
],
end_date: oneyearFromNow,
},
{
items: [
{
price: 'price_1MMwbTDTISXyBnp6jxGjMEQt',
quantity: 2, // 2months
},
],
}
],
});
Well that first price would need to be a yearly price (ie. $x/year) and the end date (based on your example) would be march 1
And if you want to cover the schedule through March 31, then you'd only want to run phase 2 for 1 month
ah so I will create 2 prices with diff price_id?
Yeah
so there's no need for end_date on the phase 1 right?
const subscriptionSchedule = await stripe.subscriptionSchedules.create({
customer: 'cus_MBUbxhQStirO4q',
start_date: 1673550493,
end_behavior: 'release',
phases: [
{
items: [
{
price: 'YEARLY_PRICE_ID',
quantity: 1 // initial payment that also covers feb 01 - feb 28,
},
],
},
{
items: [
{
price: 'MONTHLY',
quantity: 1, // march 01 to march 31
},
],
}
],
});
customer: 'cus_MBUbxhQStirO4q',
start_date: 1673550493,
end_behavior: 'release',
phases: [
{
items: [
{
price: '', // $x/year price
quantity: 1,
},
],
end_date: '', // this should be march 1
},
{
items: [
{
price: '', /. $x/month price
quantity: 1, // 1 x the price per month
},
],
'iterations': 1 // only charge for 1 month since you've already paid for feb
}
],
});```
Something like ^
nice!
End date on the first phase lets you know when to begin the second
how do I know that phase 2 start?
oh ok
I see
wow that was super helpful!
I love you guys! Thank you so much!
Recommend giving this doc a read. It outlines everything: https://stripe.com/docs/billing/subscriptions/subscription-schedules
No problem!
RESOLVED ๐