From e617569961189da4961edacfcb4cd0a9ff83d077 Mon Sep 17 00:00:00 2001 From: vsmart-06 Date: Tue, 28 Apr 2026 16:12:27 -0500 Subject: [PATCH] Added deactivate --- src/api/functions/stripe.ts | 45 +++++++++++++++++++++++++++++++++++++ src/api/routes/stripe.ts | 8 +++++++ 2 files changed, 53 insertions(+) diff --git a/src/api/functions/stripe.ts b/src/api/functions/stripe.ts index 70594fda..c8918779 100644 --- a/src/api/functions/stripe.ts +++ b/src/api/functions/stripe.ts @@ -782,6 +782,51 @@ export const recordInvoicePayment = async ({ ); }; +export const deactivatePaymentLink = async ({ + dynamoClient, + pk, // `${orgId}#${emailDomain}` + invoiceId, + linkId, +}: { + dynamoClient: DynamoDBClient; + pk: string; + invoiceId: string; + linkId: string; +}) => { + const deactivateItems: TransactWriteItemsCommand["input"]["TransactItems"] = [ + { + ConditionCheck: { + TableName: genericConfig.StripePaymentsDynamoTableName, + Key: { + primaryKey: { S: pk }, + sortKey: { S: `CHARGE#${invoiceId}` }, + }, + ConditionExpression: + "attribute_exists(paidAmount) AND paidAmount = invoiceAmtUsd", + }, + Update: { + TableName: genericConfig.StripeLinksDynamoTableName, + Key: { + linkId: { S: linkId }, + }, + ConditionExpression: "#active = :true", + UpdateExpression: "SET #active = :false", + ExpressionAttributeNames: { "#active": "active" }, + ExpressionAttributeValues: { + ":true": { BOOL: true }, + ":false": { BOOL: false }, + }, + }, + }, + ]; + + await dynamoClient.send( + new TransactWriteItemsCommand({ + TransactItems: deactivateItems, + }), + ); +}; + /** * Capture a pre-authorized payment intent */ diff --git a/src/api/routes/stripe.ts b/src/api/routes/stripe.ts index 0fd46329..f9ee338d 100644 --- a/src/api/routes/stripe.ts +++ b/src/api/routes/stripe.ts @@ -17,6 +17,7 @@ import { SupportedStripePaymentMethod, supportedStripePaymentMethods, recordInvoicePayment, + deactivatePaymentLink, } from "api/functions/stripe.js"; import { getSecretValue } from "api/plugins/auth.js"; import { genericConfig, notificationRecipients } from "common/config.js"; @@ -998,6 +999,13 @@ Please ask the payee to try again, perhaps with a different payment method, or c "unknown", decrementOwed, }); + + await deactivatePaymentLink({ + dynamoClient: fastify.dynamoClient, + pk, + invoiceId: meta.invoiceId, + linkId: event.data.object.payment_link!.toString(), + }); } catch (e: unknown) { if ( (e as { name?: string })?.name ===