Skip to content

Commit

Permalink
basic setup
Browse files Browse the repository at this point in the history
  • Loading branch information
devksingh4 committed Feb 5, 2025
1 parent 2505d44 commit 3f5dd37
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
17 changes: 14 additions & 3 deletions cloudformation/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,22 @@ Resources:
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: false
AttributeDefinitions:
- AttributeName: id
- AttributeName: userId
AttributeType: S
- AttributeName: linkId
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
- AttributeName: userId
KeyType: "HASH"
- AttributeName: linkId
KeyType: "RANGE"
GlobalSecondaryIndexes:
- IndexName: LinkIdIndex
KeySchema:
- AttributeName: linkId
KeyType: "HASH"
Projection:
ProjectionType: "ALL"

CacheRecordsTable:
Type: 'AWS::DynamoDB::Table'
Expand Down
20 changes: 12 additions & 8 deletions src/api/functions/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export type StripeLinkCreateParams = {
contactEmail: string;
createdBy: string;
stripeApiKey: string;
logger: FastifyBaseLogger;
};

/**
Expand All @@ -22,9 +21,13 @@ export const createStripeLink = async ({
contactName,
contactEmail,
createdBy,
logger,
stripeApiKey,
}: StripeLinkCreateParams): Promise<string> => {
}: StripeLinkCreateParams): Promise<{
linkId: string;
priceId: string;
productId: string;
url: string;
}> => {
const stripe = new Stripe(stripeApiKey);
const description = `Created For: ${contactName} (${contactEmail}) by ${createdBy}.`;
const product = await stripe.products.create({
Expand All @@ -44,9 +47,10 @@ export const createStripeLink = async ({
},
],
});
logger.info(
{ type: "audit", actor: createdBy, target: invoiceId },
"Created Stripe payment link",
);
return paymentLink.url;
return {
url: paymentLink.url,
linkId: paymentLink.id,
productId: product.id,
priceId: price.id,
};
};
26 changes: 24 additions & 2 deletions src/api/routes/stripe.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PutItemCommand } from "@aws-sdk/client-dynamodb";
import { marshall } from "@aws-sdk/util-dynamodb";
import {
createStripeLink,
StripeLinkCreateParams,
Expand Down Expand Up @@ -52,10 +54,30 @@ const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => {
const payload: StripeLinkCreateParams = {
...request.body,
createdBy: request.username,
logger: request.log,
stripeApiKey: secretApiConfig.stripe_secret_key as string,
};
const url = await createStripeLink(payload);
const { url, linkId, priceId, productId } =
await createStripeLink(payload);
const invoiceId = request.body.invoiceId;
const dynamoCommand = new PutItemCommand({
TableName: genericConfig.StripeLinksDynamoTableName,
Item: marshall({
userId: request.username,
linkId,
priceId,
productId,
url,
}),
});
await fastify.dynamoClient.send(dynamoCommand);
request.log.info(
{
type: "audit",
actor: request.username,
target: `Link ${linkId} | Invoice ${invoiceId}`,
},
"Created Stripe payment link",
);
reply.status(201).send({ invoiceId: request.body.invoiceId, link: url });
},
);
Expand Down
2 changes: 2 additions & 0 deletions src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type ConfigType = {
export type GenericConfigType = {
EventsDynamoTableName: string;
CacheDynamoTableName: string;
StripeLinksDynamoTableName: string;
ConfigSecretName: string;
UpcomingEventThresholdSeconds: number;
AwsRegion: string;
Expand All @@ -46,6 +47,7 @@ export const execCouncilTestingGroupId = "dbe18eb2-9675-46c4-b1ef-749a6db4fedd";

const genericConfig: GenericConfigType = {
EventsDynamoTableName: "infra-core-api-events",
StripeLinksDynamoTableName: "infra-core-api-stripe-links",
CacheDynamoTableName: "infra-core-api-cache",
ConfigSecretName: "infra-core-api-config",
UpcomingEventThresholdSeconds: 1800, // 30 mins
Expand Down

0 comments on commit 3f5dd37

Please sign in to comment.