Skip to content

Commit 24767dd

Browse files
committed
changed to payment intent
1 parent 2ee6c0b commit 24767dd

File tree

1 file changed

+31
-44
lines changed

1 file changed

+31
-44
lines changed

src/api/routes/stripe.ts

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,13 @@ const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => {
328328
message: "Could not connect to Stripe.",
329329
});
330330
}
331+
const webhookSecret =
332+
"whsec_d4839918a81492d000c72bdc4ecff3fb080818156a15dc63b64f519d0edc1ed1";
331333
event = stripe.webhooks.constructEvent(
332334
request.rawBody,
333335
sig,
334-
secretApiConfig.stripe_links_endpoint_secret as string,
336+
webhookSecret, //secretApiConfig.stripe_links_endpoint_secret as string,
335337
);
336-
// event = JSON.parse(request.rawBody.toString()); <-- this is for testing without a stripe account via Curl
337338
} catch (err: unknown) {
338339
if (err instanceof BaseError) {
339340
throw err;
@@ -717,52 +718,38 @@ Please contact Officer Board with any questions.`,
717718
return reply
718719
.code(200)
719720
.send({ handled: false, requestId: request.id });
720-
case "customer_cash_balance_transaction.created": {
721-
const txn = event.data.object as any;
721+
case "payment_intent.succeeded": {
722+
const intent = event.data.object as Stripe.PaymentIntent;
722723

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-
);
724+
const amount = intent.amount_received;
725+
const currency = intent.currency;
726+
const customerId = intent.customer?.toString() ?? "UNKNOWN";
727+
const email =
728+
intent.receipt_email ??
729+
intent.metadata?.billing_email ??
730+
"unknown@example.com";
731+
const acmOrg = intent.metadata?.acm_org ?? "ACM@UIUC";
732+
const domain = email.split("@")[1] ?? "unknown.com";
733733

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-
}),
734+
await fastify.dynamoClient.send(
735+
new PutItemCommand({
736+
TableName: genericConfig.StripePaymentsDynamoTableName,
737+
Item: marshall({
738+
primaryKey: `${acmOrg}#${domain}`,
739+
sortKey: `customer`,
740+
amount,
741+
currency,
742+
status: "succeeded",
743+
billingEmail: email,
744+
createdAt: Date.now(),
745+
eventId: event.id,
746746
}),
747-
);
747+
}),
748+
);
748749

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-
}
750+
request.log.info(
751+
`Recorded successful payment ${intent.id} from ${email} (${amount} ${currency})`,
752+
);
766753

767754
return reply
768755
.status(200)

0 commit comments

Comments
 (0)