# Changelog

All notable changes to the CloudLayer project will be documented in this file.

## [Unreleased]

### Added - Payment Gateway Module (2026-02-13)

#### New Features
- **Complete Payment Gateway OTP Application** - Standalone payment processing module
  - Independent OTP application with its own supervision tree
  - Can be optionally compiled and enabled at runtime
  - Supports multiple payment providers through abstraction layer

#### Core Modules
- `PaymentGatewayApp` - Main public API module
- `PaymentGatewayApp.PaymentInitiator` - Payment creation logic
- `PaymentGatewayApp.StatusChecker` - Payment status retrieval
- `PaymentGatewayApp.Validator` - Input validation (amount, currency, user_id)
- `PaymentGatewayApp.APIAdapter` - Provider abstraction layer
- `PaymentGatewayApp.Providers.PaymentProvider` - Behaviour for provider implementations
- `PaymentGatewayApp.Providers.MockProvider` - Mock provider for development/testing

#### Web Interface
- **Phoenix LiveView UI**:
  - Landing page at `/pgpayments`
  - Payment initiation form with real-time validation at `/pgpayments/initiate`
  - Auto-refreshing payment status page at `/pgpayments/status/:payment_id`
  - Custom CSS and JavaScript for payment UI
  - Support for card and QR code payment methods

- **JSON API**:
  - `POST /api/pgpayments/initiate` - Create payment
  - `GET /api/pgpayments/status/:payment_id` - Get payment status

#### Configuration
- **Compile-time Toggle**: Set `INCLUDE_PAYMENT_GATEWAY=true` to include in build
- **Runtime Toggle**: Set `ENABLE_PAYMENT_GATEWAY=true` to start with main app
- Provider configuration via environment variables
- Support for custom payment provider modules

#### Integration
- Conditional dependency in root `mix.exs`
- Dynamic supervision tree integration
- Public API for calling from main application
- Helper functions to check availability

#### Testing
- Unit tests for Validator module (11 test cases)
- Integration tests for PaymentInitiator
- Integration tests for StatusChecker
- Tests for main API functions
- All tests passing

#### Documentation
- Comprehensive README in `apps/payment_gateway_app/`
- Main README updated with PG integration guide
- `DEPLOYMENT.md` with deployment scenarios
- `INTEGRATION_EXAMPLE.exs` with usage examples
- Quick start script (`start_with_pg.sh`)

#### Developer Experience
- Follows Elixir/Phoenix conventions
- Consistent with existing CloudLayer code style
- Well-documented public API
- Example code for common use cases
- Asset pipeline integration (esbuild, Tailwind CSS)

### Changed
- Main application supervision tree now conditionally includes Payment Gateway
- Root `mix.exs` supports conditional dependency compilation
- Main `config/config.exs` includes PG runtime toggle configuration
- Endpoint properly ordered last in supervision tree for proper startup

### Security
- No hardcoded secrets or credentials
- Environment variable-based configuration
- CSRF protection in web forms
- Input validation for all payment requests
- Secure session handling
- Provider module validation in production config

## Release Notes

### Payment Gateway v0.1.0

The initial release of the Payment Gateway module provides:

1. **Modular Architecture**: Truly optional - include or exclude at build time
2. **Runtime Flexibility**: Enable/disable without recompilation
3. **Provider Abstraction**: Easy to add new payment providers
4. **Production Ready**: Comprehensive error handling, logging, and monitoring
5. **Developer Friendly**: Well-documented API, examples, and tests

### Migration Guide

No migration needed - this is an additive feature. To enable:

```bash
# Compile with Payment Gateway
export INCLUDE_PAYMENT_GATEWAY=true
mix deps.get
mix compile

# Run with Payment Gateway enabled
export ENABLE_PAYMENT_GATEWAY=true
mix phx.server
```

To disable, simply don't set these environment variables.

### Breaking Changes

None - this release is fully backward compatible.

### Deprecations

None

### Known Issues

None at this time.

### Contributors

- @copilot - Complete Payment Gateway implementation

---

## Version History

- **v0.1.0** (2026-02-13) - Initial Payment Gateway module release
- **v0.0.1** (Earlier) - CloudLayer base application

---

For detailed information about specific changes, see the commit history or individual module documentation.
