@@ -2,6 +2,7 @@ package handlers
22
33import (
44 "fmt"
5+ "io"
56
67 "github.com/NdoleStudio/httpsms/pkg/requests"
78 "github.com/NdoleStudio/httpsms/pkg/validators"
@@ -333,7 +334,7 @@ func (h *UserHandler) subscriptionInvoice(c fiber.Ctx) error {
333334 return h .responseUnprocessableEntity (c , errors , "validation errors while generating payment invoice" )
334335 }
335336
336- data , err := h .service .GenerateReceipt (ctx , request .UserInvoiceGenerateParams (h .userIDFomContext (c )))
337+ reader , err := h .service .GenerateReceipt (ctx , request .UserInvoiceGenerateParams (h .userIDFomContext (c )))
337338 if err != nil {
338339 msg := fmt .Sprintf ("cannot generate receipt for invoice ID [%s] and user [%s]" , request .SubscriptionInvoiceID , h .userFromContext (c ))
339340 ctxLogger .Error (stacktrace .Propagate (err , msg ))
@@ -343,5 +344,12 @@ func (h *UserHandler) subscriptionInvoice(c fiber.Ctx) error {
343344 c .Set (fiber .HeaderContentType , "application/pdf" )
344345 c .Set (fiber .HeaderContentDisposition , fmt .Sprintf ("attachment; filename=\" httpsms.com - %s.pdf\" " , request .SubscriptionInvoiceID ))
345346
346- return c .SendStream (data )
347+ data , err := io .ReadAll (reader )
348+ if err != nil {
349+ msg := fmt .Sprintf ("cannot read invoice data with ID [%s] for user with ID [%s]" , request .SubscriptionInvoiceID , h .userIDFomContext (c ))
350+ ctxLogger .Error (stacktrace .Propagate (err , msg ))
351+ return h .responseInternalServerError (c )
352+ }
353+
354+ return c .Send (data )
347355}
0 commit comments