# shetabit/payment architecture

> Architecture diagram of the GitHub repository shetabit/payment, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shetabit/payment
- Repository: https://github.com/shetabit/payment

## Overview

#### Purpose and Runtime
A PHP/Laravel 5.8+ package that integrates applications with configurable payment-gateway drivers. It is distributed through Composer and delegates gateway/invoice mechanics to the `shetabit/multipay` dependency; this repository supplies Laravel integration, presentation, and lifecycle events. Package metadata and dependencies are in `composer.json`.

#### Laravel Entry Points
Laravel discovers and boots the package through `src/Provider/PaymentServiceProvider.php`. The application-facing API is the facade `src/Facade/Payment.php`, used as `Payment::purchase(...)`, `pay()`, and `verify()`. Consumers construct invoices from Multipay, while this package resolves the configured payment manager/driver through Laravel’s container.

#### Provider and Configuration Boundary
`PaymentServiceProvider.php` is the package-to-framework boundary: it registers bindings/aliases and publishes vendor assets under the documented payment config and view tags. Host applications own gateway credentials, default driver selection, callback URLs, and driver-map extensions through published configuration; those files are not retained in this repository tree.

#### Payment Purchase Flow
An application creates a Multipay invoice with amount/details, then calls the Payment facade. The selected driver is resolved from configuration (or runtime `via`/`config` overrides), performs the external gateway purchase request, and yields a transaction ID. The host application must persist that ID in its own database; this package does not define persistence models or migrations. Successful purchase emits `src/Events/InvoicePurchasedEvent.php`.

#### Customer Redirect / Payment UI
After purchase, `pay()` produces the gateway redirect response. Redirect presentation is backed by the package Blade template `resources/views/redirectForm.blade.php`, which can be published and overridden by the host application. The customer then leaves the Laravel application to complete payment on the selected external bank/payment-provider service.

#### Callback Verification Flow
The provider redirects the customer to the configured callback URL. The host endpoint supplies the persisted transaction ID (and normally amount) through the facade’s verification flow. The driver calls the gateway verification API and either returns a receipt/reference ID or raises Multipay’s invalid-payment exception. Successful verification emits `src/Events/InvoiceVerifiedEvent.php`; application listeners are responsible for order fulfillment and idempotent payment-state updates.

#### Extensibility and External Services
Gateway implementations are selected by a configured driver map and may be added in the consuming Laravel application by extending Multipay’s driver abstraction. Each driver encapsulates provider-specific purchase, redirect, and verification protocols. Supported providers are external payment/bank APIs; no gateway driver source is present in this repository, reinforcing that Multipay is the core integration layer.

Main entry points: [`src/Provider/PaymentServiceProvider.php`](https://github.com/shetabit/payment/blob/master/src/Provider/PaymentServiceProvider.php) (Payment service provider), [`src/Facade/Payment.php`](https://github.com/shetabit/payment/blob/master/src/Facade/Payment.php) (Payment facade), [`src/Events/InvoicePurchasedEvent.php`](https://github.com/shetabit/payment/blob/master/src/Events/InvoicePurchasedEvent.php) (Invoice purchased event), [`src/Events/InvoiceVerifiedEvent.php`](https://github.com/shetabit/payment/blob/master/src/Events/InvoiceVerifiedEvent.php) (Invoice verified event)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_laravel["Laravel package"]
  node_composer["Composer package<br/>package metadata<br/>[composer.json]"]
  node_provider["Payment service provider<br/>Laravel provider"]
  node_facade["Payment facade<br/>application API<br/>[Payment.php]"]
  node_multipay{{"Multipay manager<br/>payment core dependency"}}
  node_redirect_view["Redirect form<br/>Blade view"]
  node_purchased_event(("Invoice purchased event<br/>Laravel event"))
  node_verified_event(("Invoice verified event<br/>Laravel event"))
end

subgraph group_host["Host application"]
  node_invoice["Multipay invoice<br/>payment request"]
  node_config["Published payment config<br/>host configuration"]
  node_transaction[("Host transaction record<br/>application persistence")]
  node_callback["Host callback endpoint<br/>Laravel endpoint"]
  node_fulfillment["Order fulfillment listeners<br/>application workflow"]
end

subgraph group_external["External services"]
  node_gateway_driver{{"Selected gateway driver<br/>Multipay driver"}}
  node_gateway["Payment provider API<br/>bank or gateway"]
end

node_composer -->|"installs"| node_provider
node_provider -->|"registers alias"| node_facade
node_provider -->|"publishes"| node_config
node_provider -->|"publishes"| node_redirect_view
node_facade -->|"resolves from container"| node_multipay
node_config -->|"selects driver and settings"| node_multipay
node_invoice -->|"purchase / pay / verify"| node_facade
node_multipay -->|"delegates payment flow"| node_gateway_driver
node_gateway_driver -->|"purchase and verify APIs"| node_gateway
node_gateway_driver -->|"produces redirect response"| node_redirect_view
node_multipay -->|"successful purchase"| node_purchased_event
node_purchased_event -->|"transaction ID persisted"| node_transaction
node_gateway -->|"customer callback redirect"| node_callback
node_callback -->|"loads transaction ID"| node_transaction
node_callback -->|"verify"| node_facade
node_multipay -->|"successful verification"| node_verified_event
node_verified_event -->|"triggers"| node_fulfillment

click node_composer "https://github.com/shetabit/payment/blob/master/composer.json"
click node_provider "https://github.com/shetabit/payment/blob/master/src/Provider/PaymentServiceProvider.php"
click node_facade "https://github.com/shetabit/payment/blob/master/src/Facade/Payment.php"
click node_redirect_view "https://github.com/shetabit/payment/blob/master/resources/views/redirectForm.blade.php"
click node_purchased_event "https://github.com/shetabit/payment/blob/master/src/Events/InvoicePurchasedEvent.php"
click node_verified_event "https://github.com/shetabit/payment/blob/master/src/Events/InvoiceVerifiedEvent.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_composer,node_provider,node_facade,node_multipay,node_redirect_view,node_purchased_event,node_verified_event toneBlue
class node_invoice,node_config,node_transaction,node_callback,node_fulfillment toneAmber
class node_gateway_driver,node_gateway toneMint
```

## Components

### Laravel package

- [Composer package](https://github.com/shetabit/payment/blob/master/composer.json): package metadata · Declares Laravel and Multipay dependencies. · `composer.json`
- [Payment service provider](https://github.com/shetabit/payment/blob/master/src/Provider/PaymentServiceProvider.php): Laravel provider · Registers container bindings, aliases, and publishable assets. · `src/Provider/PaymentServiceProvider.php`
- [Payment facade](https://github.com/shetabit/payment/blob/master/src/Facade/Payment.php): application API · Exposes purchase, pay, and verify operations. · `src/Facade/Payment.php`
- **Multipay manager**: payment core dependency · Resolves configured drivers and implements invoice mechanics.
- [Redirect form](https://github.com/shetabit/payment/blob/master/resources/views/redirectForm.blade.php): Blade view · Renders the gateway redirect response and can be overridden. · `resources/views/redirectForm.blade.php`
- [Invoice purchased event](https://github.com/shetabit/payment/blob/master/src/Events/InvoicePurchasedEvent.php): Laravel event · `src/Events/InvoicePurchasedEvent.php`
- [Invoice verified event](https://github.com/shetabit/payment/blob/master/src/Events/InvoiceVerifiedEvent.php): Laravel event · `src/Events/InvoiceVerifiedEvent.php`

### Host application

- **Multipay invoice**: payment request · Carries amount and payment details.
- **Published payment config**: host configuration · Supplies credentials, callbacks, default driver, and driver map.
- **Host transaction record**: application persistence · Stores the transaction ID for callback verification.
- **Host callback endpoint**: Laravel endpoint · Supplies persisted transaction data to verification.
- **Order fulfillment listeners**: application workflow · Performs idempotent payment-state updates and fulfillment.

### External services

- **Selected gateway driver**: Multipay driver · Encapsulates provider purchase, redirect, and verification protocols.
- **Payment provider API**: bank or gateway · Processes customer payment and sends the callback redirect.

## Connections

- Composer package → Payment service provider: installs
- Payment service provider → Payment facade: registers alias
- Payment service provider → Published payment config: publishes
- Payment service provider → Redirect form: publishes
- Payment facade → Multipay manager: resolves from container
- Published payment config → Multipay manager: selects driver and settings
- Multipay invoice → Payment facade: purchase / pay / verify
- Multipay manager → Selected gateway driver: delegates payment flow
- Selected gateway driver → Payment provider API: purchase and verify APIs
- Selected gateway driver → Redirect form: produces redirect response
- Multipay manager → Invoice purchased event: successful purchase
- Invoice purchased event → Host transaction record: transaction ID persisted
- Payment provider API → Host callback endpoint: customer callback redirect
- Host callback endpoint → Host transaction record: loads transaction ID
- Host callback endpoint → Payment facade: verify
- Multipay manager → Invoice verified event: successful verification
- Invoice verified event → Order fulfillment listeners: triggers
