feat: Hook up company address to payment page

This commit is contained in:
Ahmed Bouhuolia
2024-09-28 20:19:05 +02:00
parent e506a7ba35
commit 9b63c176cd
6 changed files with 123 additions and 23 deletions

View File

@@ -45,6 +45,7 @@ export class GetInvoicePaymentLinkMetadata {
.withGraphFetched('entries.item')
.withGraphFetched('customer')
.withGraphFetched('taxes.taxRate')
.withGraphFetched('paymentMethods.paymentIntegration')
.throwIfNotFound();
return this.transformer.transform(

View File

@@ -41,6 +41,8 @@ export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer
'entries',
'taxes',
'organization',
'isReceivable',
'hasStripePaymentMethod',
];
};
@@ -50,7 +52,7 @@ export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer
/**
* Retrieves the organization metadata for the payment link.
* @returns
* @returns
*/
public organization(invoice) {
return this.item(
@@ -89,6 +91,16 @@ export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer
}
);
};
protected isReceivable(invoice) {
return invoice.dueAmount > 0;
}
protected hasStripePaymentMethod(invoice) {
return invoice.paymentMethods.some(
(paymentMethod) => paymentMethod.paymentIntegration.service === 'Stripe'
);
}
}
class GetPaymentLinkOrganizationMetaTransformer extends Transformer {
@@ -97,12 +109,26 @@ class GetPaymentLinkOrganizationMetaTransformer extends Transformer {
* @returns {Array}
*/
public includeAttributes = (): string[] => {
return ['primaryColor', 'name', 'address', 'logoUri'];
return [
'primaryColor',
'name',
'address',
'logoUri',
'addressTextFormatted',
];
};
public excludeAttributes = (): string[] => {
return ['*'];
};
/**
* Retrieves the formatted text of organization address.
* @returns {string}
*/
public addressTextFormatted() {
return this.context.organization.addressTextFormatted;
}
}
class GetInvoicePaymentLinkEntryMetaTransformer extends ItemEntryTransformer {