#joel_best-practices

1 messages ยท Page 1 of 1 (latest)

polar socketBOT
#

๐Ÿ‘‹ 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. Thank you for your patience!

โฑ๏ธ We automatically close idle threads, which makes them read-only. Make sure you stick around to chat in realtime! If this thread is closed and you have another question you'll need to start a new thread.

๐Ÿ”— 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/1214187043014311976

๐Ÿ“ Have more to share? You can add more detail below, including code, screenshots, videos, etc.

tacit coyoteBOT
sharp relic
#

Hi, let me help you with this.

#

How are you creating the Subscriptions now?

nova spoke
#

Hi thanks for replying! Im using stripe webhooks

elif event_type == 'customer.subscription.created':
        print('Subscription created %s', event.id)

        mongo.insiderdata.users.update_one(
            {'stripe_customer_id': data_object.customer},
            {'$set': {
                'stripe_subscription_status': data_object.status,
                'subscription_plan': {
                    'plan_id': data_object.plan.id,
                    'plan_name': data_object.plan.nickname,
                    'amount': data_object.plan.amount,
                    'currency': data_object.plan.currency,
                },
                'subscription_dates': {
                    'start_date': data_object.start_date,
                    'end_date': data_object.current_period_end,
                },
                'has_trial': data_object.trial_end,
                'cancel_at_period_end': data_object.cancel_at_period_end,
            }}
        )
#

After stripe.checkout.Session.create

sharp relic
#

Are you creating Subscriptions via Stripe Checkout?

nova spoke
#

Thats right:


checkout_session = stripe.checkout.Session.create(
            line_items=[
                {
                    'price': price_id,
                    'quantity': 1,
                },
            ],
            mode='subscription',
            allow_promotion_codes=True,
            customer=stripe_customer_id,
            customer_email=email,
            metadata={
                'user_id': user['_id'],
            },
            subscription_data={
                "trial_period_days": trial_days,
            },
            success_url=url_for('index.konto', _external=True) + '?session_id={CHECKOUT_SESSION_ID}',
            cancel_url=url_for('index.konto', _external=True),
        )
sharp relic
#

Then a Subscription shouldn't really ever be in an incomplete state. Could you please share the Subscription ID sub_xxx?

nova spoke
#

I think it was this one

sub_1OqaguA20NWHSZe8JflFUgqB

polar socketBOT
slow sierra
#

Yeah looks like the payment declined on-session via Checkout, which can leave the subscription in this state. You need to bring the customer back on-session and re-confirm the intent

#

I think they can pay the invoice via the portal, which will active the subscription

nova spoke
#

Alright so if the status is incomplete they should get access to the customer portal, but not the extra features yet? The incomplete state can only be changed to active by manually checking out again? Stripe wont try again?

slow sierra
#

What do you mean by 'extra features'? You can create a portal session for any Customer object

The incomplete state can only be changed to active by manually checking out again? Stripe wont try again?
No we won't automatically retry the initial payment

nova spoke
#

Ah okay got you! Thanks you so much for the help ๐Ÿ™‚

#

Another question. Did i read somewhere that stripe retries to charge for the subscription x times if payments fail?

#

and will automatically send a 'customer.subscription.deleted' webhook if those x tries fail?

slow sierra
slow sierra
nova spoke
#

Ah thank you so much, just what i needed

#

You can close this now, all good now