🐛 (billing) Set invoicing behavior to "always invoice" to fix double payment issue
This commit is contained in:
@@ -125,10 +125,10 @@ export const updateSubscription = authenticatedProcedure
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await stripe.subscriptions.update(subscription.id, {
|
await stripe.subscriptions.update(subscription.id, {
|
||||||
items,
|
items,
|
||||||
proration_behavior:
|
proration_behavior: 'always_invoice',
|
||||||
plan === 'PRO' ? 'always_invoice' : 'create_prorations',
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const checkoutUrl = await createCheckoutSessionUrl(stripe)({
|
const checkoutUrl = await createCheckoutSessionUrl(stripe)({
|
||||||
|
|||||||
@@ -370,6 +370,51 @@
|
|||||||
"data"
|
"data"
|
||||||
],
|
],
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"userId": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"workspaceId": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"Subscription automatically updated"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"plan": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"FREE",
|
||||||
|
"STARTER",
|
||||||
|
"PRO",
|
||||||
|
"LIFETIME",
|
||||||
|
"OFFERED",
|
||||||
|
"CUSTOM",
|
||||||
|
"UNLIMITED"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"plan"
|
||||||
|
],
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"userId",
|
||||||
|
"workspaceId",
|
||||||
|
"name",
|
||||||
|
"data"
|
||||||
|
],
|
||||||
|
"additionalProperties": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,15 @@ const subscriptionUpdatedEventSchema = workspaceEvent.merge(
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const subscriptionAutoUpdatedEventSchema = workspaceEvent.merge(
|
||||||
|
z.object({
|
||||||
|
name: z.literal('Subscription automatically updated'),
|
||||||
|
data: z.object({
|
||||||
|
plan: z.nativeEnum(Plan),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
const newResultsCollectedEventSchema = typebotEvent.merge(
|
const newResultsCollectedEventSchema = typebotEvent.merge(
|
||||||
z.object({
|
z.object({
|
||||||
name: z.literal('New results collected'),
|
name: z.literal('New results collected'),
|
||||||
@@ -105,6 +114,7 @@ export const eventSchema = z.discriminatedUnion('name', [
|
|||||||
newResultsCollectedEventSchema,
|
newResultsCollectedEventSchema,
|
||||||
workspaceLimitReachedEventSchema,
|
workspaceLimitReachedEventSchema,
|
||||||
workspaceAutoQuarantinedEventSchema,
|
workspaceAutoQuarantinedEventSchema,
|
||||||
|
subscriptionAutoUpdatedEventSchema,
|
||||||
])
|
])
|
||||||
|
|
||||||
export type TelemetryEvent = z.infer<typeof eventSchema>
|
export type TelemetryEvent = z.infer<typeof eventSchema>
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ export const checkAndReportChatsUsage = async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const quarantineEvents: TelemetryEvent[] = []
|
const quarantineEvents: TelemetryEvent[] = []
|
||||||
|
const autoUpgradeEvents: TelemetryEvent[] = []
|
||||||
|
|
||||||
for (const workspace of workspaces) {
|
for (const workspace of workspaces) {
|
||||||
if (workspace.isQuarantined) continue
|
if (workspace.isQuarantined) continue
|
||||||
@@ -136,6 +137,21 @@ export const checkAndReportChatsUsage = async () => {
|
|||||||
stripe,
|
stripe,
|
||||||
workspaceId: workspace.id,
|
workspaceId: workspace.id,
|
||||||
})
|
})
|
||||||
|
autoUpgradeEvents.push(
|
||||||
|
...workspace.members
|
||||||
|
.filter((member) => member.role === WorkspaceRole.ADMIN)
|
||||||
|
.map(
|
||||||
|
(member) =>
|
||||||
|
({
|
||||||
|
name: 'Subscription automatically updated',
|
||||||
|
userId: member.user.id,
|
||||||
|
workspaceId: workspace.id,
|
||||||
|
data: {
|
||||||
|
plan: 'PRO',
|
||||||
|
},
|
||||||
|
} satisfies TelemetryEvent)
|
||||||
|
)
|
||||||
|
)
|
||||||
await reportUsageToStripe(totalChatsUsed, {
|
await reportUsageToStripe(totalChatsUsed, {
|
||||||
stripe,
|
stripe,
|
||||||
subscription: newSubscription,
|
subscription: newSubscription,
|
||||||
|
|||||||
Reference in New Issue
Block a user