@@ -71,139 +71,6 @@ const membershipPlugin: FastifyPluginAsync = async (fastify, _options) => {
7171 duration : 30 ,
7272 rateLimitIdentifier : "membership" ,
7373 } ) ;
74- fastify . withTypeProvider < FastifyZodOpenApiTypeProvider > ( ) . get (
75- "/checkout/:netId" ,
76- {
77- schema : withTags ( [ "Membership" ] , {
78- params : z . object ( { netId : illinoisNetId } ) ,
79- summary :
80- "Create a checkout session to purchase an ACM @ UIUC membership." ,
81- response : {
82- 200 : {
83- description : "Stripe checkout link." ,
84- content : {
85- "text/plain" : {
86- schema : z . url ( ) . meta ( {
87- example :
88- "https://buy.stripe.com/test_14A00j9Hq9tj9ZfchM3AY0s" ,
89- } ) ,
90- } ,
91- } ,
92- } ,
93- } ,
94- } ) ,
95- } ,
96- async ( request , reply ) => {
97- const netId = request . params . netId . toLowerCase ( ) ;
98- const cacheKey = `membership:${ netId } :acmpaid` ;
99- const result = await getKey < { isMember : boolean } > ( {
100- redisClient : fastify . redisClient ,
101- key : cacheKey ,
102- logger : request . log ,
103- } ) ;
104- if ( result && result . isMember ) {
105- throw new ValidationError ( {
106- message : `${ netId } is already a paid member!` ,
107- } ) ;
108- }
109- const isDynamoMember = await checkPaidMembershipFromTable (
110- netId ,
111- fastify . dynamoClient ,
112- ) ;
113- if ( isDynamoMember ) {
114- await setKey ( {
115- redisClient : fastify . redisClient ,
116- key : cacheKey ,
117- data : JSON . stringify ( { isMember : true } ) ,
118- expiresIn : MEMBER_CACHE_SECONDS ,
119- logger : request . log ,
120- } ) ;
121- throw new ValidationError ( {
122- message : `${ netId } is already a paid member!` ,
123- } ) ;
124- }
125- const entraIdToken = await getEntraIdToken ( {
126- clients : await getAuthorizedClients ( ) ,
127- clientId : fastify . environmentConfig . AadValidClientId ,
128- secretName : genericConfig . EntraSecretName ,
129- logger : request . log ,
130- } ) ;
131- const paidMemberGroup = fastify . environmentConfig . PaidMemberGroupId ;
132- const isAadMember = await checkPaidMembershipFromEntra (
133- netId ,
134- entraIdToken ,
135- paidMemberGroup ,
136- ) ;
137- if ( isAadMember ) {
138- await setKey ( {
139- redisClient : fastify . redisClient ,
140- key : cacheKey ,
141- data : JSON . stringify ( { isMember : true } ) ,
142- expiresIn : MEMBER_CACHE_SECONDS ,
143- logger : request . log ,
144- } ) ;
145- reply
146- . header ( "X-ACM-Data-Source" , "aad" )
147- . send ( { netId, isPaidMember : true } ) ;
148- await setPaidMembershipInTable ( netId , fastify . dynamoClient ) ;
149- throw new ValidationError ( {
150- message : `${ netId } is already a paid member!` ,
151- } ) ;
152- }
153- // Once the caller becomes a member, the stripe webhook will handle changing this to true
154- await setKey ( {
155- redisClient : fastify . redisClient ,
156- key : cacheKey ,
157- data : JSON . stringify ( { isMember : false } ) ,
158- expiresIn : MEMBER_CACHE_SECONDS ,
159- logger : request . log ,
160- } ) ;
161- const secretApiConfig =
162- ( await getSecretValue (
163- fastify . secretsManagerClient ,
164- genericConfig . ConfigSecretName ,
165- ) ) || { } ;
166- if ( ! secretApiConfig ) {
167- throw new InternalServerError ( {
168- message : "Could not connect to Stripe." ,
169- } ) ;
170- }
171- return reply . status ( 200 ) . send (
172- await createCheckoutSession ( {
173- successUrl : "https://acm.illinois.edu/paid" ,
174- returnUrl : "https://acm.illinois.edu/membership" ,
175- customerEmail : `${ netId } @illinois.edu` ,
176- stripeApiKey : secretApiConfig . stripe_secret_key as string ,
177- items : [
178- {
179- price : fastify . environmentConfig . PaidMemberPriceId ,
180- quantity : 1 ,
181- } ,
182- ] ,
183- customFields : [
184- {
185- key : "firstName" ,
186- label : {
187- type : "custom" ,
188- custom : "Member First Name" ,
189- } ,
190- type : "text" ,
191- } ,
192- {
193- key : "lastName" ,
194- label : {
195- type : "custom" ,
196- custom : "Member Last Name" ,
197- } ,
198- type : "text" ,
199- } ,
200- ] ,
201- initiator : "purchase-membership" ,
202- allowPromotionCodes : true ,
203- } ) ,
204- ) ;
205- } ,
206- ) ;
20774 fastify . withTypeProvider < FastifyZodOpenApiTypeProvider > ( ) . get (
20875 "/:netId" ,
20976 {
0 commit comments