Function bodies 202 total
executeStateTransition function · typescript · L224-L310 (87 LOC)supabase/functions/stripe-webhooks-v312-integrated/index.ts
async function executeStateTransition(
supabase: any,
booking: any,
event: string,
stripeEvent: any
): Promise<TransitionResult> {
const currentState = booking.status;
console.log(`[State] Attempting transition: ${currentState} -> ${event}`);
// Definir transiciones válidas (simplificado)
const validTransitions: Record<string, Record<string, string>> = {
pending_payment: {
PAYMENT_SUCCEEDED: 'confirmed',
PAYMENT_FAILED: 'failed',
SETUP_SUCCEEDED: 'confirmed',
SETUP_FAILED: 'failed',
},
confirmed: {
HOLD_CREATED: 'hold_pending',
},
hold_pending: {
HOLD_CONFIRMED: 'hold_confirmed',
HOLD_FAILED: 'failed',
},
hold_confirmed: {
HOLD_CANCELLED: 'confirmed',
},
in_progress: {
HOLD_CAPTURED: 'cancelled',
},
};
const nextState = validTransitions[currentState]?.[event];
if (!nextState) {
return {
success: false,
from_state: currentState,
to_state: currentSsendNotificationForEvent function · typescript · L315-L364 (50 LOC)supabase/functions/stripe-webhooks-v312-integrated/index.ts
async function sendNotificationForEvent(
supabase: any,
booking: any,
event: string,
stripeEvent: any
): Promise<void> {
console.log(`[Notification] Preparing notification for event: ${event}`);
// Obtener datos del cliente
const customerEmail = booking.customer_email;
const customerName = booking.customer_name;
const customerPhone = booking.customer_phone;
if (!customerEmail && !customerPhone) {
console.warn('[Notification] No contact info for customer');
return;
}
// Preparar contexto para el template
const context = {
booking_id: booking.id,
confirmation_number: booking.confirmation_number,
route: booking.route_key,
pickup_datetime: booking.pickup_datetime,
pickup_location: booking.pickup_location,
dropoff_location: booking.dropoff_location,
vehicle_type: booking.vehicle_type,
price: formatPrice(booking.total_price_cents),
hold_amount: formatPrice(booking.hold_amount_cents),
};
// TODO: Implementar envío r‹ prevpage 5 / 5