# Payment Plugin Setup Guide
## โ
Plugin Setup Complete!
Your Adyen payment plugin is now ready to use with token authentication from your main app.
## ๐ง How It Works
The plugin uses **Dio** with an **interceptor** that automatically adds your auth token to every API request.
### Architecture
```
Main App โ Token Provider โ Plugin (Dio + Interceptor) โ API with Token
```
## ๐ Usage in Your Main App
### 1. Add the Plugin to Your Main App's `pubspec.yaml`
```yaml
dependencies:
payment_plugin:
path: ../payment_plugin # Adjust path as needed
```
### 2. Initialize the AdyenRepository
```dart
import 'package:payment_plugin/payment_plugin.dart';
// Initialize with your token provider
final adyenRepo = AdyenRepository(
tokenProvider: () async {
// Get token from your auth service in main app
// This function is called every time the plugin makes an API call
return await yourAuthService.getToken();
},
baseUrl: 'https://your-api.com',
);
```
### 3. Use the Repository
```dart
// Create a payment session for checkout
final config = await adyenRepo.sessionCheckout(
'hotel123', // hotelCode
'booking456', // bookingId
false, // usePoints
);
// Add a new card
final cardConfig = await adyenRepo.fetchSessionForAddingCard();
// Get stored payment methods
final storedMethods = await adyenRepo.mockStoredPaymentData;
```
## ๐ Token Authentication Flow
1. **Main app** calls a payment method on `adyenRepo`
2. **Plugin** needs to make an API call
3. **Dio interceptor** calls your `tokenProvider()` function
4. **Main app** returns the current auth token
5. **Interceptor** adds `Authorization: Bearer {token}` header
6. **API request** is sent with authentication
### Benefits
โ
Token stays in your main app (never stored in plugin)
โ
Works with token refresh (always gets latest token)
โ
Automatic authentication on all requests
โ
Clean separation of concerns
## ๐ฆ Available API Methods
The plugin includes the following API endpoints:
- `getPaymentMethods()` - Get stored payment methods
- `createAdyenSession()` - Create session for booking payment
- `createAdyenSessionForCards()` - Create session for adding cards
- `listAvailablePaymentMethods()` - List available payment methods
- `storePaymentMethod()` - Store a new payment method
- `removePaymentMethod()` - Remove a payment method
- `submitPayment()` - Submit a payment
## ๐๏ธ Plugin Structure
```
payment_plugin/
โโโ lib/
โ โโโ adyen/
โ โ โโโ adyen_repository.dart # Main repository with business logic
โ โ โโโ api_client.dart # Retrofit API client
โ โ โโโ models/ # Adyen-specific models
โ โโโ data/
โ โ โโโ remote/
โ โ โโโ models/ # API response models
โ โโโ payment_plugin.dart # Main export file
โโโ android/ # Android-specific code
โโโ ios/ # iOS-specific code
โโโ example/ # Example usage app
```
## ๐งช Testing
Run the example app to test the plugin:
```bash
cd example
flutter run
```
## ๐ Development Workflow
When you make changes to models with `@JsonSerializable` or `@RestApi`:
```bash
# Regenerate code
flutter pub run build_runner build --delete-conflicting-outputs
# Or watch for changes
flutter pub run build_runner watch --delete-conflicting-outputs
```
## ๐ฑ AndroidManifest Configuration
The plugin already includes necessary permissions in:
`android/src/main/AndroidManifest.xml`
For Adyen-specific configuration, you may need to add activities or permissions to your **main app's** AndroidManifest.
## ๐ฏ Next Steps
1. โ
Plugin structure created
2. โ
Token authentication configured
3. โ
Code generation setup
4. โ
API client with Retrofit
5. ๐ Add plugin to your main app
6. ๐ Test with real API endpoints
7. ๐ Implement payment flows
## ๐ก Tips
- The `tokenProvider` function is called for **every API request**, so make sure it's efficient
- If you need to refresh tokens, do it in your main app's auth service, not in the plugin
- The plugin uses **Dio** which supports interceptors, retries, and more advanced features
- All API responses are wrapped in `ApiResponse<T>` for consistent error handling
## ๐ Key Files to Know
- **`lib/adyen/adyen_repository.dart`** - Your main entry point
- **`lib/adyen/api_client.dart`** - REST API definitions
- **`lib/payment_plugin.dart`** - Public API exports
- **`pubspec.yaml`** - Dependencies (Dio, Retrofit, Adyen SDK)
---
**Ready to integrate!** ๐
For questions or issues, check the example app in `example/lib/main.dart`.