Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions src/features/settings/readiness/readiness-utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { describe, expect, it } from "vitest"

import { createReadinessItems } from "./readiness-utils.ts"

const baseInput = {
hasRecoveryPhrase: true,
hasActiveSyncTransport: true,
hasActiveSparkAccount: true,
hasActiveCashRegisterAccount: false,
hasActiveFiatBankAccount: true,
hasDefaultPaymentMethod: true,
isDefaultPaymentMethodAvailable: true,
hasActiveFioPlugin: true,
hasActiveFioPluginToken: true,
}

describe("createReadinessItems", () => {
it("marks the setup checklist complete when required state is ready", () => {
const items = createReadinessItems(baseInput)

expect(items).toEqual([
expect.objectContaining({ id: "recoveryPhrase", completed: true }),
expect.objectContaining({ id: "sync", completed: true }),
expect.objectContaining({ id: "paymentMethods", completed: true }),
expect.objectContaining({ id: "defaultPaymentMethod", completed: true }),
expect.objectContaining({ id: "bankAccount", completed: true }),
expect.objectContaining({ id: "fioPlugin", completed: true }),
])
})

it("marks missing setup as incomplete and points to the relevant settings screens", () => {
const items = createReadinessItems({
...baseInput,
hasActiveSyncTransport: false,
hasActiveSparkAccount: false,
hasActiveFiatBankAccount: false,
hasDefaultPaymentMethod: false,
isDefaultPaymentMethodAvailable: false,
hasActiveFioPlugin: false,
hasActiveFioPluginToken: false,
})

expect(items).toEqual([
expect.objectContaining({
id: "recoveryPhrase",
completed: true,
actionTo: "/settings/security",
}),
expect.objectContaining({
id: "sync",
completed: false,
actionTo: "/settings/security",
}),
expect.objectContaining({
id: "paymentMethods",
completed: false,
actionTo: "/settings/payment-accounts",
}),
expect.objectContaining({
id: "defaultPaymentMethod",
completed: false,
actionTo: "/settings/default-payment-method",
}),
expect.objectContaining({
id: "bankAccount",
completed: false,
actionTo: "/settings/payment-accounts",
}),
expect.objectContaining({
id: "fioPlugin",
completed: true,
actionTo: "/settings/fio-plugin",
}),
])
})

it("marks Fio incomplete when bank payments are active without an active plugin", () => {
const items = createReadinessItems({
...baseInput,
hasActiveFioPlugin: false,
})

expect(items.find((item) => item.id === "fioPlugin")?.completed).toBe(false)
})

it("marks Fio incomplete when bank payments are active with an active plugin but no token", () => {
const items = createReadinessItems({
...baseInput,
hasActiveFioPluginToken: false,
})

expect(items.find((item) => item.id === "fioPlugin")?.completed).toBe(false)
})

it("marks Fio complete when bank payments are inactive even without a plugin token", () => {
const items = createReadinessItems({
...baseInput,
hasActiveFiatBankAccount: false,
hasActiveFioPlugin: false,
hasActiveFioPluginToken: false,
})

expect(items.find((item) => item.id === "fioPlugin")?.completed).toBe(true)
})

it("accepts any active payment method and only requires Fio for bank payments", () => {
const items = createReadinessItems({
...baseInput,
hasActiveSparkAccount: false,
hasActiveCashRegisterAccount: true,
hasActiveFiatBankAccount: false,
hasActiveFioPlugin: false,
hasActiveFioPluginToken: false,
})

expect(items.find((item) => item.id === "paymentMethods")?.completed).toBe(
true
)
expect(items.find((item) => item.id === "bankAccount")?.completed).toBe(
false
)
expect(items.find((item) => item.id === "fioPlugin")?.completed).toBe(true)
})
})
126 changes: 126 additions & 0 deletions src/features/settings/readiness/readiness-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import type { LinkProps } from "@tanstack/react-router"

import type { DefaultPaymentMethod } from "@/core/modules/app-settings/app-settings-types.ts"
import type { TranslationKey } from "@/i18n/resources.ts"

export type ReadinessItemId =
| "recoveryPhrase"
| "sync"
| "paymentMethods"
| "defaultPaymentMethod"
| "bankAccount"
| "fioPlugin"

export interface ReadinessStateInput {
readonly hasRecoveryPhrase: boolean
readonly hasActiveSyncTransport: boolean
readonly hasActiveSparkAccount: boolean
readonly hasActiveCashRegisterAccount: boolean
readonly hasActiveFiatBankAccount: boolean
readonly hasDefaultPaymentMethod: boolean
readonly isDefaultPaymentMethodAvailable: boolean
readonly hasActiveFioPlugin: boolean
readonly hasActiveFioPluginToken: boolean
}

export interface ReadinessItem {
readonly id: ReadinessItemId
readonly title: TranslationKey
readonly description: TranslationKey
readonly completed: boolean
readonly actionLabel: TranslationKey
readonly actionTo: LinkProps["to"]
}

export function isPaymentMethodAvailable({
method,
hasActiveSparkAccount,
hasActiveCashRegisterAccount,
hasActiveFiatBankAccount,
}: {
readonly method: DefaultPaymentMethod | null | undefined
readonly hasActiveSparkAccount: boolean
readonly hasActiveCashRegisterAccount: boolean
readonly hasActiveFiatBankAccount: boolean
}) {
switch (method) {
case "spark":
return hasActiveSparkAccount
case "cashRegister":
return hasActiveCashRegisterAccount
case "iban":
return hasActiveFiatBankAccount
default:
return false
}
}

export function createReadinessItems({
hasRecoveryPhrase,
hasActiveSyncTransport,
hasActiveSparkAccount,
hasActiveCashRegisterAccount,
hasActiveFiatBankAccount,
hasDefaultPaymentMethod,
isDefaultPaymentMethodAvailable,
hasActiveFioPlugin,
hasActiveFioPluginToken,
}: ReadinessStateInput): ReadonlyArray<ReadinessItem> {
const hasAnyPaymentMethod =
hasActiveSparkAccount ||
hasActiveCashRegisterAccount ||
hasActiveFiatBankAccount

return [
{
id: "recoveryPhrase",
title: "settings.readiness.item.recoveryPhrase.title",
description: "settings.readiness.item.recoveryPhrase.description",
completed: hasRecoveryPhrase,
actionLabel: "settings.readiness.item.recoveryPhrase.action",
actionTo: "/settings/security",
},
{
id: "sync",
title: "settings.readiness.item.sync.title",
description: "settings.readiness.item.sync.description",
completed: hasActiveSyncTransport,
actionLabel: "settings.readiness.item.sync.action",
actionTo: "/settings/security",
},
{
id: "paymentMethods",
title: "settings.readiness.item.paymentMethods.title",
description: "settings.readiness.item.paymentMethods.description",
completed: hasAnyPaymentMethod,
actionLabel: "settings.readiness.item.paymentMethods.action",
actionTo: "/settings/payment-accounts",
},
{
id: "defaultPaymentMethod",
title: "settings.readiness.item.defaultPaymentMethod.title",
description: "settings.readiness.item.defaultPaymentMethod.description",
completed: hasDefaultPaymentMethod && isDefaultPaymentMethodAvailable,
actionLabel: "settings.readiness.item.defaultPaymentMethod.action",
actionTo: "/settings/default-payment-method",
},
{
id: "bankAccount",
title: "settings.readiness.item.bankAccount.title",
description: "settings.readiness.item.bankAccount.description",
completed: hasActiveFiatBankAccount,
actionLabel: "settings.readiness.item.bankAccount.action",
actionTo: "/settings/payment-accounts",
},
{
id: "fioPlugin",
title: "settings.readiness.item.fioPlugin.title",
description: "settings.readiness.item.fioPlugin.description",
completed:
!hasActiveFiatBankAccount ||
(hasActiveFioPlugin && hasActiveFioPluginToken),
actionLabel: "settings.readiness.item.fioPlugin.action",
actionTo: "/settings/fio-plugin",
},
]
}
35 changes: 35 additions & 0 deletions src/i18n/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,41 @@ export const cs = {
"settings.privacy.errorReporting.title": "Hlášení chyb",
"settings.privacy.title": "Soukromí",
"settings.privacyGroup": "SOUKROMÍ",
"settings.readiness.description":
"Checklist pro používání Payky se skutečnými zákazníky",
"settings.readiness.item.bankAccount.action": "Nastavit bankovní účet",
"settings.readiness.item.bankAccount.description":
"Bankovní QR platby potřebují povolený účet pro aktuální fiat měnu.",
"settings.readiness.item.bankAccount.title": "Bankovní účet",
"settings.readiness.item.defaultPaymentMethod.action":
"Vybrat výchozí metodu",
"settings.readiness.item.defaultPaymentMethod.description":
"Checkout se má otevírat s platební metodou, která je teď povolená.",
"settings.readiness.item.defaultPaymentMethod.title":
"Výchozí platební metoda",
"settings.readiness.item.fioPlugin.action": "Nastavit Fio",
"settings.readiness.item.fioPlugin.description":
"Automatické párování bankovních transakcí je připravené, když existuje aktivní Fio plugin pro bankovní platby.",
"settings.readiness.item.fioPlugin.title": "Fio synchronizace transakcí",
"settings.readiness.item.paymentMethods.action": "Spravovat platební účty",
"settings.readiness.item.paymentMethods.description":
"Povolte alespoň jeden způsob přijímání plateb v terminálu.",
"settings.readiness.item.paymentMethods.title": "Platební metody",
"settings.readiness.item.recoveryPhrase.action": "Otevřít bezpečnost",
"settings.readiness.item.recoveryPhrase.description":
"Aktivní účet má recovery phrase dostupnou pro zálohu.",
"settings.readiness.item.recoveryPhrase.title": "Recovery phrase",
"settings.readiness.item.sync.action": "Nastavit synchronizaci",
"settings.readiness.item.sync.description":
"Aktivní sync transport pomáhá zálohovat data terminálu mezi zařízeními.",
"settings.readiness.item.sync.title": "Synchronizace dat",
"settings.readiness.progress": "Hotovo {completed} z {total} položek",
"settings.readiness.status.completed": "Hotovo",
"settings.readiness.status.notCompleted": "Není hotovo",
"settings.readiness.summary.description":
"Použijte tento praktický checklist před přijímáním skutečných plateb.",
"settings.readiness.summary.title": "Checklist nastavení",
"settings.readiness.title": "Stav nastavení",
"settings.security": "BEZPEČNOST A SOUKROMÍ",
"settings.security.description": "Správa synchronizace a obnovy účtu",
"settings.security.title": "Bezpečnost a synchronizace",
Expand Down
34 changes: 34 additions & 0 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,40 @@ export const en = {
"settings.privacy.errorReporting.title": "Error reporting",
"settings.privacy.title": "Privacy",
"settings.privacyGroup": "PRIVACY",
"settings.readiness.description":
"Checklist for using Payky with real customers",
"settings.readiness.item.bankAccount.action": "Set up bank account",
"settings.readiness.item.bankAccount.description":
"Bank QR payments need an enabled account for the current fiat currency.",
"settings.readiness.item.bankAccount.title": "Bank account",
"settings.readiness.item.defaultPaymentMethod.action": "Choose default",
"settings.readiness.item.defaultPaymentMethod.description":
"Checkout should open with a payment method that is enabled now.",
"settings.readiness.item.defaultPaymentMethod.title":
"Default payment method",
"settings.readiness.item.fioPlugin.action": "Configure Fio",
"settings.readiness.item.fioPlugin.description":
"Automatic bank transaction matching is ready when an active Fio plugin exists for bank payments.",
"settings.readiness.item.fioPlugin.title": "Fio transaction sync",
"settings.readiness.item.paymentMethods.action": "Manage payment accounts",
"settings.readiness.item.paymentMethods.description":
"Enable at least one way to accept payments in the terminal.",
"settings.readiness.item.paymentMethods.title": "Payment methods",
"settings.readiness.item.recoveryPhrase.action": "Open security settings",
"settings.readiness.item.recoveryPhrase.description":
"The active account has a recovery phrase available for backup.",
"settings.readiness.item.recoveryPhrase.title": "Recovery phrase",
"settings.readiness.item.sync.action": "Configure sync",
"settings.readiness.item.sync.description":
"An active sync transport helps keep the terminal data backed up across devices.",
"settings.readiness.item.sync.title": "Data sync",
"settings.readiness.progress": "{completed} of {total} items complete",
"settings.readiness.status.completed": "Completed",
"settings.readiness.status.notCompleted": "Not completed",
"settings.readiness.summary.description":
"Use this practical checklist before accepting real payments.",
"settings.readiness.summary.title": "Setup checklist",
"settings.readiness.title": "Setup Status",
"settings.security": "SECURITY & PRIVACY",
"settings.security.description": "Manage sync transports and recovery access",
"settings.security.title": "Security & Sync",
Expand Down
35 changes: 35 additions & 0 deletions src/i18n/sk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,41 @@ export const sk = {
"settings.privacy.errorReporting.title": "Hlásenie chýb",
"settings.privacy.title": "Súkromie",
"settings.privacyGroup": "SÚKROMIE",
"settings.readiness.description":
"Checklist pre používanie Payky so skutočnými zákazníkmi",
"settings.readiness.item.bankAccount.action": "Nastaviť bankový účet",
"settings.readiness.item.bankAccount.description":
"Bankové QR platby potrebujú povolený účet pre aktuálnu fiat menu.",
"settings.readiness.item.bankAccount.title": "Bankový účet",
"settings.readiness.item.defaultPaymentMethod.action":
"Vybrať predvolenú metódu",
"settings.readiness.item.defaultPaymentMethod.description":
"Checkout sa má otvárať s platobnou metódou, ktorá je teraz povolená.",
"settings.readiness.item.defaultPaymentMethod.title":
"Predvolená platobná metóda",
"settings.readiness.item.fioPlugin.action": "Nastaviť Fio",
"settings.readiness.item.fioPlugin.description":
"Automatické párovanie bankových transakcií je pripravené, keď existuje aktívny Fio plugin pre bankové platby.",
"settings.readiness.item.fioPlugin.title": "Fio synchronizácia transakcií",
"settings.readiness.item.paymentMethods.action": "Spravovať platobné účty",
"settings.readiness.item.paymentMethods.description":
"Povoľte aspoň jeden spôsob prijímania platieb v termináli.",
"settings.readiness.item.paymentMethods.title": "Platobné metódy",
"settings.readiness.item.recoveryPhrase.action": "Otvoriť bezpečnosť",
"settings.readiness.item.recoveryPhrase.description":
"Aktívny účet má recovery phrase dostupnú pre zálohu.",
"settings.readiness.item.recoveryPhrase.title": "Recovery phrase",
"settings.readiness.item.sync.action": "Nastaviť synchronizáciu",
"settings.readiness.item.sync.description":
"Aktívny sync transport pomáha zálohovať dáta terminálu medzi zariadeniami.",
"settings.readiness.item.sync.title": "Synchronizácia dát",
"settings.readiness.progress": "Hotovo {completed} z {total} položiek",
"settings.readiness.status.completed": "Hotovo",
"settings.readiness.status.notCompleted": "Nie je hotovo",
"settings.readiness.summary.description":
"Použite tento praktický checklist pred prijímaním skutočných platieb.",
"settings.readiness.summary.title": "Checklist nastavenia",
"settings.readiness.title": "Stav nastavenia",
"settings.security": "BEZPEČNOSŤ A SÚKROMIE",
"settings.security.description": "Správa synchronizácie a obnovy účtu",
"settings.security.title": "Bezpečnosť a synchronizácia",
Expand Down
Loading
Loading