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 ({
111111 active : false ,
112112 } ) ;
113113} ;
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 {
1313import {
1414 createStripeLink ,
1515 deactivateStripeLink ,
16+ deactivateStripeProduct ,
1617 StripeLinkCreateParams ,
1718} from "api/functions/stripe.js" ;
1819import { getSecretValue } from "api/plugins/auth.js" ;
@@ -260,9 +261,9 @@ const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => {
260261 const unmarshalledEntry = unmarshall ( response . Items [ 0 ] ) as {
261262 userId : string ;
262263 invoiceId : string ;
263- amount : number ;
264- priceId : string ;
265- productId : string ;
264+ amount ? : number ;
265+ priceId ? : string ;
266+ productId ? : string ;
266267 } ;
267268 if ( ! unmarshalledEntry . userId || ! unmarshalledEntry . invoiceId ) {
268269 return reply . status ( 200 ) . send ( {
@@ -345,6 +346,16 @@ const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => {
345346 } ,
346347 ] ,
347348 } ) ;
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 } ` ) ;
348359 await deactivateStripeLink ( {
349360 stripeApiKey : secretApiConfig . stripe_secret_key as string ,
350361 linkId : paymentLinkId ,
You can’t perform that action at this time.
0 commit comments