mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-13 19:30:30 +00:00
feat: Clean up payment links endpoints
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { body, param } from 'express-validator';
|
||||
import { param } from 'express-validator';
|
||||
import BaseController from '@/api/controllers/BaseController';
|
||||
import { GetInvoicePaymentLinkMetadata } from '@/services/Sales/Invoices/GetInvoicePaymentLinkMetadata';
|
||||
import { PaymentLinksApplication } from '@/services/PaymentLinks/PaymentLinksApplication';
|
||||
|
||||
@Service()
|
||||
export class PublicSharableLinkController extends BaseController {
|
||||
@Inject()
|
||||
private getSharableLinkMetaService: GetInvoicePaymentLinkMetadata;
|
||||
private paymentLinkApp: PaymentLinksApplication;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
@@ -16,12 +16,18 @@ export class PublicSharableLinkController extends BaseController {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
'/sharable-links/meta/invoice/:linkId',
|
||||
[param('linkId').exists()],
|
||||
'/:paymentLinkId/invoice',
|
||||
[param('paymentLinkId').exists()],
|
||||
this.validationResult,
|
||||
this.getPaymentLinkPublicMeta.bind(this),
|
||||
this.validationResult
|
||||
);
|
||||
router.post(
|
||||
'/:paymentLinkId/stripe_checkout_session',
|
||||
[param('paymentLinkId').exists()],
|
||||
this.validationResult,
|
||||
this.createInvoicePaymentLinkCheckoutSession.bind(this)
|
||||
);
|
||||
return router;
|
||||
}
|
||||
|
||||
@@ -33,19 +39,45 @@ export class PublicSharableLinkController extends BaseController {
|
||||
* @returns
|
||||
*/
|
||||
public async getPaymentLinkPublicMeta(
|
||||
req: Request,
|
||||
req: Request<{ paymentLinkId: string }>,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { linkId } = req.params;
|
||||
const { paymentLinkId } = req.params;
|
||||
|
||||
try {
|
||||
const data =
|
||||
await this.getSharableLinkMetaService.getInvoicePaymentLinkMeta(linkId);
|
||||
const data = await this.paymentLinkApp.getInvoicePaymentLink(
|
||||
paymentLinkId
|
||||
);
|
||||
|
||||
return res.status(200).send({ data });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Stripe checkout session for the given payment link id.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
* @returns {Promise<Response|void>}
|
||||
*/
|
||||
public async createInvoicePaymentLinkCheckoutSession(
|
||||
req: Request<{ paymentLinkId: string }>,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { paymentLinkId } = req.params;
|
||||
|
||||
try {
|
||||
const session =
|
||||
await this.paymentLinkApp.createInvoicePaymentCheckoutSession(
|
||||
paymentLinkId
|
||||
);
|
||||
return res.status(200).send(session);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user