#bobbyportis_code

1 messages ¡ Page 1 of 1 (latest)

late parrotBOT
#

👋 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/1331093338845216780

📝 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.

hoary flame
#

async def create_reverse_free_trial(self, user: User, extended: bool = False, hours: int = None) -> User:
"""
create an internal subscription with a certain trial period.
"""
logger.info(f"Creating (extended) reverse trial for user {user.kinde_user_id}")

    if not user.stripe_customer_id:
        raise CreateStripeCustomerError("User has no stripe customer ID")

    now = datetime.now()
    trial_end = now + timedelta(days=365)
    if extended:
        trial_end = now + timedelta(hours=hours)

    try:
        subscription = native_stripe.Subscription.create(
            customer=user.stripe_customer_id,
            items=[{
                "price": os.getenv("STRIPE_PRO_YEARLY_PRICE_ID"),
            }],
            trial_end=int(trial_end.timestamp()),
            cancel_at_period_end=True,
            metadata={
                "subscription_type": "reverse_trial",
                "extended": extended
            }
        )

        update_dict = {
            User.plan_start_date: now,
            User.plan_end_date: trial_end,
            User.trial_end_date: trial_end,
            User.latest_tier: SubscriptionTier.PRO,
            User.plan_cycle: Period.ONE_MONTH,
            User.stripe_subscription_id: subscription.id
        }

        return await user.update(Set(update_dict))

    except native_stripe.error.StripeError as e:
        logger.error(f"Stripe error creating reverse trial: {str(e)}")
        raise err_create_subscription_failed(e)
    except Exception as e:
        logger.error(f"Error creating reverse trial: {str(e)}")
        raise UpdateStripeCustomerError(e)
hybrid wolf
#

hello! Can you share example subscription ids for each of the scenarios you described? the subscription id will have the prefix sub_

hoary flame
#

sub_1QjXJ4DkAuZUHoK7dtAq8Dbz this is the one that sends the invoice when it shouldn't

#

and this one dones't when it ends:
sub_1QjXIRDkAuZUHoK7IO2ZD2sa

#

even though both are scheduled to cancelled

#

on their respective dates

hybrid wolf
#

taking a look!

#

both subscriptions have invoices created, can you share what are you using to determine if the invoice is sent?

late parrotBOT
hoary flame
#

cancelled_at_period_end parameter

#

if that's not the fix how does I just cancel it without allowing the user to be send a reminder or invoice?

#

thru email I mean

merry vale
#

Hi there, I'm also an engineer from Stripe.

#

To clarify, you want to use API to cancel a subscription immediately?

hoary flame
#

I'm using Stripe as a source of truth to track trial days and when it's ends. So I'm only creating a subscription for the purpose of tracking the trial days and want to cancel after trial_ended. Therefore, I don't want the customer to be sent invoices or emails about their trial, prompting them to add their payment method which is occuring when I extend their trial through creating a new stripe subscription where the trial days are <2 days.

merry vale
hoary flame
#

okay thanks