Skip to content

Commit

Permalink
fix: download invoice document on payment page
Browse files Browse the repository at this point in the history
  • Loading branch information
abouolia committed Nov 11, 2024
1 parent d668d60 commit ba8091d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ export class PublicSharableLinkController extends BaseController {
const { paymentLinkId } = req.params;

try {
const pdfContent = await this.paymentLinkApp.getPaymentLinkInvoicePdf(
paymentLinkId
);
const [pdfContent, filename] =
await this.paymentLinkApp.getPaymentLinkInvoicePdf(paymentLinkId);

res.set({
'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length,
'Content-Disposition': `attachment; filename="${filename}"`,
});
res.send(pdfContent);
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export class GetPaymentLinkInvoicePdf {
* Retrieves the sale invoice PDF of the given payment link id.
* @param {number} tenantId
* @param {number} paymentLinkId
* @returns {Promise<Buffer>}
* @returns {Promise<Buffer, string>}
*/
async getPaymentLinkInvoicePdf(paymentLinkId: string): Promise<Buffer> {
async getPaymentLinkInvoicePdf(
paymentLinkId: string
): Promise<[Buffer, string]> {
const paymentLink = await PaymentLink.query()
.findOne('linkId', paymentLinkId)
.where('resourceType', 'SaleInvoice')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class PaymentLinksApplication {

@Inject()
private createInvoiceCheckoutSessionService: CreateInvoiceCheckoutSession;

@Inject()
private getPaymentLinkInvoicePdfService: GetPaymentLinkInvoicePdf;

Expand Down Expand Up @@ -45,7 +45,9 @@ export class PaymentLinksApplication {
* @param {number} paymentLinkId
* @returns {Promise<Buffer> }
*/
public getPaymentLinkInvoicePdf(paymentLinkId: string): Promise<Buffer> {
public getPaymentLinkInvoicePdf(
paymentLinkId: string
): Promise<[Buffer, string]> {
return this.getPaymentLinkInvoicePdfService.getPaymentLinkInvoicePdf(
paymentLinkId
);
Expand Down

0 comments on commit ba8091d

Please sign in to comment.