@@ -333,7 +333,6 @@ const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => {
333333 sig ,
334334 secretApiConfig . stripe_links_endpoint_secret as string ,
335335 ) ;
336- // event = JSON.parse(request.rawBody.toString()); <-- this is for testing without a stripe account via Curl
337336 } catch ( err : unknown ) {
338337 if ( err instanceof BaseError ) {
339338 throw err ;
@@ -717,52 +716,38 @@ Please contact Officer Board with any questions.`,
717716 return reply
718717 . code ( 200 )
719718 . send ( { handled : false , requestId : request . id } ) ;
720- case "customer_cash_balance_transaction.created " : {
721- const txn = event . data . object as any ;
719+ case "payment_intent.succeeded " : {
720+ const intent = event . data . object as Stripe . PaymentIntent ;
722721
723- if ( txn . funding_method === "bank_transfer" ) {
724- const customerId = txn . customer ?. toString ( ) ?? "UNKNOWN" ;
725- const amount = txn . net_amount ;
726- const currency = txn . currency ;
727- const status = txn . status ;
728- const eventId = event . id ;
729-
730- request . log . info (
731- `Received ACH push ${ status } txn ${ txn . id } for ${ customerId } (${ amount } ${ currency } )` ,
732- ) ;
722+ const amount = intent . amount_received ;
723+ const currency = intent . currency ;
724+ const customerId = intent . customer ?. toString ( ) ?? "UNKNOWN" ;
725+ const email =
726+ intent . receipt_email ??
727+ intent . metadata ?. billing_email ??
728+ 729+ const acmOrg = intent . metadata ?. acm_org ?? "ACM@UIUC" ;
730+ const domain = email . split ( "@" ) [ 1 ] ?? "unknown.com" ;
733731
734- await fastify . dynamoClient . send (
735- new PutItemCommand ( {
736- TableName : genericConfig . StripePaymentsDynamoTableName ,
737- Item : marshall ( {
738- primaryKey : `CUSTOMER #${ customerId } ` ,
739- sortKey : `PAY# ${ txn . id } ` ,
740- amount,
741- currency,
742- status,
743- createdAt : Date . now ( ) ,
744- eventId ,
745- } ) ,
732+ await fastify . dynamoClient . send (
733+ new PutItemCommand ( {
734+ TableName : genericConfig . StripePaymentsDynamoTableName ,
735+ Item : marshall ( {
736+ primaryKey : `${ acmOrg } #${ domain } ` ,
737+ sortKey : `customer ` ,
738+ amount,
739+ currency,
740+ status : "succeeded" ,
741+ billingEmail : email ,
742+ createdAt : Date . now ( ) ,
743+ eventId : event . id ,
746744 } ) ,
747- ) ;
745+ } ) ,
746+ ) ;
748747
749- // if (status === "succeeded") {
750- // await fastify.dynamoClient.send(
751- // new UpdateItemCommand({
752- // TableName: genericConfig.StripePaymentsDynamoTableName,
753- // Key: marshall({
754- // primaryKey: `CUSTOMER#${customerId}`,
755- // sortKey: "SUMMARY",
756- // }),
757- // UpdateExpression: "ADD totalPaid :amount SET lastUpdated = :ts",
758- // ExpressionAttributeValues: marshall({
759- // ":amount": amount,
760- // ":ts": Date.now(),
761- // }),
762- // })
763- // );
764- // }
765- }
748+ request . log . info (
749+ `Recorded successful payment ${ intent . id } from ${ email } (${ amount } ${ currency } )` ,
750+ ) ;
766751
767752 return reply
768753 . status ( 200 )
0 commit comments