How threepoles-sa/laravel-myfatoorah works
Project type and purpose
• This is a Laravel package (open-source tool) named “laravel-myfatoorah” that wraps the MyFatoorah payment API to simplify invoice creation, payment status checks, refunds, and token/mode configuration.
• It is not a standalone application—it plugs into any Laravel app via Composer and auto-discovery.
File structure
• Top-level:
• composer.json (package metadata, dependencies, auto-discovery)
• README.md / LICENSE.md
• src/
• MyFatoorahServiceProvider.php (registers services & publishes config)
• Facades/MyFatoorah.php (Laravel Facade for static access)
• MyFatoorah.php (main entry point, resolves to underlying service)
• Services/Service.php (base HTTP client logic)
• src/config/myfatoorah.php (configuration template for mode, token)
Additional README insights
• Usage pattern:
• Laravel auto-discovery loads the ServiceProvider.
• Config is published to the host app’s config/myfatoorah.php.
• Users call the Facade in Controllers to create invoices, handle callbacks, errors, refunds.
• No database or internal persistence—stateless HTTP calls to external API.
a. Main components
• Laravel Host Application
• Package ServiceProvider (bootstraps config & binds services)
• Laravel Facade (MyFatoorah)
• Core MyFatoorah Service class & HTTP client
• External MyFatoorah REST API
• Host App Controllers (calling the Facade)
• Host App Config (.env + published config file)
b. Relationships & interactions
1. At startup: Laravel auto-discovers ServiceProvider → merges/publishes config.
2. Controller invokes Facade::createInvoice() → Facade resolves to MyFatoorah service.
3. MyFatoorah service constructs HTTP request using credentials from config → sends to External MyFatoorah API.
4. Gets API response → returns to Controller → user redirect or JSON response.
5. Callback endpoint: Controller uses Facade::payment($id) → queries API.
6. Refund: Facade::refundInvoice($data) → HTTP call to API.
c. Architectural patterns & principles
• Service Provider / IoC Container binding
• Facade pattern for simple static interface
• Separation of concerns: Controllers handle HTTP, Facade/service handles API logic
• Configuration-driven behavior (modes, tokens)
• Stateless HTTP integration (no DB)
d. Key technologies & libraries
• PHP (>=7.x), Composer
• Laravel (6.x–9.x) Service Container & Facades
• Guzzle or HTTP client (in Service.php)
• MyFatoorah REST API
Elements
• Clear labels:
• “User Browser” → “Laravel Routes” → “Controller”
• “MyFatoorah Facade” → “MyFatoorah Service” → “MyFatoorah REST API”
• “Config/myfatoorah.php” & “.env”
• Request flow from user to external API and back
• Binding flow at app startup (ServiceProvider → IoC)
• Package components (Facade, ServiceProvider, Service class, config) in another
• External system (MyFatoorah API) in a distinct style
Detail
• Config ingestion from .env → published config → service provider.
• API interactions (create invoice, payment query, refund).