Skip to content

Commit 1a2430a

Browse files
authored
chore(clerk-js,types): Align payment methods terminology (#6865)
1 parent ea011df commit 1a2430a

File tree

27 files changed

+240
-209
lines changed

27 files changed

+240
-209
lines changed

.changeset/rich-breads-move.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/shared': patch
4+
'@clerk/types': minor
5+
---
6+
7+
[Billing Beta] Rename payment source to payment method.
8+
9+
`Clerk.user.initializePaymentSource()` -> `Clerk.user.initializePaymentMethod()`
10+
`Clerk.user.addPaymentSource()` -> `Clerk.user.addPaymentMethod()`
11+
`Clerk.user.getPaymentSources()` -> `Clerk.user.getPaymentMethods()`
12+
13+
`Clerk.organization.initializePaymentSource()` -> `Clerk.organization.initializePaymentMethod()`
14+
`Clerk.organization.addPaymentSource()` -> `Clerk.organization.addPaymentMethod()`
15+
`Clerk.organization.getPaymentSources()` -> `Clerk.organization.getPaymentMethods()`
16+

.typedoc/__tests__/__snapshots__/file-structure.test.ts.snap

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
55
"types/act-claim.mdx",
66
"types/act-jwt-claim.mdx",
77
"types/active-session-resource.mdx",
8-
"types/add-payment-source-params.mdx",
8+
"types/add-payment-method-params.mdx",
99
"types/billing-checkout-json.mdx",
1010
"types/billing-checkout-resource.mdx",
1111
"types/billing-checkout-totals-json.mdx",
1212
"types/billing-checkout-totals.mdx",
13-
"types/billing-initialized-payment-source-json.mdx",
14-
"types/billing-initialized-payment-source-resource.mdx",
13+
"types/billing-initialized-payment-method-json.mdx",
14+
"types/billing-initialized-payment-method-resource.mdx",
1515
"types/billing-money-amount-json.mdx",
1616
"types/billing-money-amount.mdx",
1717
"types/billing-namespace.mdx",
1818
"types/billing-payer-json.mdx",
19+
"types/billing-payer-methods.mdx",
1920
"types/billing-payer-resource-type.mdx",
2021
"types/billing-payer-resource.mdx",
2122
"types/billing-payment-charge-type.mdx",
2223
"types/billing-payment-json.mdx",
24+
"types/billing-payment-method-json.mdx",
25+
"types/billing-payment-method-resource.mdx",
26+
"types/billing-payment-method-status.mdx",
2327
"types/billing-payment-resource.mdx",
24-
"types/billing-payment-source-json.mdx",
25-
"types/billing-payment-source-methods.mdx",
26-
"types/billing-payment-source-resource.mdx",
27-
"types/billing-payment-source-status.mdx",
2828
"types/billing-payment-status.mdx",
2929
"types/billing-plan-json.mdx",
3030
"types/billing-plan-resource.mdx",
@@ -72,21 +72,21 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
7272
"types/field-errors.mdx",
7373
"types/for-payer-type.mdx",
7474
"types/get-payment-attempts-params.mdx",
75-
"types/get-payment-sources-params.mdx",
75+
"types/get-payment-methods-params.mdx",
7676
"types/get-plans-params.mdx",
7777
"types/get-statements-params.mdx",
7878
"types/get-subscription-params.mdx",
7979
"types/get-token.mdx",
8080
"types/id-selectors.mdx",
81-
"types/initialize-payment-source-params.mdx",
81+
"types/initialize-payment-method-params.mdx",
8282
"types/internal_checkout-props.mdx",
8383
"types/internal_plan-details-props.mdx",
8484
"types/internal_subscription-details-props.mdx",
8585
"types/jwt-claims.mdx",
8686
"types/jwt-header.mdx",
8787
"types/legacy-redirect-props.mdx",
8888
"types/localization-resource.mdx",
89-
"types/make-default-payment-source-params.mdx",
89+
"types/make-default-payment-method-params.mdx",
9090
"types/multi-domain-and-or-proxy.mdx",
9191
"types/organization-custom-role-key.mdx",
9292
"types/organization-domain-resource.mdx",
@@ -109,7 +109,7 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
109109
"types/protect-props.mdx",
110110
"types/record-to-path.mdx",
111111
"types/redirect-options.mdx",
112-
"types/remove-payment-source-params.mdx",
112+
"types/remove-payment-method-params.mdx",
113113
"types/reverification-config.mdx",
114114
"types/saml-strategy.mdx",
115115
"types/sdk-metadata.mdx",

packages/clerk-js/src/core/modules/billing/namespace.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ import {
2828
} from '../../resources/internal';
2929

3030
export class Billing implements BillingNamespace {
31+
static readonly #pathRoot = '/commerce';
32+
static path(subPath: string, param?: { orgId?: string }): string {
33+
const { orgId } = param || {};
34+
const prefix = orgId ? `/organizations/${orgId}` : '/me';
35+
return `${prefix}${Billing.#pathRoot}${subPath}`;
36+
}
37+
3138
getPlans = async (params?: GetPlansParams): Promise<ClerkPaginatedResponse<BillingPlanResource>> => {
3239
const { for: forParam, ...safeParams } = params || {};
3340
const searchParams = { ...safeParams, payer_type: forParam === 'organization' ? 'org' : 'user' };
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
11
import type {
2-
AddPaymentSourceParams,
3-
BillingInitializedPaymentSourceJSON,
4-
BillingPaymentSourceJSON,
2+
AddPaymentMethodParams,
3+
BillingInitializedPaymentMethodJSON,
4+
BillingPaymentMethodJSON,
55
ClerkPaginatedResponse,
6-
GetPaymentSourcesParams,
7-
InitializePaymentSourceParams,
6+
GetPaymentMethodsParams,
7+
InitializePaymentMethodParams,
88
} from '@clerk/types';
99

1010
import { convertPageToOffsetSearchParams } from '../../../utils/convertPageToOffsetSearchParams';
11-
import { BaseResource, BillingInitializedPaymentSource, BillingPaymentSource } from '../../resources/internal';
11+
import { BaseResource, BillingInitializedPaymentMethod, BillingPaymentMethod } from '../../resources/internal';
12+
import { Billing } from './namespace';
1213

13-
export const initializePaymentSource = async (params: InitializePaymentSourceParams) => {
14+
const PAYMENT_METHODS_PATH = '/payment_methods';
15+
16+
export const initializePaymentMethod = async (params: InitializePaymentMethodParams) => {
1417
const { orgId, ...rest } = params;
1518
const json = (
1619
await BaseResource._fetch({
17-
path: orgId
18-
? `/organizations/${orgId}/commerce/payment_sources/initialize`
19-
: `/me/commerce/payment_sources/initialize`,
20+
path: Billing.path(`${PAYMENT_METHODS_PATH}/initialize`, { orgId }),
2021
method: 'POST',
2122
body: rest as any,
2223
})
23-
)?.response as unknown as BillingInitializedPaymentSourceJSON;
24-
return new BillingInitializedPaymentSource(json);
24+
)?.response as unknown as BillingInitializedPaymentMethodJSON;
25+
return new BillingInitializedPaymentMethod(json);
2526
};
2627

27-
export const addPaymentSource = async (params: AddPaymentSourceParams) => {
28+
export const addPaymentMethod = async (params: AddPaymentMethodParams) => {
2829
const { orgId, ...rest } = params;
2930

3031
const json = (
3132
await BaseResource._fetch({
32-
path: orgId ? `/organizations/${orgId}/commerce/payment_sources` : `/me/commerce/payment_sources`,
33+
path: Billing.path(PAYMENT_METHODS_PATH, { orgId }),
3334
method: 'POST',
3435
body: rest as any,
3536
})
36-
)?.response as unknown as BillingPaymentSourceJSON;
37-
return new BillingPaymentSource(json);
37+
)?.response as unknown as BillingPaymentMethodJSON;
38+
return new BillingPaymentMethod(json);
3839
};
3940

40-
export const getPaymentSources = async (params: GetPaymentSourcesParams) => {
41+
export const getPaymentMethods = async (params: GetPaymentMethodsParams) => {
4142
const { orgId, ...rest } = params;
4243

4344
return await BaseResource._fetch({
44-
path: orgId ? `/organizations/${orgId}/commerce/payment_sources` : `/me/commerce/payment_sources`,
45+
path: Billing.path(PAYMENT_METHODS_PATH, { orgId }),
4546
method: 'GET',
4647
search: convertPageToOffsetSearchParams(rest),
4748
}).then(res => {
4849
const { data: paymentSources, total_count } =
49-
res?.response as unknown as ClerkPaginatedResponse<BillingPaymentSourceJSON>;
50+
res?.response as unknown as ClerkPaginatedResponse<BillingPaymentMethodJSON>;
5051
return {
5152
total_count,
52-
data: paymentSources.map(paymentSource => new BillingPaymentSource(paymentSource)),
53+
data: paymentSources.map(paymentMethod => new BillingPaymentMethod(paymentMethod)),
5354
};
5455
});
5556
};

packages/clerk-js/src/core/resources/BillingCheckout.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
BillingCheckoutResource,
66
BillingCheckoutTotals,
77
BillingPayerResource,
8+
BillingPaymentMethodResource,
89
BillingSubscriptionPlanPeriod,
910
ConfirmCheckoutParams,
1011
} from '@clerk/types';
@@ -13,13 +14,13 @@ import { unixEpochToDate } from '@/utils/date';
1314

1415
import { billingTotalsFromJSON } from '../../utils';
1516
import { BillingPayer } from './BillingPayer';
16-
import { BaseResource, BillingPaymentSource, BillingPlan } from './internal';
17+
import { BaseResource, BillingPaymentMethod, BillingPlan } from './internal';
1718

1819
export class BillingCheckout extends BaseResource implements BillingCheckoutResource {
1920
id!: string;
2021
externalClientSecret!: string;
2122
externalGatewayId!: string;
22-
paymentSource?: BillingPaymentSource;
23+
paymentMethod?: BillingPaymentMethodResource;
2324
plan!: BillingPlan;
2425
planPeriod!: BillingSubscriptionPlanPeriod;
2526
planPeriodStart!: number | undefined;
@@ -42,7 +43,7 @@ export class BillingCheckout extends BaseResource implements BillingCheckoutReso
4243
this.id = data.id;
4344
this.externalClientSecret = data.external_client_secret;
4445
this.externalGatewayId = data.external_gateway_id;
45-
this.paymentSource = data.payment_source ? new BillingPaymentSource(data.payment_source) : undefined;
46+
this.paymentMethod = data.payment_method ? new BillingPaymentMethod(data.payment_method) : undefined;
4647
this.plan = new BillingPlan(data.plan);
4748
this.planPeriod = data.plan_period;
4849
this.planPeriodStart = data.plan_period_start;

packages/clerk-js/src/core/resources/BillingPayment.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ import type {
22
BillingMoneyAmount,
33
BillingPaymentChargeType,
44
BillingPaymentJSON,
5+
BillingPaymentMethodResource,
56
BillingPaymentResource,
6-
BillingPaymentSourceResource,
77
BillingPaymentStatus,
88
BillingSubscriptionItemResource,
99
} from '@clerk/types';
1010

1111
import { billingMoneyAmountFromJSON } from '../../utils';
1212
import { unixEpochToDate } from '../../utils/date';
13-
import { BaseResource, BillingPaymentSource, BillingSubscriptionItem } from './internal';
13+
import { BaseResource, BillingPaymentMethod, BillingSubscriptionItem } from './internal';
1414

1515
export class BillingPayment extends BaseResource implements BillingPaymentResource {
1616
id!: string;
1717
amount!: BillingMoneyAmount;
1818
failedAt?: Date;
1919
paidAt?: Date;
2020
updatedAt!: Date;
21-
paymentSource!: BillingPaymentSourceResource;
21+
paymentMethod!: BillingPaymentMethodResource;
2222
subscriptionItem!: BillingSubscriptionItemResource;
2323
chargeType!: BillingPaymentChargeType;
2424
status!: BillingPaymentStatus;
@@ -38,7 +38,7 @@ export class BillingPayment extends BaseResource implements BillingPaymentResour
3838
this.paidAt = data.paid_at ? unixEpochToDate(data.paid_at) : undefined;
3939
this.failedAt = data.failed_at ? unixEpochToDate(data.failed_at) : undefined;
4040
this.updatedAt = unixEpochToDate(data.updated_at);
41-
this.paymentSource = new BillingPaymentSource(data.payment_source);
41+
this.paymentMethod = new BillingPaymentMethod(data.payment_method);
4242
this.subscriptionItem = new BillingSubscriptionItem(data.subscription_item);
4343
this.chargeType = data.charge_type;
4444
this.status = data.status;

packages/clerk-js/src/core/resources/BillingPaymentSource.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
import type {
2-
BillingInitializedPaymentSourceJSON,
3-
BillingInitializedPaymentSourceResource,
4-
BillingPaymentSourceJSON,
5-
BillingPaymentSourceResource,
6-
BillingPaymentSourceStatus,
2+
BillingInitializedPaymentMethodJSON,
3+
BillingInitializedPaymentMethodResource,
4+
BillingPaymentMethodJSON,
5+
BillingPaymentMethodResource,
6+
BillingPaymentMethodStatus,
77
DeletedObjectJSON,
8-
MakeDefaultPaymentSourceParams,
9-
RemovePaymentSourceParams,
8+
MakeDefaultPaymentMethodParams,
9+
RemovePaymentMethodParams,
1010
} from '@clerk/types';
1111

1212
import { BaseResource, DeletedObject } from './internal';
1313

14-
export class BillingPaymentSource extends BaseResource implements BillingPaymentSourceResource {
14+
export class BillingPaymentMethod extends BaseResource implements BillingPaymentMethodResource {
1515
id!: string;
1616
last4!: string;
17-
paymentMethod!: string;
17+
paymentType!: 'card' | 'link';
1818
cardType!: string;
1919
isDefault!: boolean;
2020
isRemovable!: boolean;
21-
status!: BillingPaymentSourceStatus;
21+
status!: BillingPaymentMethodStatus;
2222
walletType: string | undefined;
2323

24-
constructor(data: BillingPaymentSourceJSON) {
24+
constructor(data: BillingPaymentMethodJSON) {
2525
super();
2626
this.fromJSON(data);
2727
}
2828

29-
protected fromJSON(data: BillingPaymentSourceJSON | null): this {
29+
protected fromJSON(data: BillingPaymentMethodJSON | null): this {
3030
if (!data) {
3131
return this;
3232
}
3333

3434
this.id = data.id;
3535
this.last4 = data.last4;
36-
this.paymentMethod = data.payment_method;
36+
this.paymentType = data.payment_type;
3737
this.cardType = data.card_type;
3838
this.isDefault = data.is_default;
3939
this.isRemovable = data.is_removable;
@@ -43,7 +43,7 @@ export class BillingPaymentSource extends BaseResource implements BillingPayment
4343
return this;
4444
}
4545

46-
public async remove(params?: RemovePaymentSourceParams) {
46+
public async remove(params?: RemovePaymentMethodParams) {
4747
const { orgId } = params ?? {};
4848
const json = (
4949
await BaseResource._fetch({
@@ -57,7 +57,7 @@ export class BillingPaymentSource extends BaseResource implements BillingPayment
5757
return new DeletedObject(json);
5858
}
5959

60-
public async makeDefault(params?: MakeDefaultPaymentSourceParams) {
60+
public async makeDefault(params?: MakeDefaultPaymentMethodParams) {
6161
const { orgId } = params ?? {};
6262
await BaseResource._fetch({
6363
path: orgId
@@ -71,17 +71,17 @@ export class BillingPaymentSource extends BaseResource implements BillingPayment
7171
}
7272
}
7373

74-
export class BillingInitializedPaymentSource extends BaseResource implements BillingInitializedPaymentSourceResource {
74+
export class BillingInitializedPaymentMethod extends BaseResource implements BillingInitializedPaymentMethodResource {
7575
externalClientSecret!: string;
7676
externalGatewayId!: string;
7777
paymentMethodOrder!: string[];
7878

79-
constructor(data: BillingInitializedPaymentSourceJSON) {
79+
constructor(data: BillingInitializedPaymentMethodJSON) {
8080
super();
8181
this.fromJSON(data);
8282
}
8383

84-
protected fromJSON(data: BillingInitializedPaymentSourceJSON | null): this {
84+
protected fromJSON(data: BillingInitializedPaymentMethodJSON | null): this {
8585
if (!data) {
8686
return this;
8787
}

packages/clerk-js/src/core/resources/BillingSubscription.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class BillingSubscription extends BaseResource implements BillingSubscrip
5959

6060
export class BillingSubscriptionItem extends BaseResource implements BillingSubscriptionItemResource {
6161
id!: string;
62-
paymentSourceId!: string;
62+
paymentMethodId!: string;
6363
plan!: BillingPlan;
6464
planPeriod!: BillingSubscriptionPlanPeriod;
6565
status!: BillingSubscriptionStatus;
@@ -86,7 +86,7 @@ export class BillingSubscriptionItem extends BaseResource implements BillingSubs
8686
}
8787

8888
this.id = data.id;
89-
this.paymentSourceId = data.payment_source_id;
89+
this.paymentMethodId = data.payment_method_id;
9090
this.plan = new BillingPlan(data.plan);
9191
this.planPeriod = data.plan_period;
9292
this.status = data.status;

packages/clerk-js/src/core/resources/Organization.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type {
2828

2929
import { convertPageToOffsetSearchParams } from '../../utils/convertPageToOffsetSearchParams';
3030
import { unixEpochToDate } from '../../utils/date';
31-
import { addPaymentSource, getPaymentSources, initializePaymentSource } from '../modules/billing';
31+
import { addPaymentMethod, getPaymentMethods, initializePaymentMethod } from '../modules/billing';
3232
import { BaseResource, OrganizationInvitation, OrganizationMembership } from './internal';
3333
import { OrganizationDomain } from './OrganizationDomain';
3434
import { OrganizationMembershipRequest } from './OrganizationMembershipRequest';
@@ -262,22 +262,22 @@ export class Organization extends BaseResource implements OrganizationResource {
262262
}).then(res => new Organization(res?.response as OrganizationJSON));
263263
};
264264

265-
initializePaymentSource: typeof initializePaymentSource = params => {
266-
return initializePaymentSource({
265+
initializePaymentMethod: typeof initializePaymentMethod = params => {
266+
return initializePaymentMethod({
267267
...params,
268268
orgId: this.id,
269269
});
270270
};
271271

272-
addPaymentSource: typeof addPaymentSource = params => {
273-
return addPaymentSource({
272+
addPaymentMethod: typeof addPaymentMethod = params => {
273+
return addPaymentMethod({
274274
...params,
275275
orgId: this.id,
276276
});
277277
};
278278

279-
getPaymentSources: typeof getPaymentSources = params => {
280-
return getPaymentSources({
279+
getPaymentMethods: typeof getPaymentMethods = params => {
280+
return getPaymentMethods({
281281
...params,
282282
orgId: this.id,
283283
});

0 commit comments

Comments
 (0)