From a7431f93c4376ac4761c6c37cbec4e42a1b2915b Mon Sep 17 00:00:00 2001 From: Dan Dorman Date: Fri, 8 Nov 2024 10:51:17 -0700 Subject: [PATCH] Remove org Stripe customer ID setter/getter (#1160) ## Description The same thing can be accomplished with the `organizations.updateOrganization` function. ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [ ] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required. --- .../fixtures/get-stripe-customer-id.json | 17 ---- ...et-stripe-customer-id-options.interface.ts | 4 - src/organizations/organizations.spec.ts | 82 ++++--------------- src/organizations/organizations.ts | 13 --- 4 files changed, 15 insertions(+), 101 deletions(-) delete mode 100644 src/organizations/fixtures/get-stripe-customer-id.json delete mode 100644 src/organizations/interfaces/set-stripe-customer-id-options.interface.ts diff --git a/src/organizations/fixtures/get-stripe-customer-id.json b/src/organizations/fixtures/get-stripe-customer-id.json deleted file mode 100644 index fd7ea5471..000000000 --- a/src/organizations/fixtures/get-stripe-customer-id.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "Test Organization 3", - "object": "organization", - "id": "org_01EHT88Z8J8795GZNQ4ZP1J81T", - "allow_profiles_outside_organization": false, - "domains": [ - { - "domain": "example.com", - "object": "organization_domain", - "id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8", - "state": "verified", - "verification_strategy": "dns", - "verification_token": "xB8SeACdKJQP9DP4CahU4YuQZ" - } - ], - "stripe_customer_id": "cus_MX8J9nfK4lP2Yw" -} diff --git a/src/organizations/interfaces/set-stripe-customer-id-options.interface.ts b/src/organizations/interfaces/set-stripe-customer-id-options.interface.ts deleted file mode 100644 index 6cbd8087a..000000000 --- a/src/organizations/interfaces/set-stripe-customer-id-options.interface.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface SetStripeCustomerIdOptions { - organization: string; - stripeCustomerId: string | null; -} diff --git a/src/organizations/organizations.spec.ts b/src/organizations/organizations.spec.ts index fd5da8bda..d1323660f 100644 --- a/src/organizations/organizations.spec.ts +++ b/src/organizations/organizations.spec.ts @@ -11,7 +11,6 @@ import clearStripeCustomerId from './fixtures/clear-stripe-customer-id.json'; import createOrganizationInvalid from './fixtures/create-organization-invalid.json'; import createOrganization from './fixtures/create-organization.json'; import getOrganization from './fixtures/get-organization.json'; -import getStripeCustomerId from './fixtures/get-stripe-customer-id.json'; import listOrganizationsFixture from './fixtures/list-organizations.json'; import updateOrganization from './fixtures/update-organization.json'; import setStripeCustomerId from './fixtures/set-stripe-customer-id.json'; @@ -297,42 +296,8 @@ describe('Organizations', () => { }); }); }); - }); - - describe('setStripeCustomerId', () => { - describe('with a valid payload', () => { - it('updates the organization’s Stripe customer ID', async () => { - fetchOnce(setStripeCustomerId); - - const subject = await workos.organizations.setStripeCustomerId({ - organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', - stripeCustomerId: 'cus_MX8J9nfK4lP2Yw', - }); - - expect(fetchBody()).toEqual({ - stripe_customer_id: 'cus_MX8J9nfK4lP2Yw', - }); - - expect(subject).toBe('cus_MX8J9nfK4lP2Yw'); - }); - - it('clears the organization’s Stripe customer ID with a `null` value', async () => { - fetchOnce(clearStripeCustomerId); - - const subject = await workos.organizations.setStripeCustomerId({ - organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', - stripeCustomerId: null, - }); - - expect(fetchBody()).toEqual({ - stripe_customer_id: null, - }); - - expect(subject).toBeUndefined(); - }); - }); - describe('when set via `updateOrganization`', () => { + describe('when given `stripeCustomerId`', () => { it('updates the organization’s Stripe customer ID', async () => { fetchOnce(setStripeCustomerId); @@ -362,42 +327,25 @@ describe('Organizations', () => { expect(subject.stripeCustomerId).toBeUndefined(); }); - }); - describe('when the feature is not enabled', () => { - it('returns an error', async () => { - fetchOnce(setStripeCustomerIdDisabled, { status: 422 }); + describe('when the feature is not enabled', () => { + it('returns an error', async () => { + fetchOnce(setStripeCustomerIdDisabled, { status: 422 }); - await expect( - workos.organizations.setStripeCustomerId({ - organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', - stripeCustomerId: 'cus_MX8J9nfK4lP2Yw', - }), - ).rejects.toThrowError( - 'stripe_customer_id is not enabled for this environment', - ); + await expect( + workos.organizations.updateOrganization({ + organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', + stripeCustomerId: 'cus_MX8J9nfK4lP2Yw', + }), + ).rejects.toThrowError( + 'stripe_customer_id is not enabled for this environment', + ); - expect(fetchBody()).toEqual({ - stripe_customer_id: 'cus_MX8J9nfK4lP2Yw', + expect(fetchBody()).toEqual({ + stripe_customer_id: 'cus_MX8J9nfK4lP2Yw', + }); }); }); }); }); - - describe('getStripeCustomerId', () => { - it('returns the organization’s Stripe customer ID', async () => { - fetchOnce(getStripeCustomerId); - - const subject = await workos.organizations.setStripeCustomerId({ - organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T', - stripeCustomerId: null, - }); - - expect(fetchURL()).toContain( - '/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T', - ); - - expect(subject).toEqual('cus_MX8J9nfK4lP2Yw'); - }); - }); }); diff --git a/src/organizations/organizations.ts b/src/organizations/organizations.ts index d00182701..01c4f6166 100644 --- a/src/organizations/organizations.ts +++ b/src/organizations/organizations.ts @@ -15,7 +15,6 @@ import { } from './serializers'; import { fetchAndDeserialize } from '../common/utils/fetch-and-deserialize'; -import { SetStripeCustomerIdOptions } from './interfaces/set-stripe-customer-id-options.interface'; export class Organizations { constructor(private readonly workos: WorkOS) {} @@ -78,16 +77,4 @@ export class Organizations { return deserializeOrganization(data); } - - async setStripeCustomerId( - options: SetStripeCustomerIdOptions, - ): Promise { - const updatedOrganization = await this.updateOrganization(options); - return updatedOrganization.stripeCustomerId; - } - - async getStripeCustomerId(id: string): Promise { - const organization = await this.getOrganization(id); - return organization.stripeCustomerId; - } }