File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -245,12 +245,6 @@ keys
245245 return res . status ( 402 ) . json ( err ) ;
246246 }
247247 }
248- // Validate the payment source
249- const card = await stripe . sources . retrieve ( token . id ) ;
250- const BANNED_CARDS : string [ ] = [ ] ;
251- if ( BANNED_CARDS . includes ( card . card ?. fingerprint ?? '' ) ) {
252- return res . status ( 402 ) . json ( { error : 'This card is not allowed' } ) ;
253- }
254248
255249 const apiKey = uuid . v4 ( ) ;
256250 const sub = await stripe . subscriptions . create ( {
Original file line number Diff line number Diff line change @@ -107,6 +107,18 @@ async function updateStripeUsage(cb: ErrorCb) {
107107 ) ;
108108 continue ;
109109 }
110+ // Deactivate any keys belonging to an invalid card
111+ const BANNED_CARDS : string [ ] = [ ] ;
112+ const sourceId = sub . default_source ;
113+ if ( sourceId ) {
114+ const source = await stripe . sources . retrieve ( sourceId as string ) ;
115+ if ( source . card ?. fingerprint && BANNED_CARDS . includes ( source . card ?. fingerprint ) ) {
116+ await db . raw (
117+ `UPDATE api_keys SET is_canceled = true WHERE subscription_id = ?` ,
118+ [ sub . id ]
119+ ) ;
120+ }
121+ }
110122 const startTime = moment
111123 . unix ( sub . current_period_end - 1 )
112124 . startOf ( 'month' ) ;
You can’t perform that action at this time.
0 commit comments