Skip to content

Commit be2e89c

Browse files
authored
chore(clerk-js,types): Use is_removable flag on payment sources (#6033)
1 parent 30bac73 commit be2e89c

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

.changeset/happy-bees-post.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/types': patch
4+
---
5+
6+
Use the `is_removable` flag on a payment source to determine if it can be removed.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class CommercePaymentSource extends BaseResource implements CommercePayme
1717
paymentMethod!: string;
1818
cardType!: string;
1919
isDefault!: boolean;
20+
isRemovable!: boolean;
2021
status!: CommercePaymentSourceStatus;
2122
walletType: string | undefined;
2223

@@ -35,6 +36,7 @@ export class CommercePaymentSource extends BaseResource implements CommercePayme
3536
this.paymentMethod = data.payment_method;
3637
this.cardType = data.card_type;
3738
this.isDefault = data.is_default;
39+
this.isRemovable = data.is_removable;
3840
this.status = data.status;
3941
this.walletType = data.wallet_type ?? undefined;
4042

packages/clerk-js/src/ui/components/PaymentSources/PaymentSources.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { SetupIntent } from '@stripe/stripe-js';
44
import { Fragment, useCallback, useMemo, useRef } from 'react';
55

66
import { RemoveResourceForm } from '../../common';
7-
import { usePaymentSources, useSubscriberTypeContext, useSubscriptions } from '../../contexts';
7+
import { usePaymentSources, useSubscriberTypeContext } from '../../contexts';
88
import { localizationKeys } from '../../customizables';
99
import { FullHeightLoader, ProfileSection, ThreeDotsMenu, useCardState, withCardStateProvider } from '../../elements';
1010
import { Action } from '../../elements/Action';
@@ -174,14 +174,13 @@ const PaymentSourceMenu = ({
174174
const card = useCardState();
175175
const { organization } = useOrganization();
176176
const subscriberType = useSubscriberTypeContext();
177-
const { data: subscriptions } = useSubscriptions();
178177

179178
const actions = [
180179
{
181180
label: localizationKeys('userProfile.billingPage.paymentSourcesSection.actionLabel__remove'),
182181
isDestructive: true,
183182
onClick: () => open(`remove-${paymentSource.id}`),
184-
isDisabled: paymentSource.isDefault && subscriptions.some(s => !s.plan.isDefault),
183+
isDisabled: !paymentSource.isRemovable,
185184
},
186185
];
187186

packages/types/src/commerce.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export interface CommercePaymentSourceResource extends ClerkResource {
9696
paymentMethod: string;
9797
cardType: string;
9898
isDefault: boolean;
99+
isRemovable: boolean;
99100
status: CommercePaymentSourceStatus;
100101
walletType: string | undefined;
101102
remove: (params?: RemovePaymentSourceParams) => Promise<DeletedObjectResource>;

packages/types/src/json.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ export interface CommercePaymentSourceJSON extends ClerkResourceJSON {
638638
payment_method: string;
639639
card_type: string;
640640
is_default: boolean;
641+
is_removable: boolean;
641642
status: CommercePaymentSourceStatus;
642643
wallet_type: string | null;
643644
}

0 commit comments

Comments
 (0)