fix: attach branding template attrs to payment page

This commit is contained in:
Ahmed Bouhuolia
2024-11-11 20:25:42 +02:00
parent c58822fd6c
commit 7ee3392d3e
6 changed files with 93 additions and 6 deletions

View File

@@ -25,7 +25,7 @@ export class GetInvoicePaymentLinkMetadata {
.findOne('linkId', linkId)
.where('resourceType', 'SaleInvoice')
.throwIfNotFound();
// Validate the expiry at date.
if (paymentLink.expiryAt) {
const currentDate = moment();
@@ -46,6 +46,7 @@ export class GetInvoicePaymentLinkMetadata {
.withGraphFetched('customer')
.withGraphFetched('taxes.taxRate')
.withGraphFetched('paymentMethods.paymentIntegration')
.withGraphFetched('pdfTemplate')
.throwIfNotFound();
return this.transformer.transform(

View File

@@ -4,6 +4,7 @@ import { SaleInvoiceTaxEntryTransformer } from './SaleInvoiceTaxEntryTransformer
import { SaleInvoiceTransformer } from './SaleInvoiceTransformer';
import { Transformer } from '@/lib/Transformer/Transformer';
import { contactAddressTextFormat } from '@/utils/address-text-format';
import { GetPdfTemplateTransformer } from '@/services/PdfTemplate/GetPdfTemplateTransformer';
export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer {
/**
@@ -45,6 +46,7 @@ export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer
'isReceivable',
'hasStripePaymentMethod',
'formattedCustomerAddress',
'brandingTemplate',
];
};
@@ -63,6 +65,18 @@ export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer
);
}
/**
* Retrieves the branding template for the payment link.
* @param {} invoice
* @returns
*/
public brandingTemplate(invoice) {
return this.item(
invoice.pdfTemplate,
new GetInvoicePaymentLinkBrandingTemplate()
);
}
/**
* Retrieves the entries of the sale invoice.
* @param {ISaleInvoice} invoice
@@ -114,7 +128,7 @@ export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer
/**
* Retrieves the formatted customer address.
* @param invoice
* @param invoice
* @returns {string}
*/
protected formattedCustomerAddress(invoice) {
@@ -193,3 +207,17 @@ class GetInvoicePaymentLinkTaxEntryTransformer extends SaleInvoiceTaxEntryTransf
return ['name', 'taxRateCode', 'taxRateAmount', 'taxRateAmountFormatted'];
};
}
class GetInvoicePaymentLinkBrandingTemplate extends GetPdfTemplateTransformer {
public includeAttributes = (): string[] => {
return ['companyLogoUri', 'primaryColor'];
};
public excludeAttributes = (): string[] => {
return ['*'];
};
primaryColor = (template) => {
return template.attributes?.primaryColor;
};
}