Home > Mobile >  Is it possible to redirect to a stripe checkout page without AJAX in Django?
Is it possible to redirect to a stripe checkout page without AJAX in Django?

Time:11-05

I have a FormView where I do some stuff after submitting the form and then I want to redirect to a stripe checkout. Is it possible without Javascript?

class ApplicationForm(forms.ModelForm):
    class Meta:
        model = Application
        fields = "email", "name"


    def save(self, commit=True):
        application = super().save(commit=commit)
        checkout_session = stripe.checkout.Session.create(...) # I'm creating the session here and do some other stuff with the form input
        return application

class ApplicationView(CreateView):
    template_name = "application.html"
    form_class = ApplicationForm

    def get_success_url(self):
        # TODO: How do I redirect to Stripe checkout here?

CodePudding user response:

You can use redirect for that :

from django.shortcuts import redirect

def get_success_url(self):
    # Redirect the user to the Stripe Checkout page (i suppose that is an external url from your app)
    stripe_checkout_url = 'https://stripe/checkout/url'
    return redirect(stripe_checkout_url)
    # If it's an app url like: stripe:checkout (name 'checkout' and namespace = 'stripe')
    # return redirect('stripe:checkout')
  • Related