#john_subscription-paymentintent

1 messages ¡ Page 1 of 1 (latest)

quick steppeBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1293697967563346023

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

loud nest
#

Here is an example of how it should work:
I book today for Jan 1 to April 10 with $1000 rent and $500 security deposit. I should pay
$1500 today
$1000 Feb 1
$1000 Mar 1
$333 Apr 1

#

For question 1
I don't see any option in the docs to take and use payment info when creating a subscription. Will we need to make a different call first to take their payment info and set it as default, or something like that?

#

For question 2
According to these docs collection_method should be charged automatically, but when I check my dashboard it says the first invoice bills at subscription start date.

From these docs it looks like maybe I need to set auto_advance to true, but there's no option in the subscription create, and the invoice isn't returned so I can't access it with a second call.

pine hollow
#

Hi there! We'll be with you shortly.

quick steppeBOT
tepid lance
#

john_subscription-paymentintent

#

@loud nest I read what you said multiple times but I admit that you lost me overall.
The most common flow is
1/ Create the Subscription
2/ Look the associated first Invoice and its underlying PaymentIntent to get the client_secret
3/ Collect the payment client-side with PaymentElement

Can you clarify what the problem is exactly? You say you "can't access" but you haven't really shared the exact code and the exact issue

loud nest
#

Sure, one moment.

#

This is the most relevant code

      const subscriptionSchedule: Stripe.SubscriptionSchedule = await stripe.subscriptionSchedules.create({
        customer: customerId,
        end_behavior: 'cancel',
        expand: ['subscription'],
        auto_advance: true,
        start_date: new Date(2025, 0, 1).getTime()/1000, // Timestamp of start date Jan 1
        phases: [
          {
            items: [
              {
                // price: 'price_1Mr3YcLkdIwHu7ixYCFhXHNb',
                price_data: {
                  currency: 'usd',
                  product: 'prod_QvWhQQGUOC1qE6', // Generic rent product
                  recurring: { interval: 'month'}, // Probably change to 30 days
                  unit_amount: 1000,
                },
                quantity: 1,
              },
            ],
            add_invoice_items: [
              {
                price_data: {
                  currency: 'usd',
                  product: 'prod_QvWhQQGUOC1qE6', // Generic rent product
                  unit_amount: 500,
                },
                quantity: 1
              }
            ],
            end_date: new Date(2025, 3, 10).getTime()/1000, // Timestamp of end date. Apr 10
          }
        ],
      });
tepid lance
#

Perfect that's the piece missing. So you are not creating a Subscription. You are creating a SubscriptionSchedule

#

You also have start_date set to a future date so there's no upfront Invoice. It doesn't match what you were describing earlier at all right? You were saying someone should pay $1500 right now no?

loud nest
#

The last person I talked to said if I do a subscription schedule but return the the clientSecret from the paymentIntent for the first invoice that I would be able to confirm the payment immediately and that it would behave exactly as in my example.

#

So yes, I am still going for the exact behavior I described, but this is how I was told to approach it.

tepid lance
#

Sure sorry I am trying to teach you some of the crucial vocabulary to understand. If you say "I create a Subscription" it means using https://docs.stripe.com/api/subscriptions/create but you use a different API which comes with a different behaviour, that's all

So why are you putting a start date in the future if you want to charge someone immediately?

loud nest
#

Yes, I appreciate any instruction!

#

I am doing it that way because that's what I was suggested to do when I posted in best practices.

#

You can look a the thread if you want, #1293697967563346023 message
But I believe the idea was that if we set the duration to the correct length then stripe will calculate the payment correctly.

tepid lance
#

Okay then something was misunderstood somewhere. What you are doing right now is deferring the first $1500 payment to January first

loud nest
#

And we can get the behavior we want by triggering the first payment early.

#

Yes, that is what is happening in the current code, but the last person I talked to said we would be able to trigger that first payment immediately.

#

If this approach doesn't work or doesn't make sense I am totally open to a different approach. I'm just trying to follow what you folks advise for best practices.

tepid lance
#

Change your logic to design multiple phases that map to the exact amounts you want to charge at each date.
Right now you designed it so that the first payment is on January 1st which isn't what you want.
What you want to do is a lot harder than it looks and I don't think we have a really clean way of doing this today so I think the advice you got in that other thread was incorrect in multiple ways.

loud nest
#

Okay. So kind of back to square one. If you looked in the other thread this question will be familiar:
Do you think we should bill it as a single one-time payment plus a two phase subscription? Or somethinge else?

#

Perhaps a 3 phase subscription where we calculate the time between now and the second time they are billed, and set that as the length of the first phase?

tepid lance
#

I am not sure. I think the best approach is to try things in Test mode and iterate slowly until you get to the exact flow you want.
Step 1: create a SubscriptionSchedule that charges the right amount upfront.

loud nest
#

Okay, could you clarify that a little? Do you mean that the first charge is for the correct amount, or that they are billed immediately?

#

The add_invoice_items in my code does appear to work as intented to increase the amount of the first charge, so I think the example I gave already covers that.

tepid lance
#

I don't think it does. I think what it is doing right now is waiting January 1st to charge $1500 which is not what you want right?

loud nest
#

I'm saying the existing code charges correctly. You are correct that it does not charge at the correct time. That is what I wanted to know about your statement: which thing you were talking about.

#

It sounds like you are saying Step 1 is create a subscription schedule that charges immediately. Correct?

tepid lance
#

yes

#

And then we can tweak the SubscriptionSchedule as we go until we get to the exact state you want

#

Be patient, it's going to be extremely complex and I think we'll have to use multiple separate "hacks" because your flow is not supported at all by default

loud nest
#

Okay. So I think it's easy to do one that starts right away, but you're right, the problem is that by default it will send the next bill a month later, and we don't want to send that until the first month of the stay is over.

#

So the first thing that jumps to mind for me is to calculate the time until the second billing event, and make the first phase last that long.

#

Is that where you would start?

tepid lance
#

yes but that phase needs to be with a $0 Price so that nothing else is charged during that period. That's where we get into the "this requires hacks" that I said earlier

loud nest
#

Okay. What prevents me from extending the $1500 phase until the date of the second payment?

#

(I'm trying to understand why the $0 phase is needed)

tepid lance
#

a phase is mapped to a certain Price and itss duration. IF you have a $1000/month Price and you have a phase that starts now and ends on February 1st for example it will charge $1000 today, $1000 on November 9, $1000 on December 9, etc.

#

So my read is you want

  • first phase: $0/month Price. Have an add_invoice_items that charges $1500. Start immediately and end on the day you want to charge the normal price
  • second phase: $1000/month Price, starts at the end of the previous phase renews for X iterations (in your example X=2)
  • third phase: partial month with a custom Price for that partial amount you would calculate yourself
loud nest
#

Okay, yes. That all makes sense. It seems like I should also be able to set the interval (not sure if that's the official stripe word) of the first phase to match it's duration, but if that's not possible I'll do as you mentioned.

#

Thanks so much for all the info!

tepid lance
#

sure thing! Let me know how it goes