#bryanschreiner_best-practices

1 messages ยท Page 1 of 1 (latest)

placid lilyBOT
#

๐Ÿ‘‹ 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/1219379786955096145

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

vagrant oasis
#

First question, is it recommended to go this route (add a card, set as default, create subscription after) and 2) can you help me understand why my subscriptions are not starting and why the invoice is left to open? I'm trying to mirror the same functionality that the checkout session has

#

I can send whatever code is helpful

frozen bearBOT
lime lantern
#

Hello, can you send me the ID of a subscription that you tried this with? That sounds like it should work on its surface

vagrant oasis
#

sub_1OvmS9FGTemLEdoK8kSPEacS

#

can you tell me about #7 confirm subscription from the client side?

#

that seems like something i wouldn't expect

#
      customerId: workspace.customerId,
      paymentBehavior: 'default_incomplete',
      trialPeriod: trialPeriod || 0,
      items: [
        {
          price: priceId,
          quantity,
        },
      ],
      expand: ['latest_invoice.payment_intent'],```
#

This is what i'm doing to create the subscription, and I'm not confirming it or passing anything back to the front end after this

lime lantern
#

So basically, your method is fine but you would also want to call /pay on the invoice or manually confirm the invoice's payment intent client side

vagrant oasis
#

we are doing some 3rd party tax calculation in stripe. Another team member was telling me about it but i don't understand it fully. I think we charge the amount and start the subscription wiht the checkout session, but it doesn't finalize for an hour

lime lantern
#

Just to double check, have you talked with Avalara about what needs to happen when creating subscriptions directly yourself to make sure the tax gets applied correctly?

vagrant oasis
#

i have not, no

lime lantern
#

You should be able to do this any which way but they may have restrictions on which of our integration paths they can do this on

vagrant oasis
#

ok i'll check with them

#

i was planning on just trying it out and seeing if it worked and then reaching out if I had issues.

#

What is /pay?

#

invoice/pay endpoint?

lime lantern
#

Yes, sorry meant to link it but am bouncing between a couple of threads.

vagrant oasis
#

no worries at all, i appreciate the help!

placid lilyBOT
vagrant oasis
#

do you have that documentation?

charred wagon
#

๐Ÿ‘‹ Stepping in for my teammate

vagrant oasis
#

I'm confused on this. I see in stripe my payment has requires_confirmation but i'm not sure why. Does that mean the customer has to do something? I wasn't expecting a customer to have to do anything after submitting a credit card

#

pi_3OvnIlFGTemLEdoK13IWn1cp

charred wagon
#

Out of curiosity, how will customers provide payment details when this is live? The reason I ask is I see the payment method used for this customer's subscription was added via the Dashboard directly (vs. collecting it using the PaymentElement and latest_invoice.payment_intent.client_secret).

vagrant oasis
#

Oh i'm just testing this in a development environment, they will add them through the app UI with the payment element

#

creating a setup intent to add the payment method, and then it'll get saved as the default payment method before calling the create subscription endpoint on the server

charred wagon
#

Hm, hold on a second. You shouldn't need to create a SetupIntent at all, unless there's a long period of time between when you expect a customer to provide their payment details and when their subscription is created

vagrant oasis
#

oh let me know if that's the case, I thought I needed to create a setup intent if I wanted to display the payment element

charred wagon
#

Ah, I see! No, no need to create a SetupIntent in addition to the Subscription. When you create the Subscription with default_incomplete, you can expand latest_invoice.payment_intent and use the PaymentIntent's client secret to render the PaymentElement

vagrant oasis
#

In more detail, my flow is 1) request a setup intent to add a card 2) client side confirms card details and submits it via the server 3) client sends id to the backend to set this payment method as the default for the customer 4) create a subscription

#

Should the flow be to create a subscription or retrieve it every time I load the checkout page?

charred wagon
#

Alternatively, you can make a separate call to update the Customer after completing the first payment on the subscription

vagrant oasis
#

Will this be compatible with Avalara and how we keep our invoices open for an hour before finalizing them so that we can charge tax if applicable?

#

my checkout flow has a "monthly" or "yearly" toggle which is actually different priceIds in stripe, so I'd rather not create a subscription before collecting payment details

charred wagon
vagrant oasis
#

I have the second option working, but the problem earlier in the thread that I was running up against was that it was just leaving the invoice open and wasn't starting the subscription. I'm trying to figure out how to start the subscription but also allow Avalara to update the invoice if needed

#

I haven't yet tried calling /pay on the invoice

charred wagon
#

Gotcha, okay. If you have the deferred intent flow working, I recommend testing it once more so you have a PaymentMethod that was created via the Element (vs. the Dashboard)

vagrant oasis
#

i'm not sure I follow, I'm not using the payment method as part of the subscription create call

#
      customerId: workspace.customerId,
      paymentBehavior: 'default_incomplete',
      trialPeriod: 0,
      items: [
        {
          price: priceId,
          quantity,
        },
      ],
      expand: ['latest_invoice.payment_intent'], 
    })```
#

And before this I am just setting the payment method as the default on the stripe customer

#

I'll recreate it again but i'm not sure why that would work

charred wagon
#

Oh, I was a little confused when you said you're using the deferred intent flow since the PI you shared is tied to an invoice > Subscription > Customer, where the PM on that customer was not created via Elements

vagrant oasis
#

that is correct just for testing, but in my app it would be created via elements.

#

I'm not following why that would affect a subscription getting created with the code I sent you above

charred wagon
vagrant oasis
#

what does that look like to the end user? Can I mimick that server side?

#

I have a lot of front end calls and I'd rather keep things server side to eliminate bugs around users refreshing or losing connection, etc

#

The other person in this chat recommended invoice/pay or auto_advance. I'll admit I'm still relatively new to stripe so I'm looking for best practices

charred wagon
vagrant oasis
#

Ok. I can wire it up to work like that. I wasn't expecting it to come front end and require the client to confirm the payment but I can do that

charred wagon
vagrant oasis
#

if i finalize the payments server side, i'm assuming that would break the integration with avalara, is that correct?

charred wagon
#

what would break exactly?

vagrant oasis
#

i don't want to finalize the invoice before taxes are calculated. we leave it open for an hour

charred wagon
#

You'll need to get a little creative with this, as the first invoice for Subscriptions will auto finalize if the collection method is charge_automatically.

vagrant oasis
#

I'm trying to mimick what the checkout session does, any tips there?

charred wagon
#

You could create a subscription with trial_end a few seconds into the future. The first invoice will thus be a $0 invoice and once the trial is over, the first non-zero invoice will be created with a one-hour draft period

vagrant oasis
#

what does the checkout session do behind the scenes?

charred wagon
#

With Checkout, a subscription isn't created until a customer pays/completes the Checkout Session

vagrant oasis
#

so is that a possibility to do the same thing?

placid lilyBOT