Search code examples
javascriptreact-nativestripe-paymentsreact-navigation

Deep Link and Stripe redirect


So I am trying to redirect my react-native application from a stripe checkout page back to the application.

app.post('/create-checkout-session', async (req, res) => {
  const prices = await stripe.prices.list({
    lookup_keys: [req.body.lookup_key],
    expand: ['data.product'],
  });
  const session = await stripe.checkout.sessions.create({
    billing_address_collection: 'auto',
    line_items: [
      {
        price: prices.data[0].id,
        // For metered billing, do not pass quantity
        quantity: 1,

      },
    ],
    mode: 'subscription',
    success_url: `${YOUR_DOMAIN}/?success=true&session_id={CHECKOUT_SESSION_ID}`,
    cancel_url: `${YOUR_DOMAIN}?canceled=true`,
  });

  res.redirect(303, session.url);
});

using the success URL but it won't redirect back into the application. I'm currently using React Navigation, Deep Linking in the App.js file.

const linking = {
  prefixes: [ Linking.createURL("hometrack://")],
  config:{
    screens:{
      EmployeeSignUp:{
        path:"EmployeeSignUp/:id",
        parse: {
          id: (id) => `${id}`,
        },
      },
      Success:{
        path:"Success"
      }
      
    }
  }
};

I can't seem to make it link back into the application.


Solution

  • Deep link with custom URL scheme (myapp://screen..) does not work in this case. Stripe expects a valid URL that redirects to a real website. I am currently facing the same problem, and my workaround is:

    • Redirect the user to my website (e.g. myapp.com/redirect).
    • Display the "Redirect back to app" button on the website.
    • Deep link back to the app

    I'll update my answer if I will find another solution.