Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/api/functions/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
8 changes: 8 additions & 0 deletions src/api/routes/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 ===
Expand Down
Loading