Skip to content

Commit 822ba1f

Browse files
authored
chore(shared,clerk-js): Align for payer type across billing APIs (#6423)
1 parent d58b959 commit 822ba1f

34 files changed

+116
-104
lines changed

.changeset/some-parents-begin.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/shared': minor
4+
'@clerk/types': minor
5+
---
6+
7+
[Billing Beta]: Replace `org` for `organization` as payer type for billing APIs.
8+
9+
This applies for all billing APIs, except the resources classes that represent data from Frontend API.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
3232
"types/commerce-initialized-payment-source-resource.mdx",
3333
"types/commerce-money-json.mdx",
3434
"types/commerce-money.mdx",
35-
"types/commerce-payer-type.mdx",
35+
"types/commerce-payer-resource-type.mdx",
3636
"types/commerce-payment-charge-type.mdx",
3737
"types/commerce-payment-json.mdx",
3838
"types/commerce-payment-resource.mdx",
@@ -66,6 +66,7 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
6666
"types/experimental_checkout-button-props.mdx",
6767
"types/experimental_plan-details-button-props.mdx",
6868
"types/experimental_subscription-details-button-props.mdx",
69+
"types/for-payer-type.mdx",
6970
"types/get-payment-attempts-params.mdx",
7071
"types/get-payment-sources-params.mdx",
7172
"types/get-plans-params.mdx",

packages/clerk-js/src/core/modules/commerce/CommerceBilling.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
export class CommerceBilling implements CommerceBillingNamespace {
3535
getPlans = async (params?: GetPlansParams): Promise<ClerkPaginatedResponse<CommercePlanResource>> => {
3636
const { for: forParam, ...safeParams } = params || {};
37-
const searchParams = { ...safeParams, payer_type: forParam || 'user' };
37+
const searchParams = { ...safeParams, payer_type: forParam === 'organization' ? 'org' : 'user' };
3838
return await BaseResource._fetch({
3939
path: `/commerce/plans`,
4040
method: 'GET',

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { CommercePayerType, CommercePlanJSON, CommercePlanJSONSnapshot, CommercePlanResource } from '@clerk/types';
1+
import type {
2+
CommercePayerResourceType,
3+
CommercePlanJSON,
4+
CommercePlanJSONSnapshot,
5+
CommercePlanResource,
6+
} from '@clerk/types';
27

38
import { BaseResource, CommerceFeature } from './internal';
49

@@ -17,7 +22,7 @@ export class CommercePlan extends BaseResource implements CommercePlanResource {
1722
isDefault!: boolean;
1823
isRecurring!: boolean;
1924
hasBaseFee!: boolean;
20-
forPayerType!: CommercePayerType;
25+
forPayerType!: CommercePayerResourceType;
2126
publiclyVisible!: boolean;
2227
slug!: string;
2328
avatarUrl!: string;

packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const CheckoutForm = withCardStateProvider(() => {
115115

116116
const useCheckoutMutations = () => {
117117
const { organization } = useOrganization();
118-
const { subscriberType, onSubscriptionComplete } = useCheckoutContext();
118+
const { for: _for, onSubscriptionComplete } = useCheckoutContext();
119119
const { checkout } = useCheckout();
120120
const { id, confirm } = checkout;
121121
const card = useCardState();
@@ -130,7 +130,8 @@ const useCheckoutMutations = () => {
130130

131131
const { data, error } = await confirm({
132132
...params,
133-
...(subscriberType === 'org' ? { orgId: organization?.id } : {}),
133+
// TODO(@COMMERCE): Come back to this, this should not be needed
134+
...(_for === 'organization' ? { orgId: organization?.id } : {}),
134135
});
135136

136137
if (error) {

packages/clerk-js/src/ui/components/Checkout/CheckoutPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ const Initiator = () => {
1010
const { checkout } = useCheckout();
1111

1212
useEffect(() => {
13-
checkout.start().catch(() => null);
13+
void checkout.start();
1414
return checkout.clear;
1515
}, []);
1616
return null;
1717
};
1818

1919
const Root = ({ children }: { children: React.ReactNode }) => {
20-
const { planId, planPeriod, subscriberType } = useCheckoutContext();
20+
const { planId, planPeriod, for: _for } = useCheckoutContext();
2121

2222
return (
2323
<CheckoutProvider
24-
for={subscriberType === 'org' ? 'organization' : undefined}
24+
for={_for}
2525
planId={
2626
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2727
planId!

packages/clerk-js/src/ui/components/Checkout/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const Checkout = (props: __internal_CheckoutProps) => {
1313
return (
1414
<Flow.Root flow='checkout'>
1515
<Flow.Part>
16-
<SubscriberTypeContext.Provider value={props.subscriberType || 'user'}>
16+
<SubscriberTypeContext.Provider value={props.for || 'user'}>
1717
<CheckoutContext.Provider
1818
value={{
1919
componentName: 'Checkout',

packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationBillingPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const OrganizationBillingPageInternal = withCardStateProvider(() => {
8383

8484
export const OrganizationBillingPage = () => {
8585
return (
86-
<SubscriberTypeContext.Provider value='org'>
86+
<SubscriberTypeContext.Provider value='organization'>
8787
<OrganizationBillingPageInternal />
8888
</SubscriberTypeContext.Provider>
8989
);

packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationPaymentAttemptPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PaymentAttemptPage } from '../PaymentAttempts';
33

44
export const OrganizationPaymentAttemptPage = () => {
55
return (
6-
<SubscriberTypeContext.Provider value='org'>
6+
<SubscriberTypeContext.Provider value='organization'>
77
<PaymentAttemptPage />
88
</SubscriberTypeContext.Provider>
99
);

packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationPlansPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const OrganizationPlansPageInternal = () => {
5353

5454
export const OrganizationPlansPage = () => {
5555
return (
56-
<SubscriberTypeContext.Provider value='org'>
56+
<SubscriberTypeContext.Provider value='organization'>
5757
<OrganizationPlansPageInternal />
5858
</SubscriberTypeContext.Provider>
5959
);

0 commit comments

Comments
 (0)