From 7ee3392d3e08bffdcfbf2df07c5efe2235508b38 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Mon, 11 Nov 2024 20:25:42 +0200 Subject: [PATCH] fix: attach branding template attrs to payment page --- .../GetInvoicePaymentLinkMetadata.ts | 3 +- .../GetInvoicePaymentLinkTransformer.ts | 30 ++++++++++++++++- .../PaymentPortal/PaymentPortal.module.scss | 7 +++- .../PaymentPortal/PaymentPortal.tsx | 22 +++++++++++-- .../PaymentPortal/PaymentPortalPage.tsx | 33 +++++++++++++++++++ .../webapp/src/hooks/query/payment-link.ts | 4 +++ 6 files changed, 93 insertions(+), 6 deletions(-) diff --git a/packages/server/src/services/PaymentLinks/GetInvoicePaymentLinkMetadata.ts b/packages/server/src/services/PaymentLinks/GetInvoicePaymentLinkMetadata.ts index d12adca4b..f437869bd 100644 --- a/packages/server/src/services/PaymentLinks/GetInvoicePaymentLinkMetadata.ts +++ b/packages/server/src/services/PaymentLinks/GetInvoicePaymentLinkMetadata.ts @@ -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( diff --git a/packages/server/src/services/Sales/Invoices/GetInvoicePaymentLinkTransformer.ts b/packages/server/src/services/Sales/Invoices/GetInvoicePaymentLinkTransformer.ts index 824c1c5d4..d86ffb04d 100644 --- a/packages/server/src/services/Sales/Invoices/GetInvoicePaymentLinkTransformer.ts +++ b/packages/server/src/services/Sales/Invoices/GetInvoicePaymentLinkTransformer.ts @@ -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; + }; +} diff --git a/packages/webapp/src/containers/PaymentPortal/PaymentPortal.module.scss b/packages/webapp/src/containers/PaymentPortal/PaymentPortal.module.scss index 5c804fae8..bfe60d8ad 100644 --- a/packages/webapp/src/containers/PaymentPortal/PaymentPortal.module.scss +++ b/packages/webapp/src/containers/PaymentPortal/PaymentPortal.module.scss @@ -1,6 +1,11 @@ +:root { + --payment-page-background-color: #fff; + --payment-page-primary-button: #0052cc; +} + .rootBodyPage { - background: #1c1d29; + background: var(--payment-page-background-color); } .root { diff --git a/packages/webapp/src/containers/PaymentPortal/PaymentPortal.tsx b/packages/webapp/src/containers/PaymentPortal/PaymentPortal.tsx index e6a11bd0e..9d5e4fc08 100644 --- a/packages/webapp/src/containers/PaymentPortal/PaymentPortal.tsx +++ b/packages/webapp/src/containers/PaymentPortal/PaymentPortal.tsx @@ -1,5 +1,6 @@ import { Text, Classes, Button, Intent } from '@blueprintjs/core'; import clsx from 'classnames'; +import { css } from '@emotion/css'; import { AppToaster, Box, Group, Stack } from '@/components'; import { usePaymentPortalBoot } from './PaymentPortalBoot'; import { useDrawerActions } from '@/hooks/state'; @@ -66,11 +67,11 @@ export function PaymentPortal() { - {sharableLinkMeta?.organization?.logoUri && ( + {sharableLinkMeta?.brandingTemplate?.companyLogoUri && ( )} @@ -170,7 +171,22 @@ export function PaymentPortal() { sharableLinkMeta?.hasStripePaymentMethod && (