Overview
The calendar integration connects virtual classes with Google Calendar, automatically creating events with Google Meet links when payments are approved. The system uses OAuth2 authentication and manages event creation, updates, and retrieval.Architecture
The calendar system consists of:- Google Calendar API - Event creation and management
- Google Meet - Video conferencing links
- OAuth2 Authentication - Secure API access
- Refresh Token Storage - Persistent authentication
Setup Requirements
Google Cloud Console Configuration
- Create a project in Google Cloud Console
- Enable the following APIs:
- Google Calendar API
- Google Meet API (if using conferencing)
- Create OAuth 2.0 credentials:
- Application type: Web application
- Authorized redirect URIs:
https://yourdomain.com/api/auth/callback/google
Environment Variables
The
CALENDAR_ID can be “primary” for the main calendar or a specific calendar ID found in Google Calendar settings.OAuth2 Authentication
Storing Refresh Tokens
The system stores refresh tokens in the database for persistent access:Managing Refresh Tokens
Calendar API Routes
Get Calendar Events (Public Read)
Retrieve upcoming events using API key authentication:Create Calendar Event (OAuth)
Create events with Google Meet links using OAuth2:Creating Google Calendar Events
Event Creation Function
Conference Data Version: The
conferenceDataVersion: 1 parameter is mandatory to generate Google Meet links. Without it, events will be created without conferencing details.Event Response Structure
Google Calendar returns a comprehensive event object:Linking Events to Virtual Classes
After creating a Google Calendar event, update the virtual class record:Finding Virtual Classes
Retrieve booking details by payment preference ID:Listing Calendar Events
Retrieve upcoming events for admin purposes:Time Zone Handling
The platform uses Argentina timezone for all events:Always use the
America/Argentina/Buenos_Aires timezone for consistency across the platform. Google Calendar API accepts timezone strings in the event creation request.Calendar Event Types
Authentication Flow
OAuth2 Setup
Service Account Alternative
For server-to-server authentication without user interaction:Service Account vs OAuth2: Service accounts are better for automated tasks, while OAuth2 is required when acting on behalf of specific users.
Best Practices
Event Management
- Use unique
requestIdfor conference data to prevent duplicates - Set
transparency: "opaque"to mark time as busy - Always specify timezone in start/end times
- Store
googleEventIdfor future updates or deletions
Authentication
- Store refresh tokens securely in database
- Implement token rotation for expired tokens
- Use service accounts for background tasks
- Never expose credentials in client-side code
Error Handling
- Handle API rate limits (implement exponential backoff)
- Catch and log authentication errors
- Validate timezone strings before API calls
- Implement retry logic for transient failures
Webhook Support
Google Calendar supports webhooks for event changes:Webhook implementation is optional but recommended for real-time synchronization of calendar changes.
API Reference
Get Upcoming Events
Create Calendar Event
Related Features
- Virtual Classes - Class booking and scheduling
- Payment System - Payment triggers calendar creation
- Learning Activities - Activities assigned after classes