How wl-online-payments-direct/plugin-magento-redirect-payments works
Overall Project Type and Purpose
• The project is a Magento module (plugin) that adds a payment solution using Worldline’s hosted and redirect capabilities.
• Its purpose is to integrate single “redirect payment” buttons and enhance Magento’s checkout functionality to communicate with external payment gateways.
• Key functionalities include building requests for hosted payments, handling payment configurations from the admin, and exposing REST endpoints for payment management.
Major Architectural Components
• Frontend Components:
• UI: Contains configuration providers (Ui/ConfigProvider.php, TokenUiComponentProvider.php) and JavaScript components that handle the redirection and dynamic behavior on the checkout page (located in view/frontend/web/js).
• Templates: HTML templates (view/frontend/web/template) and layouts (view/frontend/layout/checkout_index_index.xml) that integrate the payment method into Magento’s frontend.
• Backend Components:
• Blocks & Admin UI: Directories like Block/Adminhtml/System/Config provide GUI components for Magento’s admin panel, allowing configuration of payment methods and notifications.
• Observer & Plugin:
• Observer (e.g., Observer/PaymentMethodIsActive.php) to react to Magento events such as checking if a payment method is active.
• Plugin classes (under Plugin/Magento/Checkout) intercept and modify behaviors, particularly for the checkout layout and display logic.
• WebAPI Endpoints: WebApi folder exposes endpoints (e.g., CreatePaymentManagement) for managing payment processes and assigning specific payment data.
• Services:
• Service/CreateHostedCheckoutRequest contains builder classes to create payment requests for different payment types (card, mobile, redirect, SEPA Direct Debit, etc.).
• Service/HostedCheckout builds the complete hosted checkout request.
• Gateway: Contains configuration classes for integrating with the payment gateway and setting up necessary parameters.
• Vault: Manages secure storage of payment details using Magento’s vault system.
• Setup: Contains installation scripts and data patches (Setup/Patch/Data) that modify or migrate database settings when the module is installed or upgraded.
• Configuration/DI: etc/di.xml and other configuration files (system.xml, payment.xml, etc.) define dependency injections and module settings, ensuring that components are wired within Magento’s framework.
• Testing & Quality:
• Test/Integration: Extensive integration tests ensure proper payment flow behaviors, covering order placement, refunds, void operations, and configuration validations.
• .github/workflows configuration files indicate automated quality checks (coding standards, mess detectors).
Relationships and Data Flow
• The front end (checkout page) calls the UI components and uses JavaScript to capture customer actions. When a payment is initiated:
• The UI interacts with the Magento backend via WebAPIs.
• Plugins and Observers intercept relevant events and adjust the behavior (e.g., layout processing, payment activation).
• Service classes handle the business logic by building requests (including specific input data for various payment methods) and forwarding them to the Worldline API.
• The Gateway and configuration classes ensure that requests are properly formatted and that credentials/configurations are in place.
• The Vault and Setup components maintain and evolve the module’s state in the Magento ecosystem.
• Integration tests verify the end-to-end processing of payment requests.
Key Architectural Patterns and Technologies
• Modular Design: The module is separated into clearly defined domains (UI, service, gateway, web API, etc.), which follows the divide-and-conquer principle common in Magento extension design.
• Observer/Plugin Pattern: Employing Magento’s event-driven and interception (plugin) mechanisms to modify behaviors without core code changes.
• Dependency Injection: Extensive use of Magento’s DI configuration (etc/di.xml) for clean separation and testability.
• Integration Testing: A robust suite of integration tests to ensure that major workflows (from payment initiation to order processing) are covered.
• External SDK Integration: Integration with Worldline’s PHP SDK for processing transactions, reflected in service builders and dependency on the external library.
Final Advice
• Since the overall system integrates with an external payments provider, make sure that external interactions are clearly demarcated.