# Expedia Rapid API Integration Setup Guide

## Overview

This guide explains how to configure the Expedia Rapid API integration for the B2B Flight Ticketing Platform.

## Prerequisites

1. Expedia Partner Solutions (EPS) account
2. Rapid API credentials (API Key and Shared Secret)
3. Access to Expedia Developer Portal: https://developers.expediagroup.com/

## Configuration Steps

### 1. Obtain Expedia API Credentials

1. Log in to the Expedia Developer Portal
2. Navigate to your application dashboard
3. Copy your **API Key** and **Shared Secret**
4. Note the appropriate base URL:
   - Test environment: `https://test.ean.com`
   - Production environment: `https://api.ean.com`

### 2. Configure Environment Variables

Add the following environment variables to your `.env` file:

```bash
# Expedia Rapid API Configuration
EXPEDIA_API_KEY=your_expedia_api_key_here
EXPEDIA_API_SECRET=your_expedia_shared_secret_here
EXPEDIA_API_BASE_URL=https://test.ean.com
```

**Important Security Notes:**
- Never commit your actual credentials to version control
- Store the shared secret securely in production (e.g., AWS Secrets Manager, HashiCorp Vault)
- Use different credentials for test and production environments

### 3. Verify Configuration

The configuration is automatically loaded by Spring Boot from `application.yml`:

```yaml
expedia:
  api:
    base-url: ${EXPEDIA_API_BASE_URL:https://test.ean.com}
    key: ${EXPEDIA_API_KEY:}
    secret: ${EXPEDIA_API_SECRET:}
```

### 4. Configuration Class

The `ExpediaConfig` class loads and validates the configuration:

```java
@Configuration
@ConfigurationProperties(prefix = "expedia.api")
public class ExpediaConfig {
    private String baseUrl;  // Expedia API base URL
    private String key;      // API key for authentication
    private String secret;   // Shared secret for signature generation
}
```

## Package Structure

The Expedia integration follows the same structure as the Amadeus integration:

```
src/main/java/com/flightticket/
├── client/
│   └── expedia/              # Expedia API client code
│       └── ExpediaConfig.java
└── dto/
    └── expedia/              # Expedia DTOs (requests/responses)
        └── package-info.java
```

## Next Steps

After configuration is complete, the following components will be implemented:

1. **Signature Generator** - SHA-512 authentication for API requests
2. **API Client** - HTTP client for Expedia Rapid API
3. **Link Cache** - HATEOAS link management
4. **Booking Service** - Three-step booking workflow (Shop → Price Check → Book)
5. **Usage Tracking** - API usage logging for billing

## Troubleshooting

### Missing Configuration Error

If you see an error like:
```
Field error in object 'expedia.api' on field 'key': rejected value [null]
```

**Solution:** Ensure all three environment variables are set in your `.env` file.

### Authentication Failures

If API requests fail with 401 Unauthorized:

1. Verify your API key is correct
2. Verify your shared secret is correct
3. Check that you're using the correct base URL for your environment
4. Ensure the signature generation is working correctly

## Requirements Satisfied

This configuration setup satisfies the following requirements:

- **Requirement 12.1**: Read Expedia API_Key from external configuration
- **Requirement 12.2**: Read Expedia Shared_Secret from external configuration (encrypted)
- **Requirement 12.3**: Read Expedia base URL from external configuration
- **Requirement 12.4**: Support different configurations for test and production environments
- **Requirement 12.5**: Log warning and fail gracefully when credentials are missing

## References

- [Expedia Developer Portal](https://developers.expediagroup.com/)
- [Rapid API Documentation](https://developers.expediagroup.com/docs/rapid/)
- [Authentication Guide](https://developers.expediagroup.com/docs/rapid/resources/reference/authentication)
