mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
Merge pull request #689 from bigcapitalhq/download-payment-link-invoice-pdf
feat: Download invoice pdf of the payment link
This commit is contained in:
@@ -22,6 +22,13 @@ export class PublicSharableLinkController extends BaseController {
|
||||
this.getPaymentLinkPublicMeta.bind(this),
|
||||
this.validationResult
|
||||
);
|
||||
router.get(
|
||||
'/:paymentLinkId/invoice/pdf',
|
||||
[param('paymentLinkId').exists()],
|
||||
this.validationResult,
|
||||
this.getPaymentLinkInvoicePdf.bind(this),
|
||||
this.validationResult
|
||||
);
|
||||
router.post(
|
||||
'/:paymentLinkId/stripe_checkout_session',
|
||||
[param('paymentLinkId').exists()],
|
||||
@@ -80,4 +87,31 @@ export class PublicSharableLinkController extends BaseController {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sale invoice pdf of the given payment link.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
public async getPaymentLinkInvoicePdf(
|
||||
req: Request<{ paymentLinkId: string }>,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { paymentLinkId } = req.params;
|
||||
|
||||
try {
|
||||
const pdfContent = await this.paymentLinkApp.getPaymentLinkInvoicePdf(
|
||||
paymentLinkId
|
||||
);
|
||||
res.set({
|
||||
'Content-Type': 'application/pdf',
|
||||
'Content-Length': pdfContent.length,
|
||||
});
|
||||
res.send(pdfContent);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { initalizeTenantServices } from '@/api/middleware/TenantDependencyInjection';
|
||||
import { SaleInvoicePdf } from '../Sales/Invoices/SaleInvoicePdf';
|
||||
import { PaymentLink } from '@/system/models';
|
||||
|
||||
@Service()
|
||||
export class GetPaymentLinkInvoicePdf {
|
||||
@Inject()
|
||||
private getSaleInvoicePdfService: SaleInvoicePdf;
|
||||
|
||||
/**
|
||||
* Retrieves the sale invoice PDF of the given payment link id.
|
||||
* @param {number} tenantId
|
||||
* @param {number} paymentLinkId
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
async getPaymentLinkInvoicePdf(paymentLinkId: string): Promise<Buffer> {
|
||||
const paymentLink = await PaymentLink.query()
|
||||
.findOne('linkId', paymentLinkId)
|
||||
.where('resourceType', 'SaleInvoice')
|
||||
.throwIfNotFound();
|
||||
|
||||
const tenantId = paymentLink.tenantId;
|
||||
await initalizeTenantServices(tenantId);
|
||||
|
||||
const saleInvoiceId = paymentLink.resourceId;
|
||||
|
||||
return this.getSaleInvoicePdfService.saleInvoicePdf(
|
||||
tenantId,
|
||||
saleInvoiceId
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { Inject, Service } from 'typedi';
|
||||
import { GetInvoicePaymentLinkMetadata } from './GetInvoicePaymentLinkMetadata';
|
||||
import { CreateInvoiceCheckoutSession } from './CreateInvoiceCheckoutSession';
|
||||
import { StripeInvoiceCheckoutSessionPOJO } from '@/interfaces/StripePayment';
|
||||
import { GetPaymentLinkInvoicePdf } from './GetPaymentLinkInvoicePdf';
|
||||
|
||||
@Service()
|
||||
export class PaymentLinksApplication {
|
||||
@@ -10,6 +11,9 @@ export class PaymentLinksApplication {
|
||||
|
||||
@Inject()
|
||||
private createInvoiceCheckoutSessionService: CreateInvoiceCheckoutSession;
|
||||
|
||||
@Inject()
|
||||
private getPaymentLinkInvoicePdfService: GetPaymentLinkInvoicePdf;
|
||||
|
||||
/**
|
||||
* Retrieves the invoice payment link.
|
||||
@@ -34,4 +38,16 @@ export class PaymentLinksApplication {
|
||||
paymentLinkId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sale invoice pdf of the given payment link id.
|
||||
* @param {number} tenantId
|
||||
* @param {number} paymentLinkId
|
||||
* @returns {Promise<Buffer> }
|
||||
*/
|
||||
public getPaymentLinkInvoicePdf(paymentLinkId: string): Promise<Buffer> {
|
||||
return this.getPaymentLinkInvoicePdfService.getPaymentLinkInvoicePdf(
|
||||
paymentLinkId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user