# phpviet/laravel-omnipay architecture

> Architecture diagram of the GitHub repository phpviet/laravel-omnipay, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/phpviet/laravel-omnipay
- Repository: https://github.com/phpviet/laravel-omnipay

## Overview

##### Main Components
- Service Provider: The OmnipayServiceProvider (located at src/OmnipayServiceProvider.php) registers the package’s service container bindings and integrates the functionality with Laravel.
- Configuration: The config directory (especially config/laravel-omnipay.php) holds the gateway configurations and options for each payment method.
- Facades Layer: Each payment gateway has its own facade. For example, under src/Facades there are separate directories and classes for MoMo, OnePay, VNPay, and VTCPay. These facades wrap the underlying logic and simplify usage via static calls.
- Middleware: There is a middleware (src/Middleware/CompletePurchaseMiddleware.php) which likely manages or intercepts purchase requests to handle tasks common to all gateways (for example, verifying responses or completing purchase logic).
- Documentation & Tests: The docs/ directory provides detailed instructions and examples for using each gateway. Tests under tests/ confirm that each facade and middleware behave as expected.

##### Relationships and Interactions
- When a Laravel application uses this package, it publishes the configuration file and registers the service through OmnipayServiceProvider.
- The configuration file defines gateway-specific credentials and options for each supported payment gateway.
- A developer calls a payment method (for example, MoMoAIO::purchase(...)) via the corresponding facade.
- The facade communicates with its respective gateway class (e.g., AllInOneGateway in src/Facades/MoMo/AllInOneGateway.php).
- The request and responses follow the pattern defined by the Omnipay library. If needed, the middleware can be invoked to handle post-purchase processing.
- Finally, tests simulate these interactions to ensure the flow is correct across all payment gateways.

##### Architectural Patterns and Design Principles
- The package leverages the Facade design pattern, which hides complex logic behind simple, easy-to-use static interfaces.
- It follows Laravel’s service provider pattern to integrate seamlessly with the Laravel ecosystem.
- It implements a configuration-driven design, where options per gateway are clearly separated in the configuration file.
- The project is modular; each gateway has its own directory and set of classes, which is beneficial for maintainability and extensibility.

##### Relevant Technologies and Frameworks
- Laravel (the integration with Laravel’s service container, middleware, and facade system)
- Omnipay (the underlying payment gateway abstraction library)
- PHP Unit (for testing via tests/ directory)
- Composer (for dependency management, as indicated by composer.json)

##### Elements
- Each component (Configuration, Service Provider, Facades for MoMo, OnePay, VNPay, VTCPay, Middleware, Omnipay Library) should be clearly labeled.
- Optionally, add legends or notes clarifying that tests and docs support the core functionality and are not part of runtime interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Laravel Application"
        App["\"Laravel Application\""]:::external
    end

    subgraph "Laravel Omnipay Package"
        Config["\"Configuration: laravel-omnipay.php\""]:::config
        Provider["\"OmnipayServiceProvider\""]:::provider
        Middleware["\"CompletePurchaseMiddleware\""]:::middleware

        subgraph "Facades"
            subgraph "MoMo"
                MoMoAIO["\"MoMo AllInOneGateway\""]:::facade
                MoMoApp["\"MoMo AppInAppGateway\""]:::facade
                MoMoPOS["\"MoMo POSGateway\""]:::facade
                MoMoQR["\"MoMo QRCodeGateway\""]:::facade
            end
            subgraph "OnePay"
                OnePayDomestic["\"OnePay DomesticGateway\""]:::facade
                OnePayInternational["\"OnePay InternationalGateway\""]:::facade
            end
            VNPay["\"VNPay Gateway\""]:::facade
            VTCPay["\"VTCPay Gateway\""]:::facade
        end

        OmnipayLib["\"Omnipay Library\""]:::external
        Docs["\"Documentation\""]:::docs
        Tests["\"Testing\""]:::tests
    end

    %% Data Flow
    App -->|"bootstraps"| Provider
    Provider -->|"loads"| Config
    Provider -->|"registers"| MoMoAIO
    Provider -->|"registers"| MoMoApp
    Provider -->|"registers"| MoMoPOS
    Provider -->|"registers"| MoMoQR
    Provider -->|"registers"| OnePayDomestic
    Provider -->|"registers"| OnePayInternational
    Provider -->|"registers"| VNPay
    Provider -->|"registers"| VTCPay
    MoMoAIO ---|"uses"| OmnipayLib
    MoMoApp ---|"uses"| OmnipayLib
    MoMoPOS ---|"uses"| OmnipayLib
    MoMoQR ---|"uses"| OmnipayLib
    OnePayDomestic ---|"uses"| OmnipayLib
    OnePayInternational ---|"uses"| OmnipayLib
    VNPay ---|"uses"| OmnipayLib
    VTCPay ---|"uses"| OmnipayLib
    %% Middleware involvement in purchase process
    App -->|"initiates purchase"| Middleware
    Middleware ---|"processes via"| OmnipayLib

    %% Supporting components (Documentation & Testing)
    Provider ---|"guided by"| Docs
    Provider ---|"verified by"| Tests

    %% Click Events
    click Provider "https://github.com/phpviet/laravel-omnipay/blob/master/src/OmnipayServiceProvider.php"
    click Config "https://github.com/phpviet/laravel-omnipay/blob/master/config/laravel-omnipay.php"
    click MoMoAIO "https://github.com/phpviet/laravel-omnipay/blob/master/src/Facades/MoMo/AllInOneGateway.php"
    click MoMoApp "https://github.com/phpviet/laravel-omnipay/blob/master/src/Facades/MoMo/AppInAppGateway.php"
    click MoMoPOS "https://github.com/phpviet/laravel-omnipay/blob/master/src/Facades/MoMo/POSGateway.php"
    click MoMoQR "https://github.com/phpviet/laravel-omnipay/blob/master/src/Facades/MoMo/QRCodeGateway.php"
    click OnePayDomestic "https://github.com/phpviet/laravel-omnipay/blob/master/src/Facades/OnePay/DomesticGateway.php"
    click OnePayInternational "https://github.com/phpviet/laravel-omnipay/blob/master/src/Facades/OnePay/InternationalGateway.php"
    click VNPay "https://github.com/phpviet/laravel-omnipay/blob/master/src/Facades/VNPay/Gateway.php"
    click VTCPay "https://github.com/phpviet/laravel-omnipay/blob/master/src/Facades/VTCPay/Gateway.php"
    click Middleware "https://github.com/phpviet/laravel-omnipay/blob/master/src/Middleware/CompletePurchaseMiddleware.php"
    click Docs "https://github.com/phpviet/laravel-omnipay/tree/master/docs/"
    click Tests "https://github.com/phpviet/laravel-omnipay/tree/master/tests/"

    %% Styles
    classDef provider fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef config fill:#fff9c4,stroke:#f9a825,stroke-width:2px;
    classDef facade fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef middleware fill:#f0f4c3,stroke:#afb42b,stroke-width:2px;
    classDef external fill:#ffccbc,stroke:#d84315,stroke-width:2px;
    classDef docs fill:#e1bee7,stroke:#8e24aa,stroke-width:2px;
    classDef tests fill:#d7ccc8,stroke:#5d4037,stroke-width:2px;
```
