1
- import { useClerk } from '@clerk/shared/react' ;
1
+ import { useClerk , useOrganization } from '@clerk/shared/react' ;
2
2
import type {
3
3
__experimental_CommerceCheckoutResource ,
4
4
__experimental_CommerceMoney ,
@@ -8,6 +8,7 @@ import type {
8
8
} from '@clerk/types' ;
9
9
import { useMemo , useState } from 'react' ;
10
10
11
+ import { __experimental_PaymentSourcesContext , useCheckoutContext } from '../../contexts' ;
11
12
import { Box , Button , Col , descriptors , Flex , Form , Icon , localizationKeys , Text } from '../../customizables' ;
12
13
import { Alert , Disclosure , Divider , Drawer , LineItems , Select , SelectButton , SelectOptionList } from '../../elements' ;
13
14
import { useFetch } from '../../hooks' ;
@@ -90,17 +91,29 @@ const CheckoutFormElements = ({
90
91
onCheckoutComplete : ( checkout : __experimental_CommerceCheckoutResource ) => void ;
91
92
} ) => {
92
93
const { __experimental_commerce } = useClerk ( ) ;
94
+ const { organization } = useOrganization ( ) ;
95
+ const { subscriberType } = useCheckoutContext ( ) ;
93
96
const [ openAccountFundsDropDown , setOpenAccountFundsDropDown ] = useState ( true ) ;
94
97
const [ openAddNewSourceDropDown , setOpenAddNewSourceDropDown ] = useState ( true ) ;
95
98
const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
96
99
const [ submitError , setSubmitError ] = useState < ClerkRuntimeError | ClerkAPIError | string | undefined > ( ) ;
97
100
98
- const { data } = useFetch ( __experimental_commerce ?. getPaymentSources , 'commerce-payment-sources' ) ;
101
+ const { data } = useFetch (
102
+ __experimental_commerce ?. getPaymentSources ,
103
+ {
104
+ ...( subscriberType === 'org' ? { orgId : organization ?. id } : { } ) ,
105
+ } ,
106
+ undefined ,
107
+ 'commerce-payment-sources' ,
108
+ ) ;
99
109
const { data : paymentSources } = data || { data : [ ] } ;
100
110
101
111
const confirmCheckout = async ( { paymentSourceId } : { paymentSourceId : string } ) => {
102
112
return checkout
103
- . confirm ( { paymentSourceId } )
113
+ . confirm ( {
114
+ paymentSourceId,
115
+ ...( subscriberType === 'org' ? { orgId : organization ?. id } : { } ) ,
116
+ } )
104
117
. then ( newCheckout => {
105
118
onCheckoutComplete ( newCheckout ) ;
106
119
} )
@@ -176,16 +189,18 @@ const CheckoutFormElements = ({
176
189
{ /* TODO(@Commerce): needs localization */ }
177
190
< Disclosure . Trigger text = 'Add a New Payment Source' />
178
191
< Disclosure . Content >
179
- < AddPaymentSource
180
- checkout = { checkout }
181
- onSuccess = { onAddPaymentSourceSuccess }
182
- submitLabel = { localizationKeys (
183
- 'userProfile.__experimental_billingPage.paymentSourcesSection.formButtonPrimary__pay' ,
184
- {
185
- amount : `${ ( checkout . totals . totalDueNow || checkout . totals . grandTotal ) . currencySymbol } ${ ( checkout . totals . totalDueNow || checkout . totals . grandTotal ) . amountFormatted } ` ,
186
- } ,
187
- ) }
188
- />
192
+ < __experimental_PaymentSourcesContext . Provider value = { { componentName : 'PaymentSources' , subscriberType } } >
193
+ < AddPaymentSource
194
+ checkout = { checkout }
195
+ onSuccess = { onAddPaymentSourceSuccess }
196
+ submitLabel = { localizationKeys (
197
+ 'userProfile.__experimental_billingPage.paymentSourcesSection.formButtonPrimary__pay' ,
198
+ {
199
+ amount : `${ ( checkout . totals . totalDueNow || checkout . totals . grandTotal ) . currencySymbol } ${ ( checkout . totals . totalDueNow || checkout . totals . grandTotal ) . amountFormatted } ` ,
200
+ } ,
201
+ ) }
202
+ />
203
+ </ __experimental_PaymentSourcesContext . Provider >
189
204
</ Disclosure . Content >
190
205
</ Disclosure . Root >
191
206
</ Col >
0 commit comments