Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(app): show invoice currency and Google Play refund wording

Hampus2a417f66b5a9
diff --git a/fluxer_app/src/features/app/components/dialogs/components/plutonium/InvoiceList.tsx b/fluxer_app/src/features/app/components/dialogs/components/plutonium/InvoiceList.tsx
index 21db55729..4a29d38f3 100644
--- a/fluxer_app/src/features/app/components/dialogs/components/plutonium/InvoiceList.tsx
+++ b/fluxer_app/src/features/app/components/dialogs/components/plutonium/InvoiceList.tsx
@@ -2,11 +2,12 @@
import styles from '@app/features/app/components/dialogs/components/plutonium/InvoiceList.module.css';
import statusStyles from '@app/features/app/components/dialogs/components/plutonium/PurchaseHistoryStatus.module.css';
-import {formatMinorUnitPrice} from '@app/features/premium/utils/PricingUtils';
-import {Button} from '@app/features/ui/button/Button';
+import {PlutoniumPageButton} from '@app/features/premium/components/plutonium_page/PlutoniumPageButton';
+import PremiumState from '@app/features/premium/state/PremiumState';
import {openExternalUrl} from '@app/features/ui/utils/NativeUtils';
import {getCurrentLocale} from '@app/features/user/utils/LocaleUtils';
import {getFormattedShortDate} from '@fluxer/date_utils/src/DateFormatting';
+import {formatMinorUnitPrice} from '@fluxer/number_utils/src/PriceFormatting';
import type {PremiumBillingInvoiceResponse} from '@fluxer/schema/src/domains/premium/PremiumSchemas';
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
@@ -47,6 +48,12 @@ const OPEN_INVOICE_DESCRIPTOR = msg({
comment: 'Accessible label for opening a specific billing invoice.',
});
+const AMOUNT_WITH_CURRENCY_DESCRIPTOR = msg({
+ message: '{amount} ({currency})',
+ comment:
+ 'Amount of an invoice in the billing history, followed by its three-letter currency code so the receipt always names the currency, for example "9,99 kr (SEK)". {amount} is a price already formatted by code and {currency} is an ISO currency code such as SEK or USD. Keep both placeholders as they are and use the brackets your language normally uses.',
+});
+
function formatInvoiceDate(invoice: PremiumBillingInvoiceResponse): string | null {
const source = invoice.paid_at ?? invoice.created_at;
if (!source) return null;
@@ -55,13 +62,20 @@ function formatInvoiceDate(invoice: PremiumBillingInvoiceResponse): string | nul
return getFormattedShortDate(date, getCurrentLocale());
}
-function formatInvoiceAmount(invoice: PremiumBillingInvoiceResponse): string {
- const formattedAmount = formatMinorUnitPrice(
+const SHARED_CURRENCY_SYMBOLS = new Set(['$', 'kr', 'kr.', 'Kr', '¥', 'R', 'Rs', 'fr', 'Fr', 'zł']);
+
+function formatInvoiceAmount(i18n: I18n, invoice: PremiumBillingInvoiceResponse): string {
+ const amount = formatMinorUnitPrice(
invoice.amount_paid || invoice.amount_due,
invoice.currency,
getCurrentLocale(),
+ PremiumState.state?.pricing.country_code,
);
- return formattedAmount ?? '';
+ if (!amount) return '';
+ const currency = invoice.currency.toUpperCase();
+ const symbol = amount.replace(/[\d\s.,'\u00a0\u202f\u2212-]/g, '');
+ if (!SHARED_CURRENCY_SYMBOLS.has(symbol)) return amount;
+ return i18n._(AMOUNT_WITH_CURRENCY_DESCRIPTOR, {amount, currency});
}
function getInvoiceDateLabel(i18n: I18n, invoice: PremiumBillingInvoiceResponse): string {
@@ -131,9 +145,9 @@ export const InvoiceList: React.FC<InvoiceListProps> = observer(({invoices}) =>
</div>
{invoices.map((invoice) => {
const invoiceDate = getInvoiceDateLabel(i18n, invoice);
- const amount = formatInvoiceAmount(invoice);
+ const amount = formatInvoiceAmount(i18n, invoice);
const invoiceUrl = invoice.hosted_invoice_url ?? invoice.invoice_pdf;
- const invoiceLabel = invoice.number ?? invoice.id;
+ const invoiceLabel = invoice.number ?? invoiceDate;
return (
<div className={styles.row} key={invoice.id} data-flx="app.plutonium.invoice-list.row">
<span className={styles.date} data-flx="app.plutonium.invoice-list.date">
@@ -145,10 +159,9 @@ export const InvoiceList: React.FC<InvoiceListProps> = observer(({invoices}) =>
<span className={getInvoiceStatusClass(invoice.status)} data-flx="app.plutonium.invoice-list.span--5">
{formatInvoiceStatus(invoice.status)}
</span>
- <Button
+ <PlutoniumPageButton
variant="secondary"
- superCompact
- fitContent
+ small
disabled={!invoiceUrl}
aria-label={i18n._(OPEN_INVOICE_DESCRIPTOR, {invoiceLabel})}
onClick={() => {
@@ -157,7 +170,7 @@ export const InvoiceList: React.FC<InvoiceListProps> = observer(({invoices}) =>
data-flx="app.plutonium.invoice-list.button"
>
<Trans comment="Short button that opens a billing invoice or receipt.">Open</Trans>
- </Button>
+ </PlutoniumPageButton>
</div>
);
})}
diff --git a/fluxer_app/src/features/app/components/dialogs/components/plutonium/SelfServeRefundSection.tsx b/fluxer_app/src/features/app/components/dialogs/components/plutonium/SelfServeRefundSection.tsx
index 89864260a..9e23ae2da 100644
--- a/fluxer_app/src/features/app/components/dialogs/components/plutonium/SelfServeRefundSection.tsx
+++ b/fluxer_app/src/features/app/components/dialogs/components/plutonium/SelfServeRefundSection.tsx
@@ -7,7 +7,7 @@ import styles from '@app/features/app/components/dialogs/components/plutonium/Pu
import {Logger} from '@app/features/platform/utils/AppLogger';
import {failureCode} from '@app/features/platform/utils/ResponseInspection';
import * as PremiumCommands from '@app/features/premium/commands/PremiumCommands';
-import {Button} from '@app/features/ui/button/Button';
+import {PlutoniumPageButton} from '@app/features/premium/components/plutonium_page/PlutoniumPageButton';
import * as ModalCommands from '@app/features/ui/commands/ModalCommands';
import {modal} from '@app/features/ui/commands/ModalCommands';
import * as ToastCommands from '@app/features/ui/commands/ToastCommands';
@@ -18,7 +18,7 @@ import type {SelfServeRefundEligibilityResponse} from '@fluxer/schema/src/domain
import {msg} from '@lingui/core/macro';
import {Trans, useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
-import {useCallback, useState} from 'react';
+import {type ReactNode, useCallback, useState} from 'react';
const REFUND_YOUR_MOST_RECENT_PURCHASE_DESCRIPTOR = msg({
message: 'Refund your most recent purchase?',
@@ -124,16 +124,24 @@ export const SelfServeRefundSection: React.FC<SelfServeRefundSectionProps> = obs
({eligibility, refreshPremiumState}) => {
const {i18n} = useLingui();
const [submitting, setSubmitting] = useState(false);
+ const isGooglePlay = eligibility?.provider === 'google_play';
const handleRefund = useCallback(() => {
ModalCommands.push(
modal(() => (
<ConfirmModal
title={i18n._(REFUND_YOUR_MOST_RECENT_PURCHASE_DESCRIPTOR)}
description={
- <Trans>
- This refunds your most recent invoice and cancels any associated subscription. You won't be able to
- self-refund again for 30 days.
- </Trans>
+ isGooglePlay ? (
+ <Trans>
+ This refunds your most recent Google Play purchase and cancels any subscription it paid for. You won't
+ be able to self-refund again for 30 days.
+ </Trans>
+ ) : (
+ <Trans>
+ This refunds your most recent purchase and cancels any subscription it paid for. You won't be able to
+ self-refund again for 30 days.
+ </Trans>
+ )
}
primaryText={i18n._(REFUND_PURCHASE_DESCRIPTOR)}
primaryVariant="danger"
@@ -155,7 +163,7 @@ export const SelfServeRefundSection: React.FC<SelfServeRefundSectionProps> = obs
/>
)),
);
- }, [refreshPremiumState, i18n]);
+ }, [refreshPremiumState, i18n, isGooglePlay]);
if (
!eligibility ||
eligibility.reason === 'no_refundable_purchase' ||
@@ -166,6 +174,21 @@ export const SelfServeRefundSection: React.FC<SelfServeRefundSectionProps> = obs
const isEligible = eligibility.eligible;
const windowEndsOn = formatRelativeTime(eligibility.refund_window_expires_at);
const cooldownEndsOn = formatRelativeTime(eligibility.cooldown_expires_at);
+ let description: ReactNode;
+ if (isEligible && eligibility.cancels_subscription) {
+ description = (
+ <Trans>Eligible for a refund until {windowEndsOn}. This will also cancel your subscription immediately.</Trans>
+ );
+ } else if (isEligible) {
+ description = <Trans>Eligible for a refund until {windowEndsOn}.</Trans>;
+ } else if (eligibility.reason === 'outside_refund_window') {
+ description = <Trans>Your last purchase is outside the refund window. Contact support for billing issues.</Trans>;
+ } else if (eligibility.reason === 'cooldown_active') {
+ description = <Trans>You can refund again after {cooldownEndsOn}. Contact support for billing issues.</Trans>;
+ } else {
+ description = <Trans>This purchase is not eligible for a refund.</Trans>;
+ }
+
return (
<section className={styles.section} data-flx="app.plutonium.self-serve-refund-section.section">
<div className={styles.card} data-flx="app.plutonium.self-serve-refund-section.card">
@@ -175,34 +198,20 @@ export const SelfServeRefundSection: React.FC<SelfServeRefundSectionProps> = obs
<Trans>Refund</Trans>
</h3>
<p className={styles.description} data-flx="app.plutonium.self-serve-refund-section.description">
- {isEligible ? (
- eligibility.cancels_subscription ? (
- <Trans>
- Eligible for a refund until {windowEndsOn}. This will also cancel your subscription immediately.
- </Trans>
- ) : (
- <Trans>Eligible for a refund until {windowEndsOn}.</Trans>
- )
- ) : eligibility.reason === 'outside_refund_window' ? (
- <Trans>Your last purchase is outside the refund window. Contact support for billing issues.</Trans>
- ) : eligibility.reason === 'cooldown_active' ? (
- <Trans>You can refund again after {cooldownEndsOn}. Contact support for billing issues.</Trans>
- ) : (
- <Trans>This purchase is not eligible for a refund.</Trans>
- )}
+ {description}
</p>
</div>
- <Button
+ <PlutoniumPageButton
variant="danger"
onClick={handleRefund}
- submitting={submitting}
+ loading={submitting}
disabled={!isEligible}
small
className={styles.button}
data-flx="app.plutonium.self-serve-refund-section.button.refund"
>
<Trans>Refund purchase</Trans>
- </Button>
+ </PlutoniumPageButton>
</div>
</div>
</section>