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
5 changes: 5 additions & 0 deletions .changeset/fluffy-snails-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Revalidate payment sources from `<Checkout />` when a new payment source is added before the checkout is completed.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ const AddPaymentSourceForm = withCardStateProvider(
const { subscriberType } = usePaymentSourcesContext();
const [submitError, setSubmitError] = useState<ClerkRuntimeError | ClerkAPIError | string | undefined>();

// Revalidates the next time the hooks gets mounted
const { revalidate } = useFetch(
undefined,
{
...(subscriberType === 'org' ? { orgId: organization?.id } : {}),
},
undefined,
'commerce-payment-sources',
);

const onSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (!stripe || !elements) {
Expand All @@ -167,6 +177,8 @@ const AddPaymentSourceForm = withCardStateProvider(
...(subscriberType === 'org' ? { orgId: organization?.id } : {}),
});

revalidate();

void onSuccess(paymentSource);
} catch (error) {
void handleError(error, [], setSubmitError);
Expand Down