How phpviet/laravel-omnipay works
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.