Skip to content

Commit ecb93ef

Browse files
committed
fix endpoint code
1 parent 0713932 commit ecb93ef

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/api/routes/stripe.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@ import {
3434
import { FastifyPluginAsync } from "fastify";
3535
import { FastifyZodOpenApiTypeProvider } from "fastify-zod-openapi";
3636
import stripe, { Stripe } from "stripe";
37+
import rawbody from "fastify-raw-body";
3738

3839
const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => {
40+
await fastify.register(rawbody, {
41+
field: "rawBody",
42+
global: false,
43+
runFirst: true,
44+
});
3945
fastify.withTypeProvider<FastifyZodOpenApiTypeProvider>().get(
4046
"/paymentLinks",
4147
{
@@ -213,6 +219,13 @@ const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => {
213219
switch (event.type) {
214220
case "checkout.session.completed":
215221
if (event.data.object.payment_link) {
222+
const eventId = event.id;
223+
const paymentAmount = event.data.object.amount_total;
224+
const paymentCurrency = event.data.object.currency;
225+
const { email, name } = event.data.object.customer_details || {
226+
email: null,
227+
name: null,
228+
};
216229
const paymentLinkId = event.data.object.payment_link.toString();
217230
if (!paymentLinkId) {
218231
return reply
@@ -240,6 +253,9 @@ const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => {
240253
requestId: request.id,
241254
});
242255
}
256+
request.log.info(
257+
`Registered payment of ${paymentAmount} ${paymentCurrency} by ${name} (${email}) for payment link ${paymentLinkId}.`,
258+
);
243259
return reply.status(200).send({
244260
handled: true,
245261
requestId: request.id,

0 commit comments

Comments
 (0)