简体   繁体   English

ReferenceError:找不到变量:从“@stripe.stripe-js”导入 loadStripe 时的文档

[英]ReferenceError: Can't find variable: document when importing loadStripe from '@stripe.stripe-js'

While developing an app in React Native intgerating with Stripe, I keep getting a warning [ReferenceError: Can't find variable: document] .在与 Stripe 集成的 React Native 中开发应用程序时,我不断收到警告[ReferenceError: Can't find variable: document]

I can't get the cause for the error.我无法找到错误的原因。

The only possiblity I can think is if the Stripe module is only built for react js and is looking for the HTML document to reference.我能想到的唯一可能是 Stripe 模块是否仅适用于 react js,并且正在寻找 HTML 文档以供参考。

I am fairly certain it is this line which is causing the warning.我相当肯定是这条线导致了警告。

import {loadStripe} from '@stripe/stripe-js';

When it is included the warning shows up.当它被包括在内时,警告就会出现。 I read the documentation but there's nothing I could find.我阅读了文档,但找不到任何东西。

If anyone could point me in the right direction for what might be causing the problem or if stripe will work on react native as a cross platform app, please let me know.如果有人可以为我指出可能导致问题的正确方向,或者条带是否可以作为跨平台应用程序在 react native 上运行,请告诉我。

The only possiblity I can think is if the Stripe module is only built for react js and is looking for the HTML document to reference.我能想到的唯一可能是 Stripe 模块是否仅适用于 react js,并且正在寻找 HTML 文档以供参考。

This is correct.这是对的。 The @stripe/stripe-js module and Stripe.js are only meant to be used within in a browser. @stripe/stripe-js模块和 Stripe.js 仅用于在浏览器中使用。 The only way to use Stripe.js within React Native would be to use a WebView:在 React Native 中使用 Stripe.js 的唯一方法是使用 WebView:

The benefit of this approach is that it uses vanilla Stripe.js and Elements, and is straightforward.这种方法的好处是它使用 vanilla Stripe.js 和 Elements,而且很简单。 The cons are that the user experience can sometimes suffer due to WebView performance, and the payment request button (ie, Apple Pay, Google Pay) doesn't work in WebViews due to limitations with Android and iOS.缺点是用户体验有时会因 WebView 性能而受到影响,并且由于 Android 和 Z1BDF605991920DB11CBDF8508204 的限制,支付请求按钮(即 Apple Pay、Google Pay)在 WebViews 中不起作用。

An arguably better option is to use a library that binds to Stripe's native iOS and Android SDKs.可以说更好的选择是使用绑定到 Stripe 的原生 iOS 和 Android SDK 的库。 The most widely used library that does this is called tipsi-stripe : https://github.com/tipsi/tipsi-stripe .使用最广泛的库称为tipsi-stripehttps://github.com/tipsi/tipsi-stripe

The main downside to using tipsi-stripe is that it doesn't support SCA/PaymentIntents: https://github.com/tipsi/tipsi-stripe/issues/448 , and is not as actively maintained as one would hope.使用tipsi-stripe 的主要缺点是它不支持SCA/PaymentIntents: https://github.com/tipsi/tipsi-stripe/issues/448 ,并且没有像人们希望的那样积极维护。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM