mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
Merge pull request #732 from bigcapitalhq/attach-payment-link-invoice
fix: attach payment link in sending invoice mail receipt
This commit is contained in:
@@ -30,7 +30,6 @@ export class ShareLinkController extends BaseController {
|
|||||||
this.validationResult,
|
this.validationResult,
|
||||||
asyncMiddleware(this.generateShareLink.bind(this))
|
asyncMiddleware(this.generateShareLink.bind(this))
|
||||||
);
|
);
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +52,6 @@ export class ShareLinkController extends BaseController {
|
|||||||
const link = await this.generateShareLinkService.generatePaymentLink(
|
const link = await this.generateShareLinkService.generatePaymentLink(
|
||||||
tenantId,
|
tenantId,
|
||||||
transactionId,
|
transactionId,
|
||||||
transactionType,
|
|
||||||
publicity,
|
publicity,
|
||||||
expiryDate
|
expiryDate
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -32,15 +32,14 @@ export class GenerateShareLink {
|
|||||||
*/
|
*/
|
||||||
async generatePaymentLink(
|
async generatePaymentLink(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
transactionId: number,
|
saleInvoiceId: number,
|
||||||
transactionType: string,
|
|
||||||
publicity: string = 'private',
|
publicity: string = 'private',
|
||||||
expiryTime: string = ''
|
expiryTime: string = ''
|
||||||
) {
|
) {
|
||||||
const { SaleInvoice } = this.tenancy.models(tenantId);
|
const { SaleInvoice } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
const foundInvoice = await SaleInvoice.query()
|
const foundInvoice = await SaleInvoice.query()
|
||||||
.findById(transactionId)
|
.findById(saleInvoiceId)
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
// Generate unique uuid for sharable link.
|
// Generate unique uuid for sharable link.
|
||||||
@@ -48,8 +47,7 @@ export class GenerateShareLink {
|
|||||||
|
|
||||||
const commonEventPayload = {
|
const commonEventPayload = {
|
||||||
tenantId,
|
tenantId,
|
||||||
transactionId,
|
saleInvoiceId,
|
||||||
transactionType,
|
|
||||||
publicity,
|
publicity,
|
||||||
expiryTime,
|
expiryTime,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
DEFAULT_INVOICE_MAIL_SUBJECT,
|
DEFAULT_INVOICE_MAIL_SUBJECT,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
import { GetInvoicePaymentMail } from './GetInvoicePaymentMail';
|
import { GetInvoicePaymentMail } from './GetInvoicePaymentMail';
|
||||||
|
import { GenerateShareLink } from './GenerateeInvoicePaymentLink';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class SendSaleInvoiceMailCommon {
|
export class SendSaleInvoiceMailCommon {
|
||||||
@@ -23,6 +24,9 @@ export class SendSaleInvoiceMailCommon {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private getInvoicePaymentMail: GetInvoicePaymentMail;
|
private getInvoicePaymentMail: GetInvoicePaymentMail;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private generatePaymentLinkService: GenerateShareLink;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the mail options.
|
* Retrieves the mail options.
|
||||||
* @param {number} tenantId - Tenant id.
|
* @param {number} tenantId - Tenant id.
|
||||||
@@ -81,6 +85,13 @@ export class SendSaleInvoiceMailCommon {
|
|||||||
mailOptions,
|
mailOptions,
|
||||||
formatterArgs
|
formatterArgs
|
||||||
);
|
);
|
||||||
|
// Generates the a new payment link for the given invoice.
|
||||||
|
const paymentLink =
|
||||||
|
await this.generatePaymentLinkService.generatePaymentLink(
|
||||||
|
tenantId,
|
||||||
|
invoiceId,
|
||||||
|
'public'
|
||||||
|
);
|
||||||
const message = await this.getInvoicePaymentMail.getMailTemplate(
|
const message = await this.getInvoicePaymentMail.getMailTemplate(
|
||||||
tenantId,
|
tenantId,
|
||||||
invoiceId,
|
invoiceId,
|
||||||
@@ -88,6 +99,9 @@ export class SendSaleInvoiceMailCommon {
|
|||||||
// # Invoice message
|
// # Invoice message
|
||||||
invoiceMessage: formattedOptions.message,
|
invoiceMessage: formattedOptions.message,
|
||||||
preview: formattedOptions.message,
|
preview: formattedOptions.message,
|
||||||
|
|
||||||
|
// # Payment link
|
||||||
|
viewInvoiceButtonUrl: paymentLink.link,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return { ...formattedOptions, message };
|
return { ...formattedOptions, message };
|
||||||
|
|||||||
Reference in New Issue
Block a user