From 6506055ae3a28b5e182926e120a760eb94503871 Mon Sep 17 00:00:00 2001 From: Tony Averty Date: Mon, 12 Oct 2026 16:10:56 +0200 Subject: [PATCH] =?UTF-8?q?Num=C3=A9ro=20de=20carte=20plus=20court=20(MEP?= =?UTF-8?q?=20+=208=20caract=C3=A8res),=20affich=C3=A9=20sur=20les=20carte?= =?UTF-8?q?s=20Apple=20Wallet=20et=20Google=20Wallet=20;=20compte=20de=20d?= =?UTF-8?q?=C3=A9monstration=20App=20Review=20(SQL)=20;=20correction=20de?= =?UTF-8?q?=20la=20saisie=20manuelle=20(le=20=C2=AB=20S=20=C2=BB=20=C3=A9t?= =?UTF-8?q?ait=20supprim=C3=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- .../2026-10-12-compte-demo-apple.sql | 56 +++++++++++++++++++ backend/src/enrollment/enrollment.service.ts | 12 +++- backend/src/wallet/apple-pass.service.ts | 7 ++- backend/src/wallet/google-wallet.service.ts | 3 +- backend/src/wallet/wallet.types.ts | 4 +- pro/app/scan.tsx | 6 +- 6 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 backend/prisma/manual-migrations/2026-10-12-compte-demo-apple.sql diff --git a/backend/prisma/manual-migrations/2026-10-12-compte-demo-apple.sql b/backend/prisma/manual-migrations/2026-10-12-compte-demo-apple.sql new file mode 100644 index 0000000..5c42939 --- /dev/null +++ b/backend/prisma/manual-migrations/2026-10-12-compte-demo-apple.sql @@ -0,0 +1,56 @@ +-- Compte de démonstration pour App Review (Apple) — à exécuter UNE fois dans phpMyAdmin +-- sur la base monespacepro. Magasin « Café Démo » actif d'emblée, formule Pro, sans Stripe, +-- abonnement valable 3 mois (aucune tâche ne le coupe automatiquement à l'échéance : voir la note en bas). +-- Connexion app : demo.apple@gmail.com (mot de passe = celui du hachage argon2 ci-dessous). + +START TRANSACTION; + +SET @store := 'demoapplestore000000001'; +SET @design := 'demoapplecard0000000001'; +SET @cust := 'demoapplecust0000000001'; +SET @now := UTC_TIMESTAMP(3); + +INSERT INTO `Store` + (`id`, `slug`, `name`, `addressLine`, `postalCode`, `city`, `siret`, `contactName`, `contactEmail`, `contactPhone`, + `status`, `billingSuspended`, `maxAmountCents`, `minScanIntervalSec`, `createdAt`, `updatedAt`) +VALUES + (@store, 'cafe-demo-a9k2', 'Café Démo', '1 rue de la Démo', '35000', 'Rennes', '35600000000048', 'Tony Averty', + 'demo.apple@gmail.com', '0612345678', 'ACTIVE', false, 50000, 300, @now, @now); + +INSERT INTO `Subscription` + (`id`, `storeId`, `status`, `plan`, `interval`, `legacyPrice`, `cancelAtPeriodEnd`, `currentPeriodEnd`, `updatedAt`) +VALUES + ('demoapplesub00000000001', @store, 'ACTIVE', 'PRO', 'MONTH', false, false, DATE_ADD(@now, INTERVAL 3 MONTH), @now); + +INSERT INTO `CardDesign` + (`id`, `storeId`, `programName`, `backgroundColor`, `foregroundColor`, `labelColor`, `pointsMode`, `pointsPerEuro`, `updatedAt`) +VALUES + (@design, @store, 'Carte Café Démo', '#0E7A66', '#FFFFFF', '#D1D5DB', 'STAMP', 1.00, @now); + +INSERT INTO `Reward` (`id`, `cardDesignId`, `label`, `cost`, `active`) +VALUES ('demoapplerew0000000001', @design, 'Un café offert', 10, true); + +INSERT INTO `StaffUser` + (`id`, `storeId`, `email`, `displayName`, `passwordHash`, `role`, `active`, `tokenVersion`, `createdAt`) +VALUES + ('demoapplestaff00000001', @store, 'demo.apple@gmail.com', 'Tony Averty', + '$argon2id$v=19$m=65536,t=3,p=4$1ooFWhMtIbYvzipnM++uMw$4gTPLEz9tCb8Qt+GWPGg3Bj9vnEGLstX5drwgrrnqRA', + 'MANAGER', true, 0, @now); + +-- Client de démonstration (à chercher par son prénom « Camille » ou par le numéro de carte ci-dessous) +INSERT INTO `Customer` (`id`, `firstName`, `email`, `consentAt`, `createdAt`) +VALUES (@cust, 'Camille', 'camille.demo@example.com', @now, @now); + +INSERT INTO `LoyaltyCard` + (`id`, `storeId`, `customerId`, `serial`, `authToken`, `accessKey`, `balance`, `passUpdatedAt`, `createdAt`, `updatedAt`) +VALUES + ('demoapplecardc00000001', @store, @cust, 'MEPK7M2QX9R', + REPLACE(UUID(), '-', ''), CONCAT(REPLACE(UUID(), '-', ''), REPLACE(UUID(), '-', '')), 0, @now, @now, @now); + +COMMIT; + +-- Numéro de carte à reporter dans les remarques de vérification Apple : MEP K7M2 QX9R +-- (le contenu du QR est le numéro de série « MEPK7M2QX9R »). +-- +-- À l'échéance des 3 mois, couper le compte à la main : +-- UPDATE `Store` SET `status` = 'CLOSED' WHERE `id` = 'demoapplestore000000001'; diff --git a/backend/src/enrollment/enrollment.service.ts b/backend/src/enrollment/enrollment.service.ts index 372b497..c45cabf 100644 --- a/backend/src/enrollment/enrollment.service.ts +++ b/backend/src/enrollment/enrollment.service.ts @@ -13,11 +13,19 @@ import { referralLink, referralOffered } from '../wallet/wallet.types'; /** Alphabet sans caractères ambigus : le numéro peut être lu à voix haute au comptoir. */ const SERIAL_ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; +/** Numéro court (« MEP » + 8 caractères) : il n'a de sens que dans le magasin qui scanne la carte. */ function randomSerial() { - const bytes = randomBytes(16); + const bytes = randomBytes(8); return 'MEP' + [...bytes].map((b) => SERIAL_ALPHABET[b % SERIAL_ALPHABET.length]).join(''); } +async function uniqueSerial(prisma: PrismaService) { + for (;;) { + const serial = randomSerial(); + if (!(await prisma.loyaltyCard.findUnique({ where: { serial }, select: { id: true } }))) return serial; + } +} + const token = () => randomBytes(24).toString('base64url'); /** « tony.prive@gmail.com » → « t•••@g•••.com » */ @@ -67,7 +75,7 @@ export class EnrollmentService { const card = await this.prisma.loyaltyCard.create({ data: { ...(referrer && { referredBy: { connect: { id: referrer.id } } }), - serial: randomSerial(), + serial: await uniqueSerial(this.prisma), authToken: token(), accessKey: token(), store: { connect: { id: store.id } }, diff --git a/backend/src/wallet/apple-pass.service.ts b/backend/src/wallet/apple-pass.service.ts index a113d87..be928a5 100644 --- a/backend/src/wallet/apple-pass.service.ts +++ b/backend/src/wallet/apple-pass.service.ts @@ -83,9 +83,10 @@ export class ApplePassService { ], // Face avant : la prochaine récompense. Pas de message de notification ici : quand deux champs // à message changent ensemble (solde + récompense), l'iPhone affiche « Carte de fidélité modifiée ». - ...(nextReward && { - auxiliaryFields: [{ key: 'next-reward', label: 'PROCHAINE RÉCOMPENSE', value: nextReward }], - }), + auxiliaryFields: [ + ...(nextReward ? [{ key: 'next-reward', label: 'PROCHAINE RÉCOMPENSE', value: nextReward }] : []), + { key: 'number', label: 'N° DE CARTE', value: readableSerial(card.serial), textAlignment: 'PKTextAlignmentRight' }, + ], backFields: [ // Toujours présent : quand sa valeur change (nouvelle campagne), l'iPhone affiche le message sur l'écran verrouillé. { key: 'news', label: newsLabels(card.store).label, value: newsText(card) ?? newsLabels(card.store).empty, changeMessage: '%@' }, diff --git a/backend/src/wallet/google-wallet.service.ts b/backend/src/wallet/google-wallet.service.ts index 4eb5b98..ff73715 100644 --- a/backend/src/wallet/google-wallet.service.ts +++ b/backend/src/wallet/google-wallet.service.ts @@ -131,12 +131,13 @@ export class GoogleWalletService { id: this.objectId(card.serial), classId: this.classId(card.storeId), state: 'ACTIVE', - accountId: card.serial, + accountId: readableSerial(card.serial), accountName: card.customer.firstName, loyaltyPoints: { label: unitLabel(card), balance: { int: card.balance } }, barcode: { type: 'QR_CODE', value: card.serial, alternateText: readableSerial(card.serial) }, textModulesData: [ ...(next ? [{ id: 'next_reward', header: 'Prochaine récompense', body: next }] : []), + { id: 'card_number', header: 'Numéro de carte', body: readableSerial(card.serial) }, { id: 'rewards', header: 'Toutes les récompenses', body: rewardsText(card) }, ], linksModuleData: { diff --git a/backend/src/wallet/wallet.types.ts b/backend/src/wallet/wallet.types.ts index f0180a9..3efdd0b 100644 --- a/backend/src/wallet/wallet.types.ts +++ b/backend/src/wallet/wallet.types.ts @@ -141,7 +141,7 @@ export function referralLink(webUrl: string, card: CardWithContext) { return card.referralCode ? `${webUrl}/c/${card.store.slug}?parrain=${card.referralCode}` : null; } -/** Numéro de carte lisible sous le QR (« MEP ABCD EFGH JKLM NPQR ») : saisie manuelle au comptoir si le scan échoue. */ +/** Numéro de carte lisible (« MEP ABCD EFGH ») : saisie manuelle au comptoir si le scan échoue. Les anciennes cartes ont 16 caractères. */ export function readableSerial(serial: string) { - return serial.replace(/^(MEP)(.{4})(.{4})(.{4})(.{4})$/, '$1 $2 $3 $4 $5'); + return serial.replace(/^(MEP)((?:.{4})+)$/, (_, p: string, rest: string) => `${p} ${rest.match(/.{4}/g)!.join(' ')}`); } diff --git a/pro/app/scan.tsx b/pro/app/scan.tsx index 8ec5129..7627272 100644 --- a/pro/app/scan.tsx +++ b/pro/app/scan.tsx @@ -13,11 +13,11 @@ import { font, useColors } from '../src/theme'; import { Icon } from '../src/icons'; /** Les numéros de carte commencent par « MEP » (voir le back-end). */ -const SERIAL = /^MEP[A-Z2-9]{16}$/; +const SERIAL = /^MEP(?:[A-Z2-9]{8}|[A-Z2-9]{16})$/; const FRAME = 260; const DIM = 'rgba(0,0,0,0.55)'; /** Saisie manuelle : espaces et tirets ignorés (« MEP ABCD EFGH… » est affiché sous le QR de la carte). */ -const normalize = (v: string) => v.toUpperCase().replace(/[s-]/g, ''); +const normalize = (v: string) => v.toUpperCase().replace(/[\s-]/g, ''); /** Résultat de la recherche d'un client (e-mail masqué par le serveur). */ interface Found { @@ -101,7 +101,7 @@ export default function Scan() { style={{ borderWidth: 1, borderColor: c.border, borderRadius: 14, padding: 14, fontSize: 17, color: c.text, backgroundColor: c.bg, fontFamily: font.semibold }} /> {typedOk &&