#alexg_code

1 messages ยท Page 1 of 1 (latest)

queen fableBOT
#

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

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

vernal spruce
#
    const usageSubscriptions = await stripe.subscriptions.create({
        customer: customerID,
        items: [
            {
                price: usageTier.SEATS,
            },
            {
                price: usageTier.DATABASE_ENTRIES,
            },
            {
                price: usageTier.API_REQUESTS,
            },
            {
                price: usageTier.BANDWIDTH,
            },
            {
                price: usageTier.ASSET_STORAGE,
            },
        ],
        metadata: {
            project_id: projectID,
            project_slug: projectDetails.slug,
            project_admin_link: `${config.ADMIN_URL}/admin/content/cloud_projects/${projectDetails.id}`,
            project_hubspot_link: `https://app.hubspot.com/contacts/${config.HUBSPOT_DASHBOARD_ACCOUNT}/deal/${projectDetails.hubspot_deal_id}`,
        },
        ...(subscription.trial_end && { trial_end: subscription.trial_end }),
    });
#

here is where the usages subscription is created by the handler that fires on the checkout.session.completed webhook

stone yacht
#

Hi, if you've collected the payment method, Stripe would attach the payment method to the customer. However, it looks like you're talking about Stripe Checkout, https://docs.stripe.com/billing/quickstart with checkout.session.completed. However, the code you shared is using our direct API to create a subscription.

vernal spruce
#

here is an example of a payment that failed as it has no payment method attached

stone yacht
#

Can you confirm which you're using?

vernal spruce
#

so first the customer goes through a checkout -> base subscription is created

#

checkout.session.completed webhook fires

#

our api then catches the succesful webhook for the successful payment

#

We then create second subscription directly with the api that is attached to the same customer for which we record usage charges

#

ideally, what will then happen is that it attempts to use the customer's saved payment method to pay for that second subscription whenever they have accrued usages

#

So i have the customer's payment method on file

#

but i need to it be attached to this second subscription when it gets created

#

becuase what happens now is when they have a non-zero charge for usages the payment fails the first time and the customer has to go and manually enter their payment details again through the generated checkout in the stripe email

stone yacht
vernal spruce
#

hmmm, interesting ๐Ÿค”

#

ok ill give it a try

#

ill try do it manualy in the dashboard first and if that works then ill do it automatically when the subscription is created

#

TYVM ๐Ÿ‘