Les pages des commerçants (/inscription, /espace) sont copiées dans le site vitrine par « npm --prefix admin run build:espace » ; liens des e-mails, de Stripe et de l'app Pro mis à jour. ADMIN_URL n'est plus nécessaire. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.4 KiB
TypeScript
65 lines
2.4 KiB
TypeScript
import { Body, Controller, Get, HttpCode, Post } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { PickType } from '@nestjs/mapped-types';
|
|
import { Throttle } from '@nestjs/throttler';
|
|
import { BillingInterval, Plan } from '@prisma/client';
|
|
import { Equals, IsEnum, IsString, Length } from 'class-validator';
|
|
import { CreateStoreDto } from '../stores/dto/store.dto';
|
|
import { BillingService } from '../billing/billing.service';
|
|
import { publicCatalog } from '../billing/plans';
|
|
import { SignupService } from './signup.service';
|
|
|
|
class SignupDto extends PickType(CreateStoreDto, ['name', 'siret', 'addressLine', 'postalCode', 'city', 'contactName', 'contactEmail', 'contactPhone'] as const) {
|
|
@IsString() @Length(10, 128, { message: 'Mot de passe : 10 caractères minimum' })
|
|
password!: string;
|
|
|
|
@IsEnum(Plan)
|
|
plan!: Plan;
|
|
|
|
@IsEnum(BillingInterval)
|
|
interval!: BillingInterval;
|
|
|
|
/** Acceptation des CGV. */
|
|
@Equals(true, { message: 'Acceptez les conditions générales de vente' })
|
|
cgv!: boolean;
|
|
}
|
|
|
|
/** Inscription en ligne : renvoie l'adresse de paiement Stripe. */
|
|
@Controller('public/signup')
|
|
export class SignupController {
|
|
constructor(
|
|
private signup: SignupService,
|
|
private billing: BillingService,
|
|
private config: ConfigService,
|
|
) {}
|
|
|
|
/** Formules et prix affichés sur le formulaire d'inscription. */
|
|
@Get('plans')
|
|
plans() {
|
|
return publicCatalog();
|
|
}
|
|
|
|
@Post()
|
|
@HttpCode(200)
|
|
@Throttle({ default: { limit: 5, ttl: 10 * 60_000 } })
|
|
async start(@Body() dto: SignupDto) {
|
|
const { password, plan, interval, cgv: _cgv, ...data } = dto;
|
|
const pending = await this.signup.prepare(data, password, plan, interval);
|
|
const price = await this.billing.priceFor(plan, interval);
|
|
const espace = `${this.config.get('webUrl')}/espace`;
|
|
const session = await this.billing.stripe.checkout.sessions.create({
|
|
mode: 'subscription',
|
|
customer_email: pending.email,
|
|
line_items: [{ price: price.id, quantity: 1 }],
|
|
payment_method_types: ['card', 'sepa_debit'],
|
|
allow_promotion_codes: true,
|
|
locale: 'fr',
|
|
client_reference_id: pending.id,
|
|
subscription_data: { metadata: { signupId: pending.id } },
|
|
metadata: { signupId: pending.id },
|
|
success_url: `${espace}?bienvenue=1`,
|
|
cancel_url: `${this.config.get('webUrl')}/inscription?formule=${plan.toLowerCase()}&annule=1`,
|
|
});
|
|
return { url: session.url };
|
|
}
|
|
}
|