import { Text, Classes, Button, Intent } from '@blueprintjs/core'; import clsx from 'classnames'; import { AppToaster, Box, Group, Stack } from '@/components'; import { usePaymentPortalBoot } from './PaymentPortalBoot'; import { useDrawerActions } from '@/hooks/state'; import { useCreateStripeCheckoutSession, useGeneratePaymentLinkInvoicePdf, } from '@/hooks/query/payment-link'; import { DRAWERS } from '@/constants/drawers'; import { downloadFile } from '@/hooks/useDownloadFile'; import styles from './PaymentPortal.module.scss'; export function PaymentPortal() { const { openDrawer } = useDrawerActions(); const { sharableLinkMeta, linkId } = usePaymentPortalBoot(); const { mutateAsync: createStripeCheckoutSession, isLoading: isStripeCheckoutLoading, } = useCreateStripeCheckoutSession(); const { mutateAsync: generatePaymentLinkInvoice, isLoading: isInvoiceGenerating, } = useGeneratePaymentLinkInvoicePdf(); // Handles invoice preview button click. const handleInvoicePreviewBtnClick = () => { openDrawer(DRAWERS.PAYMENT_INVOICE_PREVIEW); }; // Handles invoice download button click. const handleInvoiceDownloadBtnClick = () => { generatePaymentLinkInvoice({ paymentLinkId: linkId }) .then((data) => { downloadFile( data, `Invoice ${sharableLinkMeta?.invoiceNo}`, 'application/pdf', ); }) .catch(() => { AppToaster.show({ intent: Intent.DANGER, message: 'Something went wrong.', }); }); }; // handles the pay button click. const handlePayButtonClick = () => { createStripeCheckoutSession({ linkId }) .then((session) => { window.open(session.redirectTo); }) .catch((error) => { AppToaster.show({ intent: Intent.DANGER, message: 'Something went wrong.', }); }); }; return ( {sharableLinkMeta?.organization?.logoUri && ( )} {sharableLinkMeta?.organization?.name}

{sharableLinkMeta?.organization?.name} Sent an Invoice for{' '} {sharableLinkMeta?.totalFormatted}

Invoice due {sharableLinkMeta?.dueDateFormatted}{' '}
{sharableLinkMeta?.customerName} {sharableLinkMeta?.formattedCustomerAddress && ( )}

Invoice {sharableLinkMeta?.invoiceNo}

Sub Total {sharableLinkMeta?.subtotalFormatted} Total {sharableLinkMeta?.totalFormatted} {sharableLinkMeta?.taxes?.map((tax, key) => ( {tax?.name} {tax?.taxRateAmountFormatted} ))} Paid Amount (-) {sharableLinkMeta?.paymentAmountFormatted} Due Amount {sharableLinkMeta?.dueAmountFormatted}
{sharableLinkMeta?.isReceivable && sharableLinkMeta?.hasStripePaymentMethod && ( )} By confirming your payment, you allow Bigcapital Technology, Inc. to charge you for this payment and save your payment information in accordance with their terms.
© 2024 Bigcapital Technology, Inc.
All rights reserved.
); }