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,
|
||||
asyncMiddleware(this.generateShareLink.bind(this))
|
||||
);
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
@@ -53,7 +52,6 @@ export class ShareLinkController extends BaseController {
|
||||
const link = await this.generateShareLinkService.generatePaymentLink(
|
||||
tenantId,
|
||||
transactionId,
|
||||
transactionType,
|
||||
publicity,
|
||||
expiryDate
|
||||
);
|
||||
|
||||
@@ -32,15 +32,14 @@ export class GenerateShareLink {
|
||||
*/
|
||||
async generatePaymentLink(
|
||||
tenantId: number,
|
||||
transactionId: number,
|
||||
transactionType: string,
|
||||
saleInvoiceId: number,
|
||||
publicity: string = 'private',
|
||||
expiryTime: string = ''
|
||||
) {
|
||||
const { SaleInvoice } = this.tenancy.models(tenantId);
|
||||
|
||||
const foundInvoice = await SaleInvoice.query()
|
||||
.findById(transactionId)
|
||||
.findById(saleInvoiceId)
|
||||
.throwIfNotFound();
|
||||
|
||||
// Generate unique uuid for sharable link.
|
||||
@@ -48,8 +47,7 @@ export class GenerateShareLink {
|
||||
|
||||
const commonEventPayload = {
|
||||
tenantId,
|
||||
transactionId,
|
||||
transactionType,
|
||||
saleInvoiceId,
|
||||
publicity,
|
||||
expiryTime,
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
DEFAULT_INVOICE_MAIL_SUBJECT,
|
||||
} from './constants';
|
||||
import { GetInvoicePaymentMail } from './GetInvoicePaymentMail';
|
||||
import { GenerateShareLink } from './GenerateeInvoicePaymentLink';
|
||||
|
||||
@Service()
|
||||
export class SendSaleInvoiceMailCommon {
|
||||
@@ -23,6 +24,9 @@ export class SendSaleInvoiceMailCommon {
|
||||
@Inject()
|
||||
private getInvoicePaymentMail: GetInvoicePaymentMail;
|
||||
|
||||
@Inject()
|
||||
private generatePaymentLinkService: GenerateShareLink;
|
||||
|
||||
/**
|
||||
* Retrieves the mail options.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
@@ -81,6 +85,13 @@ export class SendSaleInvoiceMailCommon {
|
||||
mailOptions,
|
||||
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(
|
||||
tenantId,
|
||||
invoiceId,
|
||||
@@ -88,6 +99,9 @@ export class SendSaleInvoiceMailCommon {
|
||||
// # Invoice message
|
||||
invoiceMessage: formattedOptions.message,
|
||||
preview: formattedOptions.message,
|
||||
|
||||
// # Payment link
|
||||
viewInvoiceButtonUrl: paymentLink.link,
|
||||
}
|
||||
);
|
||||
return { ...formattedOptions, message };
|
||||
|
||||
Reference in New Issue
Block a user