title: How to redirect a user to a site only after successful stripe payment?
body: <p>For my website i have one site to explain the pricing plans and where you can submit your email and credit card info. After that you get redirected to the create account site. I want to redirect though only to the site if payment was successful - otherwise, the /createaccount url shouldn't be accessible. I have some ideas on how to do that but would need help with that or tipps. </p>
  
  <p>In the past I tried to add some id to the /createaccount:id url but that didnt work out.</p>
  
  <p>Frontend code is the typical stripe subscription code with stripe.elemens and elements.create('card') </p>
  
  <p>Backend code looks like that:</p>
  
  <pre><code>app.post("/charge", (req, res) =&gt; {
  let email = req.body.email;
  let card = req.body.stripeToken;
  let amount = req.body.plan;
  let interval = req.body.interval;
  const createSubscription = async () =&gt; {
  const stripe = require("stripe")(SK);
  const {
    data: plans
  } = await stripe.plans.list({
    product: "prod_id"
  })
  // Create Customer
  const customer = await stripe.customers.create({
    email: email,
    card: card,
  });
  const planToSubscribeTo = plans.find(p =&gt; p.interval === interval)
  // Subscribe Customer to plan
  const subscription = await stripe.subscriptions.create({
    customer: customer.id,
    items: [{
      plan: planToSubscribeTo.id
    }],
  });
  return {
    customer,
    // prodgHack,
    planToSubscribeTo,
    // ThreeMonthFreeCoupon,
    subscription
  };
  };
  
  console.log('Creating subscriptions ...... ');
  createSubscription().then((sub) =&gt; {
   console.log(sub);
  }).catch(err =&gt; {
   console.warn('Failed to create subscriptions ', err);
  });
  res.redirect('/createAccount');
  });
  </code></pre>