Stripe Create Payment Intents 承诺永远不会解决

时间:2020-12-20 20:31:54

标签: reactjs npm stripe-payments strip

我注册了一个 Stripe 帐户,并按照一些简单的步骤来启动和运行 Node。我刚刚安装了该软件包并使用我的测试密钥测试了支付意图:

const Stripe = require('stripe');

const handleStripe = async () => {
    const stripe = Stripe(testKeyString);
   
    console.log(“we make it here”);

    try {

        const paymentIntent = await stripe.paymentIntents.create({
            amount: 1000,
            currency: 'usd',
            payment_method_types: ['card'],
            receipt_email: 'jenny.rosen@example.com',
        });
   
        //we never make it here
        console.log(paymentIntent);
    }
    catch(err){
        //we never make it here either
        console.log(err);
    }
}

控制台记录“我们在这里成功”,但没有其他记录。承诺永远不会解决。

我怀疑这可能是 stripe npm 包的一个错误。有没有人对为什么永远不会返回承诺有任何想法?

编辑:抱歉,我在这里浪费了大家的时间。我正在关注文档 QuickStart,它说“安装客户端库”,我认为它是用于前端的。所以我认为这是一个非常愚蠢的错误,认为使用密钥从前端进行支付是一个好主意。刚刚开始使用 Stripe API,我的开局很糟糕。感谢您的评论和回答

谢谢

1 个答案:

答案 0 :(得分:1)

如果你在没有 try/catch 的情况下运行它会发生什么?另外,如果您从该服务器尝试 https://status.stripe.com/reachability,您会得到什么 - 您确定可以访问 Stripe 的服务器吗?