🐛 (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, {
|
||||
items,
|
||||
proration_behavior:
|
||||
plan === 'PRO' ? 'always_invoice' : 'create_prorations',
|
||||
proration_behavior: 'always_invoice',
|
||||
})
|
||||
} else {
|
||||
const checkoutUrl = await createCheckoutSessionUrl(stripe)({
|
||||
|
@ -370,6 +370,51 @@
|
||||
"data"
|
||||
],
|
||||
"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(
|
||||
z.object({
|
||||
name: z.literal('New results collected'),
|
||||
@ -105,6 +114,7 @@ export const eventSchema = z.discriminatedUnion('name', [
|
||||
newResultsCollectedEventSchema,
|
||||
workspaceLimitReachedEventSchema,
|
||||
workspaceAutoQuarantinedEventSchema,
|
||||
subscriptionAutoUpdatedEventSchema,
|
||||
])
|
||||
|
||||
export type TelemetryEvent = z.infer<typeof eventSchema>
|
||||
|
@ -76,6 +76,7 @@ export const checkAndReportChatsUsage = async () => {
|
||||
})
|
||||
|
||||
const quarantineEvents: TelemetryEvent[] = []
|
||||
const autoUpgradeEvents: TelemetryEvent[] = []
|
||||
|
||||
for (const workspace of workspaces) {
|
||||
if (workspace.isQuarantined) continue
|
||||
@ -136,6 +137,21 @@ export const checkAndReportChatsUsage = async () => {
|
||||
stripe,
|
||||
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, {
|
||||
stripe,
|
||||
subscription: newSubscription,
|
||||
|
Reference in New Issue
Block a user