mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,6 @@ export class StripeIntegrationController extends BaseController {
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.createAccountLink.bind(this))
|
||||
);
|
||||
router.post(
|
||||
'/:linkId/create_checkout_session',
|
||||
this.createCheckoutSession.bind(this)
|
||||
);
|
||||
return router;
|
||||
}
|
||||
|
||||
@@ -75,33 +71,6 @@ export class StripeIntegrationController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 createCheckoutSession(
|
||||
req: Request<{ linkId: number }>,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { linkId } = req.params;
|
||||
const { tenantId } = req;
|
||||
|
||||
try {
|
||||
const session =
|
||||
await this.stripePaymentApp.createSaleInvoiceCheckoutSession(
|
||||
tenantId,
|
||||
linkId
|
||||
);
|
||||
return res.status(200).send(session);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Stripe account.
|
||||
* @param {Request} req - The Express request object.
|
||||
|
||||
Reference in New Issue
Block a user