我在我的 Web 應用程式中使用 Firebase JS V9。我正在嘗試將來自 Firebase 的 Stripe Etension 實施到我的應用程式中。
此擴展的檔案尚未更新以支持 Firebase v9。我已經在 Twitter 上確認檔案將更新,但目前沒有 ETA :)
以下是他們在以前的 Firebase 版本中的做法:
const docRef = await db
.collection('customers')
.doc(currentUser.uid)
.collection('checkout_sessions')
.add({
price: 'price_1GqIC8HYgolSBA35zoTTN2Zl',
success_url: window.location.origin,
cancel_url: window.location.origin,
});
// Wait for the CheckoutSession to get attached by the extension
docRef.onSnapshot((snap) => {
const { error, url } = snap.data();
if (error) {
// Show an error to your customer and
// inspect your Cloud Function logs in the Firebase console.
alert(`An error occured: ${error.message}`);
}
if (url) {
// We have a Stripe Checkout URL, let's redirect.
window.location.assign(url);
}
});
所以我正在嘗試這樣做,但是有了 v9 的新東西,一切都不同了。我在網上搜索過,我能找到的唯一解決方案是關于以前的 Firebase 版本。
這是我第一次使用 Firebase,所以它也無濟于事。
任何人都知道如何在 Firebase JS SDK V9 中執行上述代碼片段?
謝謝!
uj5u.com熱心網友回復:
您會在下面找到代碼的 V9 版本。在 JS SDK 檔案中有兩個選項卡,一個用于 V9,一個用于 V8,因此從一個版本轉換到另一個版本并不是很困難。方法示例onSnapshot()。
import { collection, addDoc, onSnapshot } from "firebase/firestore";
const docRef = await addDoc(collection(db, `customers/${currentUser.uid}/checkout_sessions`), {
price: 'price_1GqIC8HYgolSBA35zoTTN2Zl',
success_url: window.location.origin,
cancel_url: window.location.origin,
});
onSnapshot(docRef, (snap) => {
const { error, url } = snap.data();
if (error) {
// Show an error to your customer and
// inspect your Cloud Function logs in the Firebase console.
alert(`An error occured: ${error.message}`);
}
if (url) {
// We have a Stripe Checkout URL, let's redirect.
window.location.assign(url);
}
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/365994.html
標籤:火力基地 谷歌云firestore 下一个.js 条纹支付 萨斯
