Stripe Plugin | Bugs To Fix

"@better-auth/stripe": "^1.2.1",
"better-auth": "^1.2.1",
"@better-auth/stripe": "^1.2.1",
"better-auth": "^1.2.1",
1. even if a error happens it still creates a subscription in the database 2. getCheckoutSessionParams cause error Received unknown parameter: params (REF1.png files for reference) also causes 1. bug to happens 3. When "admin" cancels user subscription from stripe dashboard it doesnt update the subscription in the database that is cancelled 4. onSubscriptionDeleted doesnt do anything same goes with the similar ones
No description
No description
32 Replies
🌠kkMihai ⚡
🌠kkMihai ⚡OP•18h ago
5. when user tries to upgrade to the same subscription tier it already has, server does return a error but its an unhandled error so it just gives a prisma error in the console (check message.txt)
🌠kkMihai ⚡
🌠kkMihai ⚡OP•18h ago
6. be able to return multiple objects for organization like both slug and id in the session
🌠kkMihai ⚡
🌠kkMihai ⚡OP•18h ago
Update Regarding 2. getCheckoutSessionParams, docs and types are wrong the image below represents the correct way of using it (tested)
No description
No description
bekacru
bekacru•17h ago
1. A sub is created on the db before it tries to create stripe session but it's marked incomplete. Migh tbe good idea to remove newly created subs if it fails, but shouldn't be a problem. 2. will be fixed 3. I'll take a look (should be fixed) 4. onSubscriptionDeleted is only called when the sub status is set cancelled and it's no longer active. If it's still not being called, I'll check but I doubt that's the case. 5. I think this is cause you haven't marked referenceId unique in your prisma schema (or we haven't marked that on generate command). If the user has the same tier active sub, it should return a proper error.
🌠kkMihai ⚡
🌠kkMihai ⚡OP•17h ago
5. ye its not set as unique but its generate with betterauth cli so 1. at some point it can cause that alot of subscription with incomplete status to be create and its accumulates over the time and could cause a performance issue on the db/storage part
bekacru
bekacru•17h ago
yeah, we'll clean it up
🌠kkMihai ⚡
🌠kkMihai ⚡OP•17h ago
thanks, keep up the great work i will send here if i found any more bugs 5. well...
prisma:error
Invalid `prisma.subscription.create()` invocation:


Unique constraint failed on the fields: (`referenceId`)
\node_modules\.pnpm\@[email protected][email protected][email protected][email protected]\node_modules\@prisma\client\runtime\library.js: Invalid source map. Only conformant source maps can be used to find the original code. Cause: TypeError [ERR_INVALID_ARG_TYPE]: The "payload" argument must be of type object. Received null
\node_modules\.pnpm\@[email protected][email protected][email protected][email protected]\node_modules\@prisma\client\runtime\library.js: Invalid source map. Only conformant source maps can be used to find the original code. Cause: TypeError [ERR_INVALID_ARG_TYPE]: The "payload" argument must be of type object. Received null
\node_modules\.pnpm\@[email protected][email protected][email protected][email protected]\node_modules\@prisma\client\runtime\library.js: Invalid source map. Only conformant source maps can be used to find the original code. Cause: TypeError [ERR_INVALID_ARG_TYPE]: The "payload" argument must be of type object. Received null
\node_modules\.pnpm\@[email protected][email protected][email protected][email protected]\node_modules\@prisma\client\runtime\library.js: Invalid source map. Only conformant source maps can be used to find the original code. Cause: TypeError [ERR_INVALID_ARG_TYPE]: The "payload" argument must be of type object. Received null
# SERVER_ERROR: [Error [PrismaClientKnownRequestError]:
Invalid `prisma.subscription.create()` invocation:


Unique constraint failed on the fields: (`referenceId`)] {
code: 'P2002',
clientVersion: '6.4.1',
meta: [Object]
}
POST /api/auth/subscription/upgrade 500 in 715ms
prisma:error
Invalid `prisma.subscription.create()` invocation:


Unique constraint failed on the fields: (`referenceId`)
\node_modules\.pnpm\@[email protected][email protected][email protected][email protected]\node_modules\@prisma\client\runtime\library.js: Invalid source map. Only conformant source maps can be used to find the original code. Cause: TypeError [ERR_INVALID_ARG_TYPE]: The "payload" argument must be of type object. Received null
\node_modules\.pnpm\@[email protected][email protected][email protected][email protected]\node_modules\@prisma\client\runtime\library.js: Invalid source map. Only conformant source maps can be used to find the original code. Cause: TypeError [ERR_INVALID_ARG_TYPE]: The "payload" argument must be of type object. Received null
\node_modules\.pnpm\@[email protected][email protected][email protected][email protected]\node_modules\@prisma\client\runtime\library.js: Invalid source map. Only conformant source maps can be used to find the original code. Cause: TypeError [ERR_INVALID_ARG_TYPE]: The "payload" argument must be of type object. Received null
\node_modules\.pnpm\@[email protected][email protected][email protected][email protected]\node_modules\@prisma\client\runtime\library.js: Invalid source map. Only conformant source maps can be used to find the original code. Cause: TypeError [ERR_INVALID_ARG_TYPE]: The "payload" argument must be of type object. Received null
# SERVER_ERROR: [Error [PrismaClientKnownRequestError]:
Invalid `prisma.subscription.create()` invocation:


Unique constraint failed on the fields: (`referenceId`)] {
code: 'P2002',
clientVersion: '6.4.1',
meta: [Object]
}
POST /api/auth/subscription/upgrade 500 in 715ms
user doesnt have any sub @bekacru
bekacru
bekacru•16h ago
will take a look
MyWay
MyWay•16h ago
can we use that plugin for stripe single payments too, or subscriptions only?
🌠kkMihai ⚡
🌠kkMihai ⚡OP•16h ago
both
MyWay
MyWay•16h ago
could an example be added to the docs, showing if we need different events for the webhook in that case and so on?
🌠kkMihai ⚡
🌠kkMihai ⚡OP•11h ago
i m not a contributor to betterauth source code so i cant answer to that 7. freeTrial doesnt seem to work for stripe plugin at subscription.plans and by that i mean a free trial doesnt seem to show at the payment link/page @bekacru
bekacru
bekacru•11h ago
This should be fixed on latest beta
🌠kkMihai ⚡
🌠kkMihai ⚡OP•11h ago
alr
bekacru
bekacru•11h ago
Including the other issues
🌠kkMihai ⚡
🌠kkMihai ⚡OP•11h ago
ty and sorry for ping
MyWay
MyWay•11h ago
great guys, this plugin is life-changing!
🌠kkMihai ⚡
🌠kkMihai ⚡OP•9h ago
@bekacru when i cancel the sub from stripe dashboard it still doesnt set the status to canceled in the db using 1.2.2
bekacru
bekacru•9h ago
is the webhook being triggered?
🌠kkMihai ⚡
🌠kkMihai ⚡OP•9h ago
yes
🌠kkMihai ⚡
🌠kkMihai ⚡OP•9h ago
No description
🌠kkMihai ⚡
🌠kkMihai ⚡OP•9h ago
No description
bekacru
bekacru•9h ago
do you see any log on the server when the webhook is hit?
🌠kkMihai ⚡
🌠kkMihai ⚡OP•9h ago
prisma:error
Invalid `prisma.subscription.update()` invocation:

{
where: {
stripeSubscriptionId: "sub_1QyeC4LmFXqXOAOqjLjjwgUT",
? id?: String,
? AND?: SubscriptionWhereInput | SubscriptionWhereInput[],
? OR?: SubscriptionWhereInput[],
? NOT?: SubscriptionWhereInput | SubscriptionWhereInput[],
? plan?: StringFilter | String,
? referenceId?: StringFilter | String,
? stripeCustomerId?: StringNullableFilter | String | Null,
? status?: StringNullableFilter | String | Null,
? periodStart?: DateTimeNullableFilter | DateTime | Null,
? periodEnd?: DateTimeNullableFilter | DateTime | Null,
? cancelAtPeriodEnd?: BoolNullableFilter | Boolean | Null,
? seats?: IntNullableFilter | Int | Null
},
data: {
status: "canceled"
}
}

Argument `where` of type SubscriptionWhereUniqueInput needs at least one of `id` arguments. Available options are marked with ?.
2025-03-03T18:59:19.834Z ERROR [Better Auth]: Stripe webhook failed. Error: PrismaClientValidationError:
Invalid `prisma.subscription.update()` invocation:

{
where: {
stripeSubscriptionId: "sub_1QyeC4LmFXqXOAOqjLjjwgUT",
? id?: String,
? AND?: SubscriptionWhereInput | SubscriptionWhereInput[],
? OR?: SubscriptionWhereInput[],
? NOT?: SubscriptionWhereInput | SubscriptionWhereInput[],
? plan?: StringFilter | String,
? referenceId?: StringFilter | String,
? stripeCustomerId?: StringNullableFilter | String | Null,
? status?: StringNullableFilter | String | Null,
? periodStart?: DateTimeNullableFilter | DateTime | Null,
? periodEnd?: DateTimeNullableFilter | DateTime | Null,
? cancelAtPeriodEnd?: BoolNullableFilter | Boolean | Null,
? seats?: IntNullableFilter | Int | Null
},
data: {
status: "canceled"
}
}

Argument `where` of type SubscriptionWhereUniqueInput needs at least one of `id` arguments. Available options are marked with ?.
prisma:error
Invalid `prisma.subscription.update()` invocation:

{
where: {
stripeSubscriptionId: "sub_1QyeC4LmFXqXOAOqjLjjwgUT",
? id?: String,
? AND?: SubscriptionWhereInput | SubscriptionWhereInput[],
? OR?: SubscriptionWhereInput[],
? NOT?: SubscriptionWhereInput | SubscriptionWhereInput[],
? plan?: StringFilter | String,
? referenceId?: StringFilter | String,
? stripeCustomerId?: StringNullableFilter | String | Null,
? status?: StringNullableFilter | String | Null,
? periodStart?: DateTimeNullableFilter | DateTime | Null,
? periodEnd?: DateTimeNullableFilter | DateTime | Null,
? cancelAtPeriodEnd?: BoolNullableFilter | Boolean | Null,
? seats?: IntNullableFilter | Int | Null
},
data: {
status: "canceled"
}
}

Argument `where` of type SubscriptionWhereUniqueInput needs at least one of `id` arguments. Available options are marked with ?.
2025-03-03T18:59:19.834Z ERROR [Better Auth]: Stripe webhook failed. Error: PrismaClientValidationError:
Invalid `prisma.subscription.update()` invocation:

{
where: {
stripeSubscriptionId: "sub_1QyeC4LmFXqXOAOqjLjjwgUT",
? id?: String,
? AND?: SubscriptionWhereInput | SubscriptionWhereInput[],
? OR?: SubscriptionWhereInput[],
? NOT?: SubscriptionWhereInput | SubscriptionWhereInput[],
? plan?: StringFilter | String,
? referenceId?: StringFilter | String,
? stripeCustomerId?: StringNullableFilter | String | Null,
? status?: StringNullableFilter | String | Null,
? periodStart?: DateTimeNullableFilter | DateTime | Null,
? periodEnd?: DateTimeNullableFilter | DateTime | Null,
? cancelAtPeriodEnd?: BoolNullableFilter | Boolean | Null,
? seats?: IntNullableFilter | Int | Null
},
data: {
status: "canceled"
}
}

Argument `where` of type SubscriptionWhereUniqueInput needs at least one of `id` arguments. Available options are marked with ?.
should switch to using updateMany method this way you dont need to pass the local id
bekacru
bekacru•9h ago
yeah. it passes local test cause we're not using prisma. should have used id instead of referenceId. Will be patched on the next release.
🌠kkMihai ⚡
🌠kkMihai ⚡OP•9h ago
alr, v1.2.3? also the referenceid shouldnt be unique?
🌠kkMihai ⚡
🌠kkMihai ⚡OP•9h ago
in my case is not
No description
bekacru
bekacru•9h ago
yeah It shouldn't be since we could be creating incomplete subs in between
🌠kkMihai ⚡
🌠kkMihai ⚡OP•9h ago
ah i see also even tho its kinda off-topic, will i see in the near future an option to create a organization (called "personal" for example) automatically when a new user signs up? like have a organization by "default" currently i have it integrate it in my app but would be nicer if it was built-in yk
bekacru
bekacru•9h ago
yeah we should have that soon. in the works already.
🌠kkMihai ⚡
🌠kkMihai ⚡OP•9h ago
perfect thank you, u are amazing fr

Did you find this page helpful?