-
Notifications
You must be signed in to change notification settings - Fork 391
chore(clerk-js,types): Align payment methods terminology #6865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
cb47eea
74383e5
4dc4c44
2ae5a17
8ed4a25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@clerk/clerk-js': minor | ||
'@clerk/shared': patch | ||
'@clerk/types': minor | ||
--- | ||
|
||
[Billing Beta] Rename payment source to payment method. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,56 @@ | ||
import type { | ||
AddPaymentSourceParams, | ||
BillingInitializedPaymentSourceJSON, | ||
BillingPaymentSourceJSON, | ||
AddPaymentMethodParams, | ||
BillingInitializedPaymentMethodJSON, | ||
BillingPaymentMethodJSON, | ||
ClerkPaginatedResponse, | ||
GetPaymentSourcesParams, | ||
InitializePaymentSourceParams, | ||
GetPaymentMethodsParams, | ||
InitializePaymentMethodParams, | ||
} from '@clerk/types'; | ||
|
||
import { convertPageToOffsetSearchParams } from '../../../utils/convertPageToOffsetSearchParams'; | ||
import { BaseResource, BillingInitializedPaymentSource, BillingPaymentSource } from '../../resources/internal'; | ||
import { BaseResource, BillingInitializedPaymentMethod, BillingPaymentMethod } from '../../resources/internal'; | ||
import { Billing } from './namespace'; | ||
|
||
export const initializePaymentSource = async (params: InitializePaymentSourceParams) => { | ||
const PAYMENT_METHODS_PATH = '/payment_methods'; | ||
|
||
export const initializePaymentMethod = async (params: InitializePaymentMethodParams) => { | ||
const { orgId, ...rest } = params; | ||
const json = ( | ||
await BaseResource._fetch({ | ||
path: orgId | ||
? `/organizations/${orgId}/commerce/payment_sources/initialize` | ||
: `/me/commerce/payment_sources/initialize`, | ||
path: Billing.path(`${PAYMENT_METHODS_PATH}/initialize`, { orgId }), | ||
method: 'POST', | ||
body: rest as any, | ||
}) | ||
)?.response as unknown as BillingInitializedPaymentSourceJSON; | ||
return new BillingInitializedPaymentSource(json); | ||
)?.response as unknown as BillingInitializedPaymentMethodJSON; | ||
return new BillingInitializedPaymentMethod(json); | ||
}; | ||
|
||
export const addPaymentSource = async (params: AddPaymentSourceParams) => { | ||
export const addPaymentMethod = async (params: AddPaymentMethodParams) => { | ||
const { orgId, ...rest } = params; | ||
|
||
const json = ( | ||
await BaseResource._fetch({ | ||
path: orgId ? `/organizations/${orgId}/commerce/payment_sources` : `/me/commerce/payment_sources`, | ||
path: Billing.path(PAYMENT_METHODS_PATH, { orgId }), | ||
method: 'POST', | ||
body: rest as any, | ||
}) | ||
)?.response as unknown as BillingPaymentSourceJSON; | ||
return new BillingPaymentSource(json); | ||
)?.response as unknown as BillingPaymentMethodJSON; | ||
return new BillingPaymentMethod(json); | ||
}; | ||
|
||
export const getPaymentSources = async (params: GetPaymentSourcesParams) => { | ||
export const getPaymentMethods = async (params: GetPaymentMethodsParams) => { | ||
const { orgId, ...rest } = params; | ||
|
||
return await BaseResource._fetch({ | ||
path: orgId ? `/organizations/${orgId}/commerce/payment_sources` : `/me/commerce/payment_sources`, | ||
path: Billing.path(PAYMENT_METHODS_PATH, { orgId }), | ||
method: 'GET', | ||
search: convertPageToOffsetSearchParams(rest), | ||
}).then(res => { | ||
const { data: paymentSources, total_count } = | ||
res?.response as unknown as ClerkPaginatedResponse<BillingPaymentSourceJSON>; | ||
res?.response as unknown as ClerkPaginatedResponse<BillingPaymentMethodJSON>; | ||
return { | ||
total_count, | ||
data: paymentSources.map(paymentSource => new BillingPaymentSource(paymentSource)), | ||
data: paymentSources.map(paymentMethod => new BillingPaymentMethod(paymentMethod)), | ||
}; | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||||||||||||||||
import { __experimental_useCheckout as useCheckout } from '@clerk/shared/react'; | ||||||||||||||||||||
import type { BillingMoneyAmount, BillingPaymentSourceResource, ConfirmCheckoutParams } from '@clerk/types'; | ||||||||||||||||||||
import type { BillingMoneyAmount, BillingPaymentMethodResource, ConfirmCheckoutParams } from '@clerk/types'; | ||||||||||||||||||||
import { useMemo, useState } from 'react'; | ||||||||||||||||||||
|
||||||||||||||||||||
import { Card } from '@/ui/elements/Card'; | ||||||||||||||||||||
|
@@ -367,16 +367,16 @@ const ExistingPaymentSourceForm = withCardStateProvider( | |||||||||||||||||||
paymentSources, | ||||||||||||||||||||
}: { | ||||||||||||||||||||
totalDueNow: BillingMoneyAmount; | ||||||||||||||||||||
paymentSources: BillingPaymentSourceResource[]; | ||||||||||||||||||||
paymentSources: BillingPaymentMethodResource[]; | ||||||||||||||||||||
}) => { | ||||||||||||||||||||
const submitLabel = useSubmitLabel(); | ||||||||||||||||||||
const { checkout } = useCheckout(); | ||||||||||||||||||||
const { paymentSource, isImmediatePlanChange, freeTrialEndsAt } = checkout; | ||||||||||||||||||||
const { paymentMethod, isImmediatePlanChange, freeTrialEndsAt } = checkout; | ||||||||||||||||||||
|
||||||||||||||||||||
const { payWithExistingPaymentSource } = useCheckoutMutations(); | ||||||||||||||||||||
const card = useCardState(); | ||||||||||||||||||||
const [selectedPaymentSource, setSelectedPaymentSource] = useState<BillingPaymentSourceResource | undefined>( | ||||||||||||||||||||
paymentSource || paymentSources.find(p => p.isDefault), | ||||||||||||||||||||
const [selectedPaymentSource, setSelectedPaymentSource] = useState<BillingPaymentMethodResource | undefined>( | ||||||||||||||||||||
paymentMethod || paymentSources.find(p => p.isDefault), | ||||||||||||||||||||
); | ||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+380
to
382
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restore fallback when preselecting payment method With the new initialization, - const [selectedPaymentSource, setSelectedPaymentSource] = useState<BillingPaymentMethodResource | undefined>(
- paymentMethod || paymentSources.find(p => p.isDefault),
- );
+ const defaultPaymentMethod =
+ paymentMethod ?? paymentSources.find(p => p.isDefault) ?? paymentSources[0];
+
+ const [selectedPaymentSource, setSelectedPaymentSource] = useState<BillingPaymentMethodResource | undefined>(
+ defaultPaymentMethod,
+ ); 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||
|
||||||||||||||||||||
const options = useMemo(() => { | ||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.