fix: payment page

This commit is contained in:
Ahmed Bouhuolia
2024-09-25 12:21:26 +02:00
parent 2f9adfd908
commit 946872204b
8 changed files with 59 additions and 3 deletions

View File

@@ -25,6 +25,17 @@ export class PaymentIntegration extends Model {
return this.paymentEnabled && this.payoutEnabled; return this.paymentEnabled && this.payoutEnabled;
} }
static get modifiers() {
return {
/**
* Query to filter enabled payment and payout.
*/
fullEnabled(query) {
query.where('paymentEnabled', true).andWhere('payoutEnabled', true);
},
};
}
static get jsonSchema() { static get jsonSchema() {
return { return {
type: 'object', type: 'object',

View File

@@ -21,7 +21,7 @@ export class GetPaymentServicesSpecificInvoice {
const { PaymentIntegration } = this.tenancy.models(tenantId); const { PaymentIntegration } = this.tenancy.models(tenantId);
const paymentGateways = await PaymentIntegration.query() const paymentGateways = await PaymentIntegration.query()
.where('active', true) .modify('fullEnabled')
.orderBy('name', 'ASC'); .orderBy('name', 'ASC');
return this.transform.transform( return this.transform.transform(

View File

@@ -44,6 +44,7 @@ export class GetInvoicePaymentLinkMetadata {
.findById(paymentLink.resourceId) .findById(paymentLink.resourceId)
.withGraphFetched('entries.item') .withGraphFetched('entries.item')
.withGraphFetched('customer') .withGraphFetched('customer')
.withGraphFetched('taxes.taxRate')
.throwIfNotFound(); .throwIfNotFound();
return this.transformer.transform( return this.transformer.transform(

View File

@@ -1,4 +1,5 @@
import { ItemEntryTransformer } from './ItemEntryTransformer'; import { ItemEntryTransformer } from './ItemEntryTransformer';
import { SaleInvoiceTaxEntryTransformer } from './SaleInvoiceTaxEntryTransformer';
import { SaleInvoiceTransformer } from './SaleInvoiceTransformer'; import { SaleInvoiceTransformer } from './SaleInvoiceTransformer';
export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer { export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer {
@@ -37,6 +38,7 @@ export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer
'invoiceMessage', 'invoiceMessage',
'termsConditions', 'termsConditions',
'entries', 'entries',
'taxes',
]; ];
}; };
@@ -62,6 +64,22 @@ export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer
} }
); );
}; };
/**
* Retrieves the sale invoice entries.
* @returns {}
*/
protected taxes = (invoice) => {
return this.item(
invoice.taxes,
new GetInvoicePaymentLinkTaxEntryTransformer(),
{
subtotal: invoice.subtotal,
isInclusiveTax: invoice.isInclusiveTax,
currencyCode: invoice.currencyCode,
}
);
};
} }
class GetInvoicePaymentLinkEntryMetaTransformer extends ItemEntryTransformer { class GetInvoicePaymentLinkEntryMetaTransformer extends ItemEntryTransformer {
@@ -94,3 +112,13 @@ class GetInvoicePaymentLinkEntryMetaTransformer extends ItemEntryTransformer {
return ['*']; return ['*'];
}; };
} }
class GetInvoicePaymentLinkTaxEntryTransformer extends SaleInvoiceTaxEntryTransformer {
/**
* Included attributes.
* @returns {Array}
*/
public includeAttributes = (): string[] => {
return ['name', 'taxRateCode', 'taxRateAmount', 'taxRateAmountFormatted'];
};
}

View File

@@ -1,6 +1,6 @@
.rootBodyPage { .rootBodyPage {
background: #0c103f; background: #1c1d29;
} }
.root { .root {

View File

@@ -83,6 +83,13 @@ export function PaymentPortal() {
</Text> </Text>
</Group> </Group>
{sharableLinkMeta?.taxes?.map((tax, key) => (
<Group key={key} position={'apart'} className={styles.totalItem}>
<Text>{tax?.name}</Text>
<Text>{tax?.taxRateAmountFormatted}</Text>
</Group>
))}
<Group <Group
position={'apart'} position={'apart'}
className={clsx(styles.totalItem, styles.borderBottomGray)} className={clsx(styles.totalItem, styles.borderBottomGray)}

View File

@@ -30,6 +30,10 @@ export function PaymentInvoicePreviewContent() {
rate: entry.rateFormatted, rate: entry.rateFormatted,
total: entry.totalFormatted, total: entry.totalFormatted,
}))} }))}
taxes={sharableLinkMeta?.taxes?.map((tax) => ({
label: tax.name,
amount: tax.taxRateAmountFormatted,
}))}
/> />
</Box> </Box>
</DrawerBody> </DrawerBody>

View File

@@ -50,7 +50,6 @@ export function useCreatePaymentLink(
); );
} }
// Get Invoice Payment Link // Get Invoice Payment Link
// ----------------------------------------- // -----------------------------------------
export interface GetInvoicePaymentLinkResponse { export interface GetInvoicePaymentLinkResponse {
@@ -82,6 +81,12 @@ export interface GetInvoicePaymentLinkResponse {
total: number; total: number;
totalFormatted: string; totalFormatted: string;
}>; }>;
taxes: Array<{
name: string;
taxRateAmount: number;
taxRateAmountFormatted: string;
taxRateCode: string;
}>;
} }
/** /**
* Fetches the sharable invoice link metadata for a given link ID. * Fetches the sharable invoice link metadata for a given link ID.