【发布时间】:2021-07-16 05:18:58
【问题描述】:
出于某些测试目的,我将我的 stripe 和 firebase api 密钥以及所有内容都更改回了测试模式。但是,当我尝试使用 firebase stripe api 重定向到结帐时,我在控制台中遇到了这个错误,这让我很不愉快:
An error occured: Cannot read property 'stripeId' of null
但是,在我的代码中,stripeID 不存在。有趣的。这是代码。哦,请记住,这只发生在测试模式下。
var userID = "";
firebase.auth().onAuthStateChanged((user) => {
if(user) {
userID = user.uid
console.log(user.uid)
}
});
export async function createCheckoutSession(activtyStatus){
var price = 'price_1Iav0JKDPaWWeL1yBa9F7Aht'
if (activtyStatus == "canceled") {
// test price
price = 'price_1IelOCKDPaWWeL1ynps36jkc'
}
const checkoutSessionRef = firestore
.collection('customers')
.doc(userID)
.collection('checkout_sessions')
.add({
price: price,
success_url: "https://app.x.com/successPage",
cancel_url: "https://app.x.com/signin",
});
// Wait for the CheckoutSession to get attached by the extension
(await checkoutSessionRef).onSnapshot(function (snap) {
const { error, sessionId } = snap.data();
if (error) {
// Show an error to your customer and
// inspect your Cloud Function logs in the Firebase console.
console.log(`An error occured: ${error.message}`);
}
if (sessionId) {
// We have a session, let's redirect to Checkout
// Init Stripe
const stripe = window.Stripe('pk_test_C');
console.log("going to stripe: ")
stripe.redirectToCheckout({sessionId})
console.log("logged stripe")
}
});
}
export async function goToBilliingPortal(){
var finalRoute = "https://app.x.com/profile"
const functionRef = app
.functions('us-central1')
.httpsCallable('ext-firestore-stripe-subscriptions-createPortalLink');
const {data} = await functionRef({returnUrl : finalRoute});
window.location.assign(data.url);
};
有人有什么想法吗?
【问题讨论】:
-
肯定有各种各样的堆栈跟踪,至少可以告诉您在哪里发生了错误以及当时调用了什么。你能提供这些信息吗?
-
@DrewReese 我只更改了测试键,更改了网络挂钩和受限键,如 Stripe 和 firebase 所述。我的控制台中的错误实际上只是
An error occured: Cannot read property 'stripeId' of null,如果我单击它以获取更多上下文,它只会将我带到我的代码中的源页面,向我显示我记录错误的行!好奇怪 -
我明白了,所以在某处检测到错误,您的代码只是控制台记录它。
error对象本身有什么?还有其他细节吗? -
遇到了同样的问题,结果发现我试图重定向到门户的(测试)客户以前没有订阅过。在确保他们订阅了产品后,我能够将他们重定向到门户网站。
标签: javascript node.js firebase google-cloud-firestore stripe-payments