mirror of
https://github.com/nestriness/nestri.git
synced 2026-09-19 17:25:19 +03:00
fix(billing): an organization token already names its organization
Creating a product with one sends `organization_id` alongside a token that implies it, which is refused outright rather than ignored — so which kind of token is in hand has to be known before the call, not after. A personal token can see several organizations and still has to say which.
This commit is contained in:
@@ -54,6 +54,15 @@ if (!accessToken) {
|
|||||||
|
|
||||||
const polar = new Polar({ accessToken, server });
|
const polar = new Polar({ accessToken, server });
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An organization token already names its organization.
|
||||||
|
*
|
||||||
|
* Sending `organizationId` alongside one is refused outright rather than
|
||||||
|
* ignored, so which kind of token this is has to be known before the call. A
|
||||||
|
* personal token can see several organizations and must say which.
|
||||||
|
*/
|
||||||
|
const scopedToOrganization = accessToken.startsWith('polar_oat_');
|
||||||
|
|
||||||
const organizations = await polar.organizations.listOrganizations({ limit: 2 });
|
const organizations = await polar.organizations.listOrganizations({ limit: 2 });
|
||||||
const organization = organizations.result.items.at(0);
|
const organization = organizations.result.items.at(0);
|
||||||
if (!organization) {
|
if (!organization) {
|
||||||
@@ -89,7 +98,7 @@ if (!apply) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const created = await polar.products.create({
|
const created = await polar.products.create({
|
||||||
organizationId: organization.id,
|
...(scopedToOrganization ? {} : { organizationId: organization.id }),
|
||||||
name: PRODUCT.name,
|
name: PRODUCT.name,
|
||||||
description: PRODUCT.description,
|
description: PRODUCT.description,
|
||||||
recurringInterval: PRODUCT.recurringInterval,
|
recurringInterval: PRODUCT.recurringInterval,
|
||||||
|
|||||||
Reference in New Issue
Block a user