@@ -25,7 +25,7 @@ type PendingStripeSubscription = { pendingSince: number };
25
25
26
26
interface Props {
27
27
subject ?: hasId ;
28
- attributionId : AttributionId ;
28
+ attributionId : string ;
29
29
}
30
30
31
31
export default function UsageBasedBillingConfig ( { subject, attributionId } : Props ) {
@@ -50,9 +50,7 @@ export default function UsageBasedBillingConfig({ subject, attributionId }: Prop
50
50
setStripeSubscriptionId ( undefined ) ;
51
51
setIsLoading ( true ) ;
52
52
try {
53
- const subscriptionId = await getGitpodService ( ) . server . findStripeSubscriptionId (
54
- AttributionId . render ( attributionId ) ,
55
- ) ;
53
+ const subscriptionId = await getGitpodService ( ) . server . findStripeSubscriptionId ( attributionId ) ;
56
54
setStripeSubscriptionId ( subscriptionId ) ;
57
55
} catch ( error ) {
58
56
console . error ( error ) ;
@@ -68,8 +66,8 @@ export default function UsageBasedBillingConfig({ subject, attributionId }: Prop
68
66
}
69
67
( async ( ) => {
70
68
const [ portalUrl , spendingLimit ] = await Promise . all ( [
71
- getGitpodService ( ) . server . getStripePortalUrl ( AttributionId . render ( attributionId ) ) ,
72
- getGitpodService ( ) . server . getUsageLimit ( AttributionId . render ( attributionId ) ) ,
69
+ getGitpodService ( ) . server . getStripePortalUrl ( attributionId ) ,
70
+ getGitpodService ( ) . server . getUsageLimit ( attributionId ) ,
73
71
] ) ;
74
72
setStripePortalUrl ( portalUrl ) ;
75
73
setUsageLimit ( spendingLimit ) ;
@@ -91,7 +89,7 @@ export default function UsageBasedBillingConfig({ subject, attributionId }: Prop
91
89
setPendingStripeSubscription ( pendingSubscription ) ;
92
90
window . localStorage . setItem ( localStorageKey , JSON . stringify ( pendingSubscription ) ) ;
93
91
try {
94
- await getGitpodService ( ) . server . subscribeToStripe ( AttributionId . render ( attributionId ) , setupIntentId ) ;
92
+ await getGitpodService ( ) . server . subscribeToStripe ( attributionId , setupIntentId ) ;
95
93
} catch ( error ) {
96
94
console . error ( "Could not subscribe subject to Stripe" , error ) ;
97
95
window . localStorage . removeItem ( localStorageKey ) ;
@@ -140,9 +138,7 @@ export default function UsageBasedBillingConfig({ subject, attributionId }: Prop
140
138
if ( ! pollStripeSubscriptionTimeout ) {
141
139
// Refresh Stripe subscription in 5 seconds in order to poll for upgrade confirmation
142
140
const timeout = setTimeout ( async ( ) => {
143
- const subscriptionId = await getGitpodService ( ) . server . findStripeSubscriptionId (
144
- AttributionId . render ( attributionId ) ,
145
- ) ;
141
+ const subscriptionId = await getGitpodService ( ) . server . findStripeSubscriptionId ( attributionId ) ;
146
142
setStripeSubscriptionId ( subscriptionId ) ;
147
143
setPollStripeSubscriptionTimeout ( undefined ) ;
148
144
} , 5000 ) ;
@@ -161,7 +157,7 @@ export default function UsageBasedBillingConfig({ subject, attributionId }: Prop
161
157
const oldLimit = usageLimit ;
162
158
setUsageLimit ( newLimit ) ;
163
159
try {
164
- await getGitpodService ( ) . server . setUsageLimit ( AttributionId . render ( attributionId ) , newLimit ) ;
160
+ await getGitpodService ( ) . server . setUsageLimit ( attributionId , newLimit ) ;
165
161
} catch ( error ) {
166
162
setUsageLimit ( oldLimit ) ;
167
163
console . error ( error ) ;
@@ -239,7 +235,7 @@ export default function UsageBasedBillingConfig({ subject, attributionId }: Prop
239
235
) ;
240
236
}
241
237
242
- function BillingSetupModal ( props : { attributionId : AttributionId ; onClose : ( ) => void } ) {
238
+ function BillingSetupModal ( props : { attributionId : string ; onClose : ( ) => void } ) {
243
239
const { isDark } = useContext ( ThemeContext ) ;
244
240
const [ stripePromise , setStripePromise ] = useState < Promise < Stripe | null > | undefined > ( ) ;
245
241
const [ stripeSetupIntentClientSecret , setStripeSetupIntentClientSecret ] = useState < string | undefined > ( ) ;
@@ -283,7 +279,7 @@ function getStripeAppearance(isDark?: boolean): Appearance {
283
279
} ;
284
280
}
285
281
286
- function CreditCardInputForm ( props : { attributionId : AttributionId } ) {
282
+ function CreditCardInputForm ( props : { attributionId : string } ) {
287
283
const stripe = useStripe ( ) ;
288
284
const elements = useElements ( ) ;
289
285
const { currency, setCurrency } = useContext ( PaymentContext ) ;
@@ -292,18 +288,16 @@ function CreditCardInputForm(props: { attributionId: AttributionId }) {
292
288
293
289
const handleSubmit = async ( event : React . FormEvent ) => {
294
290
event . preventDefault ( ) ;
295
- if ( ! stripe || ! elements ) {
291
+ const attrId = AttributionId . parse ( props . attributionId ) ;
292
+ if ( ! stripe || ! elements || ! attrId ) {
296
293
return ;
297
294
}
298
295
setBillingError ( undefined ) ;
299
296
setIsLoading ( true ) ;
300
297
try {
301
- if ( props . attributionId . kind === "team" ) {
298
+ if ( attrId . kind === "team" ) {
302
299
// Create Stripe customer for team & currency (or update currency)
303
- await getGitpodService ( ) . server . createOrUpdateStripeCustomerForTeam (
304
- props . attributionId . teamId ,
305
- currency ,
306
- ) ;
300
+ await getGitpodService ( ) . server . createOrUpdateStripeCustomerForTeam ( attrId . teamId , currency ) ;
307
301
} else {
308
302
// Create Stripe customer for user & currency (or update currency)
309
303
await getGitpodService ( ) . server . createOrUpdateStripeCustomerForUser ( currency ) ;
0 commit comments