🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🔧 AI Nachrichten ChatGPT automatically logged out [Fix](12.09.2026 um 17:09 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
🪟 Windows TippsServertimeout in Outlook über 10 Minuten verlängern(12.09.2026 um 15:10 Uhr)
🪟 Windows ServerSchatten-KI: Verborgene Sicherheitsrisiken minimieren - BornCity(13.09.2026 um 00:31 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🔧 AI Nachrichten ChatGPT automatically logged out [Fix](12.09.2026 um 17:09 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
🪟 Windows TippsServertimeout in Outlook über 10 Minuten verlängern(12.09.2026 um 15:10 Uhr)
🪟 Windows ServerSchatten-KI: Verborgene Sicherheitsrisiken minimieren - BornCity(13.09.2026 um 00:31 Uhr)

🔧 Programmierung 🕛 vor 2 Jahren 12 Min Lesezeit
0

How to setup Stripe subscriptions with Django and React

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




what we will be building



Recently I added a subscription model to one of my projects,



New users are welcomed by an ‘upgrade’ button next to their user button. Clicking this will redirect them to a Stripe Checkout page, like so:





  • Install the stripe-cli by following the official guide






    Creating a Checkout Session



    If you do not have a Django project setup please checkout Django’s guide on getting started



    Let’s create another endpoint for this:




    CODE
    def customer_portal(request):
    stripe.api_key = '<stripe-api-key>'

    try:
    session = stripe.billing_portal.Session.create(
    customer=request.user.customer.source_id,
    return_url=settings.CLIENT_URL + '/settings',
    )
    except Exception as e:
    return JsonResponse({'error': str(e)}, status=400)

    return JsonResponse({'url': session.url}, status=201)






    Make sure to enable the portal in your stripe settings



    Make sure your application takes advantage of these new values in your production environment.



    Congratiulations you now have a working subscription in your project!






    Final notes



    You are now ready to go, but there are some potential edge cases you want to consider handeling.






    Canceled subscriptions that are still active



    When a user cancels their subscription they still have access till the end of the subscription period, you might want to inform the user of this. Stripe provides us with some additional values, which we can add to our models.



    First we update our models:




    CODE
    class Subscription(models.Model):
    # ...

    cancel_at_period_end = models.BooleanField(default=False)
    cancel_at = models.DateTimeField(blank=True, null=True)






    cancel_at_period_end indicates that our subscription will expire at the end of the billing period and cancel_at indicates at what date this will happen.



    in our services we should also handle this to ensure these values are updated accordingly:




    CODE
    def handle_subscription_updated(event):
    # ...

    subscription.cancel_at_period_end = stripe_subscription.cancel_at_period_end
    subscription.cancel_at = datetime.fromtimestamp(
    stripe_subscription.cancel_at) if stripe_subscription.cancel_at else None

    # ...






    Next in our frontend we can handle it as such, where we render an alert if cancel_at_period_end:




    CODE
    subscription.cancel_at_period_end && (
    <Alert>
    <AlertCircleIcon className="h-4 w-4" />
    <AlertTitle>Your subscription has been canceled</AlertTitle>
    <AlertDescription>
    You can continue using our services till the end if your current billing period. Your subscription
    will end on {format(new Date(subscription.cancel_at), 'MMMM dd, yyyy')}
    </AlertDescription>
    </Alert>
    )






    Which should look something like this:





    To see this example in action or if you are simply in need of a resume go checkout my latest project over at CV Forge!

    Vollständiger Original-Bericht
    Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
    ↗ Original-Artikel auf dev.to lesen
  • Wie bewertest du diesen Beitrag?
    1 Klick Feedback
    Teilen mit Netzwerk & Team:

    Community-Analysen & Experten-Meinungen 0

    Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
    Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
    Community Pulse: Relevanz-Einschätzung
    1 Klick Experten-Votum
    🔴 Akute Relevanz 0%
    🟡 In Evaluierung 0%
    🟢 Keine Auswirkung 0%
    Spannende Innovation 0%
    Verwandte Story-Cluster & Quellen (Vektor-KI)
    Port 8095 Engine
    1 Quelle
    ChatGPT automatically logged out [Fix]
    1 Quelle
    Windows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC
    1 Quelle
    Sysinternals für Linux: Microsoft bringt 15 Diagnose-Tools auf Linux - ad-hoc-news.de
    Ähnliche Beiträge
    🔍 Verwandte News

    Auch interessante Nachrichten How to setup Stripe subscriptions with Django and React

    Thematisch verwandte Begriffe: setup, Stripe, subscriptions, with · 6 Treffer

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...