![](/img/trans.png)
[英]Storing a username on sign up only displays after page refresh (Firebase)
[英]Firebase sign user up only after successful payment
我正在嘗試實現以下流程:
Subscribe now
Stripe Checkout
(因為它更容易)長話短說:只有在用戶付費時才授予他訪問權限。
我為此使用 Firebase,但似乎有很多障礙/頭痛:
我用Firebase的時候到處找web關於訂閱model,幾乎沒有。
我的問題是:任何人都使用Stripe實現了訂閱服務(任何,不必是 Checkout - 流程是一樣的)和Firebase ? 或者我應該為我自己的服務器使用 go 而僅將 Firebase 用於數據庫?
當用戶必須先注冊然后付款(太多摩擦)時,我真的不覺得它是一個好的 UX。
使用雲函數:
stripe.customers.create({ email: 'user_email' }) // grab customer id
(將userRecord.uid
id 用於doc()
id)
firebaseAdmin.auth().createUser({
email: 'email',
password: 'temporary_password',
displayName: 'fullname'
})
.then((userRecord) => {
return firebaseAdminSDK.firestore()
.collection('users').doc(userRecord.uid)
.set({ stripe_account: 'cus_HILXPWljT9fKRA' })
})
在客戶端:
firebase.auth().signInWithEmailAndPassword(data.email, data.password)
當用戶登錄時,從用戶集合中獲取stripe_account
並獲取條帶訂閱狀態並將其顯示給用戶。
要求用戶驗證其 email 或更改密碼。 禁用所有編輯,直到用戶驗證其 email 或更改其密碼。
我正在考慮使用 firebase 條紋擴展的以下設置:
用戶填寫電子郵件地址並單擊提交。
signInAnonymously()
並使用updateEmail()
設置用戶電子郵件地址。
然后創建一個附加 uid 的結帳會話:
async stripeCheckout({ state }, payload) { const uid = state.authUser.uid const ref = await this.$fire.firestore.collection('users').doc(uid).collection('checkout_sessions').add({ price: payload.price, success_url: SUCCES_URL, cancel_url: CANCEL_URL, }); // Wait for the CheckoutSession to get attached by the extension ref.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); } }) }
CANCEL_URL 可以是任何 url
SUCCESS_URL 將是一個 url + 帶有電子郵件的查詢參數
在 SUCCESS_URL 后面,您將調用sendSignInLinkToEmail()
在 stripe 中,您可以在訂閱中設置自定義聲明,例如: stripeRole
equals premium
。 此聲明將添加到 firebase 授權,僅供訂閱用戶使用。
您的前端可以使用 auth guard 或中間件來檢查自定義聲明
如果您使用 firestore 為高級會員提供內容,您應該使用如下安全規則: request.auth.token.stripeRole == "premium";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.