Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/kind-ghosts-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
12 changes: 5 additions & 7 deletions packages/clerk-js/src/core/resources/BillingPaymentSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type {
RemovePaymentMethodParams,
} from '@clerk/types';

import { Billing } from '@/core/modules/billing';

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

export class BillingPaymentMethod extends BaseResource implements BillingPaymentMethodResource {
Expand Down Expand Up @@ -47,9 +49,7 @@ export class BillingPaymentMethod extends BaseResource implements BillingPayment
const { orgId } = params ?? {};
const json = (
await BaseResource._fetch({
path: orgId
? `/organizations/${orgId}/commerce/payment_sources/${this.id}`
: `/me/commerce/payment_sources/${this.id}`,
path: Billing.path(`/payment_methods/${this.id}`, { orgId }),
method: 'DELETE',
})
)?.response as unknown as DeletedObjectJSON;
Expand All @@ -60,11 +60,9 @@ export class BillingPaymentMethod extends BaseResource implements BillingPayment
public async makeDefault(params?: MakeDefaultPaymentMethodParams) {
const { orgId } = params ?? {};
await BaseResource._fetch({
path: orgId
? `/organizations/${orgId}/commerce/payers/default_payment_source`
: `/me/commerce/payers/default_payment_source`,
path: Billing.path(`/payers/default_payment_method`, { orgId }),
method: 'PUT',
body: { payment_source_id: this.id } as any,
body: { payment_method_id: this.id } as any,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify backend API compatibility for the payload key change.

The request body key has been changed from payment_source_id to payment_method_id. Ensure the backend API has been updated to accept this new key name, as this is a breaking change.


🏁 Script executed:

#!/bin/bash
set -e

echo "Searching for old key 'payment_source_id'"
rg -n 'payment_source_id' -C2

echo "Searching for new key 'payment_method_id'"
rg -n 'payment_method_id' -C2

Length of output: 4084


Backend schema still expects payment_source_id Update packages/backend/src/api/resources/JSON.ts:990 to accept payment_method_id or revert the payload key rename.

🤖 Prompt for AI Agents
In packages/clerk-js/src/core/resources/BillingPaymentSource.ts around line 65,
the code sends body: { payment_method_id: this.id } but the backend schema still
expects payment_source_id; either change this client payload back to
payment_source_id or update packages/backend/src/api/resources/JSON.ts at ~line
990 to accept payment_method_id (or both for backward compatibility). Modify the
client to send payment_source_id (preferred) or update the backend
schema/validation to accept both keys and map payment_method_id to
payment_source_id so requests succeed without breaking existing consumers.

});

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ describe('Checkout', () => {
freeTrialDays: 14,
freeTrialEnabled: true,
},
paymentSource: undefined,
paymentMethod: undefined,
confirm: vi.fn(),
freeTrialEndsAt,
} as any);
Expand Down Expand Up @@ -758,7 +758,7 @@ describe('Checkout', () => {
onOpenChange={() => {}}
>
<Checkout
planId='plan_with_payment_sources'
planId='plan_with_payment_methods'
planPeriod='month'
/>
</Drawer.Root>,
Expand Down Expand Up @@ -897,7 +897,7 @@ describe('Checkout', () => {
onOpenChange={() => {}}
>
<Checkout
planId='plan_with_payment_sources'
planId='plan_with_payment_methods'
planPeriod='month'
/>
</Drawer.Root>,
Expand Down Expand Up @@ -1036,7 +1036,7 @@ describe('Checkout', () => {
onOpenChange={() => {}}
>
<Checkout
planId='plan_with_payment_sources'
planId='plan_with_payment_methods'
planPeriod='month'
/>
</Drawer.Root>,
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/react/hooks/useCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const useCheckout = (options?: Params): __experimental_UseCheckoutReturn
isImmediatePlanChange: null,
planPeriod: null,
plan: null,
paymentSource: null,
paymentMethod: null,
freeTrialEndsAt: null,
payer: null,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ export interface BillingPaymentMethodJSON extends ClerkResourceJSON {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingInitializedPaymentMethodJSON extends ClerkResourceJSON {
object: 'commerce_payment_source_initialize';
object: 'commerce_payment_method_initialize';
external_client_secret: string;
external_gateway_id: string;
payment_method_order: string[];
Expand Down
Loading