Finance SDK

A Flutter plugin that provides Firebase-driven dynamic API orchestration using Firestore and Remote Config.

🚀 Features

  • Firebase Integration: Automatic initialization of Firestore and Remote Config
  • Dynamic API Configuration: Fetch API definitions from Firestore
  • Dynamic Enum Generation: Auto-generate enums from Firestore data
  • Caching Layer: Local caching with SharedPreferences for offline support
  • Comprehensive Logging: Built-in logging system for debugging
  • Error Handling: Robust error handling with structured responses

📦 Installation

Add this to your package's pubspec.yaml file:

dependencies:
  awn_finance_sdk: ^1.0.2

The plugin handles Firebase initialization internally, so you don't need to add firebase_core to your dependencies.

🔧 Quick Start

1. Configure Firebase for the Plugin

See FIREBASE_PLUGIN_SETUP.md for detailed instructions.

Important: Firebase is initialized internally by the plugin. Your app does NOT need to call Firebase.initializeApp().

2. Initialize the SDK

import 'package:awn_finance_sdk/finance_sdk.dart';

final financeSdk = FinanceSdk();

// Initialize the SDK (this fetches data from Firebase)
await financeSdk.initialize();

3. Send API Requests

// Send a request using an API key from Firestore
final response = await financeSdk.sendRequest(
  apiKey: 'GET_USER_DETAIL',
  requestBody: {
    'userId': '12345',
    'includeProfile': true,
  },
);

if (response.success) {
  print('Success: ${response.data}');
} else {
  print('Error: ${response.error}');
}

📖 See API User Guide for complete API reference with all endpoints and examples.

📚 Documentation

🗄️ Firebase Setup

The plugin requires Firebase to be configured in the plugin itself, not in your app.

Setup Guide: FIREBASE_PLUGIN_SETUP.md

Quick Setup Steps:

  1. Create Firebase Project with Firestore and Remote Config enabled
  2. Add Android App with package: com.mytm.finance.sdk.finance_sdk
  3. Add iOS App with bundle ID: com.mytm.finance.sdk.finance_sdk
  4. Place configuration files:
    • google-services.jsonandroid/google-services.json
    • GoogleService-Info.plistios/GoogleService-Info.plist
  5. Configure Firestore: Create api_definitions collection
  6. Configure Remote Config: Add baseUrl parameter

📱 Example App

The example app demonstrates all SDK features:

cd example
flutter run

🔄 How It Works

  1. Initialization: The SDK initializes Firebase services and fetches API definitions from Firestore

  2. Request Processing: When you call sendRequest():

    • SDK looks up the API definition by key
    • Retrieves the base URL from Remote Config
    • Constructs the final URL: $baseUrl/$service$endpoint
    • Merges request body with default parameters
    • Sends HTTP request with configured headers
    • Returns structured response
  3. Caching: All data is cached locally for offline support and faster access

💻 API Reference

FinanceSdk Class

initialize()

Initializes the Firebase-based API handling system. Must be called before using other methods.

sendRequest({required String apiKey, required Map<String, dynamic> requestBody})

Sends an API request using Firebase configuration.

Parameters:

  • apiKey: The API key identifier from Firestore
  • requestBody: The request body data to send

Returns: Future<ApiResponse>

getAvailableApiKeys()

Returns all available API keys from Firestore.

Returns: Future<Map<String, String>>

getAvailableServices()

Returns all available services from Firestore.

Returns: Future<Map<String, String>>

refreshData()

Refreshes data from Firebase (API definitions and base URL).

Returns: Future<void>

ApiResponse Class

Properties

  • success: bool - Whether the request was successful
  • data: dynamic - Response data (if successful)
  • error: String? - Error message (if failed)
  • statusCode: int? - HTTP status code

🛠️ Development

Running Tests

flutter test

Running Integration Tests

cd example
flutter test integration_test/

🔒 Security Considerations

Firebase Configuration

  • The plugin uses an embedded Firebase configuration to ensure all users access the same Firebase project
  • Firebase credentials are protected by ProGuard rules in Android release builds
  • Firebase Security Rules should be configured on the server side to protect your data

Best Practices

  • Store sensitive API keys securely in Firestore with proper Security Rules
  • Use Firebase App Check for additional security
  • Implement proper authentication in your backend APIs
  • Never commit Firebase configuration files to public repositories
  • Use environment-specific Firebase projects for development and production

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please follow these steps:

  1. Create your feature branch
  2. Commit your changes with clear messages
  3. Ensure all tests pass
  4. Submit your changes for review

📞 Support

For support, please contact the development team.