download allowed if purchase
This commit is contained in:
@@ -21,6 +21,20 @@ const {
|
|||||||
} = require('./shared')
|
} = require('./shared')
|
||||||
const { PREMIUM_SUBSCRIPTION_STATUSES } = require('./constants')
|
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 } = {}) => {
|
const handleCheckoutSessionCompleted = async (session, event, { stripe } = {}) => {
|
||||||
if (!session || typeof session !== 'object') {
|
if (!session || typeof session !== 'object') {
|
||||||
return
|
return
|
||||||
@@ -62,6 +76,10 @@ const handleCheckoutSessionCompleted = async (session, event, { stripe } = {}) =
|
|||||||
lastStripeWebhookEvent: lastEvent,
|
lastStripeWebhookEvent: lastEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isPaidCheckoutSession(session)) {
|
||||||
|
userUpdate.hasPurchased = true
|
||||||
|
}
|
||||||
|
|
||||||
if (session.customer) {
|
if (session.customer) {
|
||||||
userUpdate.stripeCustomerId = session.customer
|
userUpdate.stripeCustomerId = session.customer
|
||||||
}
|
}
|
||||||
@@ -462,6 +480,10 @@ const handleCustomerSubscriptionEvent = async (subscription, event, { stripe } =
|
|||||||
subscriptionNextGrantAt,
|
subscriptionNextGrantAt,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isPremium) {
|
||||||
|
userUpdate.hasPurchased = true
|
||||||
|
}
|
||||||
|
|
||||||
if (!isPremium) {
|
if (!isPremium) {
|
||||||
userUpdate.subscriptionNextGrantAt = null
|
userUpdate.subscriptionNextGrantAt = null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -450,6 +450,10 @@ export default ({ children }) => {
|
|||||||
return hasPremiumLevel
|
return hasPremiumLevel
|
||||||
}, [currentUserDoc])
|
}, [currentUserDoc])
|
||||||
|
|
||||||
|
const hasPurchased = useMemo(() => {
|
||||||
|
return currentUserDoc?.hasPurchased === true
|
||||||
|
}, [currentUserDoc])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UserDataContext.Provider
|
<UserDataContext.Provider
|
||||||
value={{
|
value={{
|
||||||
@@ -489,6 +493,7 @@ export default ({ children }) => {
|
|||||||
|
|
||||||
videos,
|
videos,
|
||||||
hasActiveSubscription,
|
hasActiveSubscription,
|
||||||
|
hasPurchased,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ const uploadSourceRecording = async ({ uri, uid, projectId }) => {
|
|||||||
|
|
||||||
const PlaybackDownload = ({ route }) => {
|
const PlaybackDownload = ({ route }) => {
|
||||||
const { currentUID, selectedProject } = useUserData()
|
const { currentUID, selectedProject } = useUserData()
|
||||||
const { hasActiveSubscription, videos } = useUser() || {}
|
const { hasActiveSubscription, hasPurchased, videos } = useUser() || {}
|
||||||
const { createPlaybackDownloadCheckout } = useStripe()
|
const { createPlaybackDownloadCheckout } = useStripe()
|
||||||
const { action: routeAction, uri, project: routeProject } = route.params || {}
|
const { action: routeAction, uri, project: routeProject } = route.params || {}
|
||||||
const action = routeAction || 'playback'
|
const action = routeAction || 'playback'
|
||||||
@@ -168,7 +168,7 @@ const PlaybackDownload = ({ route }) => {
|
|||||||
|
|
||||||
const playbackDownloadStatus = projectForDownload?.playbackDownloadPurchase?.status || null
|
const playbackDownloadStatus = projectForDownload?.playbackDownloadPurchase?.status || null
|
||||||
const hasPaidPlaybackDownload = playbackDownloadStatus === 'paid'
|
const hasPaidPlaybackDownload = playbackDownloadStatus === 'paid'
|
||||||
const canDownloadPlayback = hasActiveSubscription || hasPaidPlaybackDownload
|
const canDownloadPlayback = hasActiveSubscription || hasPaidPlaybackDownload || hasPurchased
|
||||||
const downloadLabel = canDownloadPlayback
|
const downloadLabel = canDownloadPlayback
|
||||||
? 'Télécharger le playback'
|
? 'Télécharger le playback'
|
||||||
: 'Acheter le playback pour 1,99€'
|
: 'Acheter le playback pour 1,99€'
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const SongDownload = ({ route }) => {
|
|||||||
skipAdventureGate = false,
|
skipAdventureGate = false,
|
||||||
promptPurchaseConfirm = false,
|
promptPurchaseConfirm = false,
|
||||||
} = route?.params || {}
|
} = route?.params || {}
|
||||||
const { selectedProject, updateProjectData, hasActiveSubscription } = useUser()
|
const { selectedProject, updateProjectData, hasActiveSubscription, hasPurchased } = useUser()
|
||||||
const { createSongDownloadCheckout } = useStripe()
|
const { createSongDownloadCheckout } = useStripe()
|
||||||
const { setTooltip } = useMinuit()
|
const { setTooltip } = useMinuit()
|
||||||
const { setLoading } = useGlobalLoading()
|
const { setLoading } = useGlobalLoading()
|
||||||
@@ -104,7 +104,7 @@ const SongDownload = ({ route }) => {
|
|||||||
const projectId = projectForStage?.id || null
|
const projectId = projectForStage?.id || null
|
||||||
const downloadPurchaseStatus = projectForStage?.downloadPurchase?.status || null
|
const downloadPurchaseStatus = projectForStage?.downloadPurchase?.status || null
|
||||||
const hasPaidDownload = downloadPurchaseStatus === 'paid'
|
const hasPaidDownload = downloadPurchaseStatus === 'paid'
|
||||||
const canDownloadDirectly = hasActiveSubscription || hasPaidDownload
|
const canDownloadDirectly = hasActiveSubscription || hasPaidDownload || hasPurchased
|
||||||
const downloadLabel = canDownloadDirectly
|
const downloadLabel = canDownloadDirectly
|
||||||
? 'Télécharger mon morceau'
|
? 'Télécharger mon morceau'
|
||||||
: 'Acheter ce morceau pour 1,99€'
|
: 'Acheter ce morceau pour 1,99€'
|
||||||
|
|||||||
Reference in New Issue
Block a user