stripe.redirectToCheckout参数:价格不是可接受的参数 [英] stripe.redirectToCheckout parameter: price is not an accepted parameter react

查看:34
本文介绍了stripe.redirectToCheckout参数:价格不是可接受的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的条纹签出中遇到错误,我正在执行......我有一个按钮,当单击它时,它应该重定向到条纹签出页面.但是,我得到了错误

I have an error I am running into on my stripe checkout in react... I have a button and when it is clicked, it is supposed to redirect to the stripe checkout page. However, I get the error

Uncaught (in promise) IntegrationError: Invalid stripe.redirectToCheckout parameter: price is not an accepted parameter.

这是在我运行这段代码时发生的-这是我整个checkout.js页面

this happens when I run this code -- this is my entire checkout.js page

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

const firestore = firebase.firestore();


export async function createCheckoutSession(){

    // without uid
    
    // return firestore.collection()
    const checkoutSessionRef =  await firestore.collection('profiledata').doc().collection('checkout_sessions').add(
        
        // {price : 'price_1IGEdTKDPaWWeL1ymwWH5Ubb',
        {price : '9.99',
         success_url : window.location.origin,
        //  cancel_url: window.location.origin,
    }
    );
    
    console.log("Before onSnapShot");
    checkoutSessionRef.onSnapshot(async (snap) => {
        const sessionid = snap.data();
        console.log("Snap Data: ", snap.data());
        console.log("Session ID: ", sessionid);
        if (sessionid) {
            console.log("Inside session ID: ", sessionid);
            const stripe = loadStripe("pk_test_mystripeid")
             stripe.redirectToCheckout(sessionid)
        }
});
}

有人知道为什么会这样吗?

does anyone know why this is happening?

推荐答案

在创建Checkout会话时,

When creating a Checkout Session, line_items.price is a Price ID in the form of price_123, not an integer.

在这种情况下, sessionid 是什么?是字符串还是对象?由于您正在使用会话,因此它应该是 cs_test_123 形式的字符串.您的console.log的输出是什么?错误发生在哪一行?

What is sessionid in this context? Is it a string or an object? Since you're using sessions it should be a string in the form of cs_test_123. What do your console.log's output? On what line is the error happening?

stripe.redirectToCheckout 是一种异步方法,但是您没有捕获任何错误.尝试这样的事情:

stripe.redirectToCheckout is an asynchronous method, but you're not catching any errors. Try something like this instead:

const result = await stripe.redirectToCheckout({
  sessionId: session.id,
});

if (result.error) {
  // If `redirectToCheckout` fails due to a browser or network
  // error, display the localized error message to your customer
  // using `result.error.message`.
}

您似乎也没有正确使用 loadStripe ,因为它也是一种返回承诺的异步方法:

You also don't appear to be using loadStripe correctly, as it's also an asynchronous method that returns a promise: https://github.com/stripe/stripe-js#loadstripe.

这里发生了很多事情,信息也不多(例如, getStripe 的作用是什么?).我建议您花一些时间阅读react-stripe-js文档,以熟悉该库及其使用方法: https://github.com/stripe/react-stripe-js

There's a lot going on here and not much info (for instance, what does getStripe do?). I suggest you take some time to read the react-stripe-js docs to familiarise yourself with the library and how to use it: https://github.com/stripe/react-stripe-js

这篇关于stripe.redirectToCheckout参数:价格不是可接受的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆