Merge pull request #871 from bigcapitalhq/fix-payment-link-base-url

fix: generated payment link base url
This commit is contained in:
Ahmed Bouhuolia
2025-12-14 13:29:09 +02:00
committed by GitHub
5 changed files with 25 additions and 8 deletions

View File

@@ -0,0 +1,5 @@
import { registerAs } from '@nestjs/config';
export default registerAs('app', () => ({
baseUrl: process.env.BASE_URL,
}));

View File

@@ -1,3 +1,4 @@
import app from './app';
import systemDatabase from './system-database';
import tenantDatabase from './tenant-database';
import signup from './signup';
@@ -18,6 +19,7 @@ import throttle from './throttle';
import cloud from './cloud';
export const config = [
app,
systemDatabase,
cloud,
tenantDatabase,

View File

@@ -10,6 +10,7 @@ import { PaymentLink } from '@/modules/PaymentLinks/models/PaymentLink';
import { SaleInvoice } from '../models/SaleInvoice';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
import { ConfigService } from '@nestjs/config';
@Injectable()
export class GenerateShareLink {
@@ -18,13 +19,14 @@ export class GenerateShareLink {
private eventPublisher: EventEmitter2,
private transformer: TransformerInjectable,
private tenancyContext: TenancyContext,
private configService: ConfigService,
@Inject(SaleInvoice.name)
private saleInvoiceModel: TenantModelProxy<typeof SaleInvoice>,
@Inject(PaymentLink.name)
private paymentLinkModel: typeof PaymentLink,
) {}
) { }
/**
* Generates private or public payment link for the given sale invoice.
@@ -75,6 +77,9 @@ export class GenerateShareLink {
return this.transformer.transform(
paymentLink,
new GeneratePaymentLinkTransformer(),
{
baseUrl: this.configService.get('app.baseUrl'),
}
);
});
}

View File

@@ -1,7 +1,10 @@
import { Transformer } from '@/modules/Transformer/Transformer';
import { PUBLIC_PAYMENT_LINK } from '../constants';
export class GeneratePaymentLinkTransformer extends Transformer {
interface GeneratePaymentLinkTransformerOptions {
baseUrl: string;
}
export class GeneratePaymentLinkTransformer extends Transformer<GeneratePaymentLinkTransformerOptions> {
/**
* Exclude these attributes from payment link object.
* @returns {Array}
@@ -23,6 +26,9 @@ export class GeneratePaymentLinkTransformer extends Transformer {
* @returns {string}
*/
public link(link) {
return PUBLIC_PAYMENT_LINK?.replace('{PAYMENT_LINK_ID}', link.linkId);
return PUBLIC_PAYMENT_LINK?.replace(
'{BASE_URL}',
this.options.baseUrl,
).replace('{PAYMENT_LINK_ID}', link.linkId);
}
}

View File

@@ -3,10 +3,9 @@
export const SendSaleInvoiceQueue = 'SendSaleInvoiceQueue';
export const SendSaleInvoiceMailJob = 'SendSaleInvoiceMailJob';
const BASE_URL = 'http://localhost:3000';
export const DEFAULT_INVOICE_MAIL_SUBJECT =
'Invoice {Invoice Number} from {Company Name} for {Customer Name}';
'Invoice {Invoice Number} from {Company Name} for {Customer Name}';
export const DEFAULT_INVOICE_MAIL_CONTENT = `Hi {Customer Name},
Here's invoice # {Invoice Number} for {Invoice Amount}
@@ -23,8 +22,8 @@ Thanks,
export const DEFAULT_INVOICE_REMINDER_MAIL_SUBJECT =
'Invoice {InvoiceNumber} reminder from {CompanyName}';
export const DEFAULT_INVOICE_REMINDER_MAIL_CONTENT = `
<p>Dear {CustomerName}</p>
export const DEFAULT_INVOICE_REMINDER_MAIL_CONTENT = `
<p>Dear {CustomerName}</p>
<p>You might have missed the payment date and the invoice is now overdue by {OverdueDays} days.</p>
<p>Invoice <strong>#{InvoiceNumber}</strong><br />
Due Date : <strong>{InvoiceDueDate}</strong><br />
@@ -36,7 +35,7 @@ Amount : <strong>{InvoiceAmount}</strong></p>
</p>
`;
export const PUBLIC_PAYMENT_LINK = `${BASE_URL}/payment/{PAYMENT_LINK_ID}`;
export const PUBLIC_PAYMENT_LINK = "{BASE_URL}/payment/{PAYMENT_LINK_ID}";
export const ERRORS = {
INVOICE_NUMBER_NOT_UNIQUE: 'INVOICE_NUMBER_NOT_UNIQUE',