#jojilede

1 messages ยท Page 1 of 1 (latest)

tired starBOT
sweet terrace
#

Hello! Can you provide more details? What exactly are you trying to do?

mighty relic
#

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.

sweet terrace
mighty relic
#

i see, how do I retrieve it on the webhook?

sweet terrace
#

The object inside the Event set to the Webhook Endpoint will have the metadata in its metadata property.

mighty relic
#

So if:
event = stripe.webhooks.constructEvent(buf, signature, webhookSecret);

#

const metadata = event.metadata ?

sweet terrace
mighty relic
#

btw is webhook really the best way to do our method, webhook will listen to other's session too right?

sweet terrace
#

What do you mean?

mighty relic
#

like for now Person 1 and Person 2 is checking out to the page, will Person 1 webhook listen to Person 2 webhook too?

sweet terrace
#

You'll receive separate Events for each customer, yes.

mighty relic
#

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!

#

๐Ÿ’Ÿ

sweet terrace
#

I'm happy to help you further if I can! Can you explain more about your use case?

mighty relic
#

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?

sweet terrace
#

Why are you creating the Subscription Schedule?

mighty relic
#

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

quasi plume
#

Hi there. Taking over for Rubeus as they have to step out. Give me a bit to catch up on context here

mighty relic
#

thank you ๐Ÿ˜„

quasi plume
#

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

mighty relic
#

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

quasi plume
#

Haha no worries!

#

Your approach would also work

mighty relic
#

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?

quasi plume
mighty relic
#
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
        },
      ],
    }
  ],
});
quasi plume
#

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

mighty relic
#

ah so I will create 2 prices with diff price_id?

quasi plume
#

Yeah

mighty relic
#

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
        },
      ],
    }
  ],
});
quasi plume
#
  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 ^

mighty relic
#

nice!

quasi plume
#

End date on the first phase lets you know when to begin the second

mighty relic
#

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!

quasi plume
#

No problem!

mighty relic
#

RESOLVED ๐Ÿ˜„