File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,14 @@ import {
3434import { FastifyPluginAsync } from "fastify" ;
3535import { FastifyZodOpenApiTypeProvider } from "fastify-zod-openapi" ;
3636import stripe , { Stripe } from "stripe" ;
37+ import rawbody from "fastify-raw-body" ;
3738
3839const 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 ,
You can’t perform that action at this time.
0 commit comments