File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -111,3 +111,16 @@ export const deactivateStripeLink = async ({
111
111
active : false ,
112
112
} ) ;
113
113
} ;
114
+
115
+ export const deactivateStripeProduct = async ( {
116
+ productId,
117
+ stripeApiKey,
118
+ } : {
119
+ productId : string ;
120
+ stripeApiKey : string ;
121
+ } ) : Promise < void > => {
122
+ const stripe = new Stripe ( stripeApiKey ) ;
123
+ await stripe . products . update ( productId , {
124
+ active : false ,
125
+ } ) ;
126
+ } ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
13
13
import {
14
14
createStripeLink ,
15
15
deactivateStripeLink ,
16
+ deactivateStripeProduct ,
16
17
StripeLinkCreateParams ,
17
18
} from "api/functions/stripe.js" ;
18
19
import { getSecretValue } from "api/plugins/auth.js" ;
@@ -260,9 +261,9 @@ const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => {
260
261
const unmarshalledEntry = unmarshall ( response . Items [ 0 ] ) as {
261
262
userId : string ;
262
263
invoiceId : string ;
263
- amount : number ;
264
- priceId : string ;
265
- productId : string ;
264
+ amount ? : number ;
265
+ priceId ? : string ;
266
+ productId ? : string ;
266
267
} ;
267
268
if ( ! unmarshalledEntry . userId || ! unmarshalledEntry . invoiceId ) {
268
269
return reply . status ( 200 ) . send ( {
@@ -345,6 +346,16 @@ const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => {
345
346
} ,
346
347
] ,
347
348
} ) ;
349
+ if ( unmarshalledEntry . productId ) {
350
+ request . log . debug (
351
+ `Deactivating Stripe product ${ unmarshalledEntry . productId } ` ,
352
+ ) ;
353
+ await deactivateStripeProduct ( {
354
+ stripeApiKey : secretApiConfig . stripe_secret_key as string ,
355
+ productId : unmarshalledEntry . productId ,
356
+ } ) ;
357
+ }
358
+ request . log . debug ( `Deactivating Stripe link ${ paymentLinkId } ` ) ;
348
359
await deactivateStripeLink ( {
349
360
stripeApiKey : secretApiConfig . stripe_secret_key as string ,
350
361
linkId : paymentLinkId ,
You can’t perform that action at this time.
0 commit comments