download allowed if purchase
This commit is contained in:
@@ -21,6 +21,20 @@ const {
|
||||
} = require('./shared')
|
||||
const { PREMIUM_SUBSCRIPTION_STATUSES } = require('./constants')
|
||||
|
||||
const isPaidCheckoutSession = (session) => {
|
||||
if (!session || typeof session !== 'object') {
|
||||
return false
|
||||
}
|
||||
|
||||
if (typeof session.payment_status !== 'string') {
|
||||
return false
|
||||
}
|
||||
|
||||
const normalizedStatus = session.payment_status.trim().toLowerCase()
|
||||
|
||||
return normalizedStatus === 'paid' || normalizedStatus === 'no_payment_required'
|
||||
}
|
||||
|
||||
const handleCheckoutSessionCompleted = async (session, event, { stripe } = {}) => {
|
||||
if (!session || typeof session !== 'object') {
|
||||
return
|
||||
@@ -62,6 +76,10 @@ const handleCheckoutSessionCompleted = async (session, event, { stripe } = {}) =
|
||||
lastStripeWebhookEvent: lastEvent,
|
||||
}
|
||||
|
||||
if (isPaidCheckoutSession(session)) {
|
||||
userUpdate.hasPurchased = true
|
||||
}
|
||||
|
||||
if (session.customer) {
|
||||
userUpdate.stripeCustomerId = session.customer
|
||||
}
|
||||
@@ -462,6 +480,10 @@ const handleCustomerSubscriptionEvent = async (subscription, event, { stripe } =
|
||||
subscriptionNextGrantAt,
|
||||
}
|
||||
|
||||
if (isPremium) {
|
||||
userUpdate.hasPurchased = true
|
||||
}
|
||||
|
||||
if (!isPremium) {
|
||||
userUpdate.subscriptionNextGrantAt = null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user