Home > Enterprise >  firebase dynamic links in stripe throws err_unknown_url_scheme
firebase dynamic links in stripe throws err_unknown_url_scheme

Time:09-28

I've been developing an app with firebase and stripe payment. I've created a checkout session in stripe and added firebase dynamic links for the success_url and cancel_url. The URLs are working fine. I've tested them outside stripe with a simple html file and it opens the app and takes the user to the correct page. If the page doesn't exist it'll take the user to the assigned website. This is stripe checkout session code:

const session = await stripe.checkout.sessions.create({
        line_items: [{
            price_data: { currency: 'INR', unit_amount: amount, product_data: { name: 'name' } },
            quantity: 1,
        }],
        mode: 'payment',
        success_url: 'https://-------.page.link/payment-success',
        cancel_url: 'https://-------.page.link/payment-failed',
        payment_intent_data: {
            application_fee_amount: fee
        },
    }, {
        stripeAccount: req.query.stripeId,
    });

I've changed up the actual link since I don't know how much I'm allowed to share. But I can guarantee the dynamic links works fine. But after payment, the test payment at least, it's suppose to open the app and take the user to a payment success page. AND it was working fine for the first 2 or 3 days. After payment it re-opened the app and took the user to the correct page. But when I tried a few days later, this is what it's taking us to: Screenshot

Again, I've removed the link since I don't know how much I'm allowed to share. It won't even open the app right now. It just shows this message in the browser. Both success and cancel url are doing the same. Why does the links work outside the function but not in it? Has anyone ever faced any similar issues before? Any help will be greatly appreciated.

CodePudding user response:

It seems like you're trying to open the Checkout Session in a WebView which causing the issue in the redirect. Webviews don't know how to handle an URL Scheme other than http:// or https://. That being said, your problem isn't uncommon and there are multiple ways of solving this. Your first approach would be to open the Checkout Session in an external browser as described in this answer or try to create your own WebViewClient and override shouldOverrideUrlLoading method like described in this answer. Just note that since the last edit of that answer the signature of the shouldOverrideUrlLoading method has changed but the logic should still be used the same way but instead of dealing with the String url, you will have to deal with a WebResourceRequest.

  • Related