Add subcription feature 4

This commit is contained in:
Urtzi Alfaro
2026-01-15 22:06:36 +01:00
parent b674708a4c
commit 483a9f64cd
10 changed files with 1209 additions and 1390 deletions

View File

@@ -31,6 +31,9 @@ export interface UserRegistration {
billing_cycle?: 'monthly' | 'yearly' | null; // Default: "monthly" - Billing cycle preference
payment_method_id?: string | null; // Stripe payment method ID
coupon_code?: string | null; // Promotional coupon code for discounts/trial extensions
// Payment setup data (passed to complete-registration after 3DS)
customer_id?: string | null; // Stripe customer ID from payment setup
trial_period_days?: number | null; // Trial period from coupon
// GDPR Consent fields
terms_accepted?: boolean; // Default: true - Accept terms of service
privacy_accepted?: boolean; // Default: true - Accept privacy policy
@@ -68,6 +71,7 @@ export interface RegistrationStartResponse {
plan_id?: string | null; // Plan ID
payment_method_id?: string | null; // Payment method ID
billing_cycle?: string | null; // Billing cycle
trial_period_days?: number | null; // Trial period from coupon (e.g., 90 for PILOT2025)
email?: string | null; // User email
state_id?: string | null; // Registration state ID for tracking
message?: string | null; // Message explaining what needs to be done

View File

@@ -264,7 +264,7 @@ export const PaymentStep: React.FC<PaymentStepProps> = ({
// Store payment method ID for use after 3DS completion
setPendingPaymentMethodId(paymentMethod.id);
// Update paymentSetup state with customer_id for redirect recovery
// Update paymentSetup state with customer_id and trial_period_days for redirect recovery
updateRegistrationState({
paymentSetup: {
success: false,
@@ -272,6 +272,7 @@ export const PaymentStep: React.FC<PaymentStepProps> = ({
subscriptionId: '',
paymentMethodId: paymentMethod.id,
planId: registrationState.subscription.planId,
trialPeriodDays: paymentSetupResult.trial_period_days ?? (registrationState.subscription.useTrial ? 90 : 0),
},
});
@@ -353,6 +354,7 @@ export const PaymentStep: React.FC<PaymentStepProps> = ({
: setupIntent.payment_method?.id || pendingPaymentMethodId;
// Complete registration with verified SetupIntent using React Query mutation
// Send coupon_code to backend for trial period calculation
const verificationResult = await completeRegistrationMutation.mutateAsync({
setup_intent_id: setupIntentId || '',
user_data: {
@@ -363,6 +365,9 @@ export const PaymentStep: React.FC<PaymentStepProps> = ({
billing_cycle: registrationState.subscription.billingInterval,
payment_method_id: confirmedPaymentMethodId || pendingPaymentMethodId,
coupon_code: registrationState.subscription.couponCode,
// Pass customer_id for reference
customer_id: registrationState.paymentSetup?.customerId || '',
// Remove trial_period_days - backend will calculate from coupon_code
},
});

View File

@@ -40,6 +40,7 @@ export type PaymentSetupData = {
paymentMethodId?: string;
planId?: string;
threedsCompleted?: boolean;
trialPeriodDays?: number; // Trial period from coupon (e.g., 90 for PILOT2025)
};
export type RegistrationState = {