# visal-98/laravel-phonepe architecture

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

- Interactive diagram: https://gitdiagram.com/visal-98/laravel-phonepe
- Repository: https://github.com/visal-98/laravel-phonepe

## Overview

##### Project Type and Purpose
- This is an open-source Laravel package (composer library) named “laravel-phonepe” that integrates the PhonePe Standard Checkout API into any Laravel 10+ application.
- Its goal is to provide a reusable interface (via a ServiceProvider and Facade) to initiate payments, handle callbacks, and render success/failure views.

##### File Structure Analysis
- Top-level files: composer.json (package config), LICENSE, README.md
- routes/web.php: the package’s HTTP routes (callback endpoints)
- src/
- PhonePeServiceProvider.php: registers configs, routes, views, and the Facade
- Facades/PhonePe.php: Laravel Facade pattern to expose a fluent API
- PhonePe.php: core service class that wraps HTTP calls to PhonePe
- Http/Controllers/PhonePeRedirectController.php: handles redirect callbacks from PhonePe
- config/phonepe.php: configuration template for merchant keys, environment, callback URLs
- views/success.blade.php & failure.blade.php: Blade templates rendered after callback

##### Key Components
a. Host Application (Laravel App)
- Includes your app’s controllers, middleware, and Blade layout that call the PhonePe Facade.
b. Package Service Layer
- PhonePeServiceProvider (bootstraps everything)
- PhonePe Facade (Facade pattern façade class)
- PhonePe Core Class (implements initPayment(), fetchStatus(), etc.)
c. Routes & Controllers
- routes/web.php → PhonePeRedirectController (success & failure callbacks)
d. Configuration
- config/phonepe.php (merchant credentials, endpoints)
e. Views
- success.blade.php & failure.blade.php
f. External Endpoint
- PhonePe Standard Checkout API (Payment initiation & verification)

##### Interactions and Data Flow
1. User clicks “Pay with PhonePe” in the Host App →
2. Host App invokes PhonePe Facade →
3. Facade delegates to PhonePe Core →
4. Core builds request (using config values) →
5. Core issues HTTP call to PhonePe API →
6. PhonePe redirects user to callback URL (defined in routes/web.php) →
7. PhonePeRedirectController processes success or failure →
8. Controller renders appropriate Blade view

##### Architectural Patterns & Design Principles
- Facade Pattern: exposes a simple static interface to the core service.
- Service Provider: uses Laravel’s inversion of control to register bindings, publish configs, routes, and views.
- MVC for callbacks: routes → controller → view.
- Separation of concerns: config loader, HTTP client wrapper, controller, and views are modular.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Host Application"
        HostApp["Host App\n(Controllers, Middleware, Blade Layout)"]
    end

    subgraph "Laravel Integration"
        SP["ServiceProvider"]:::laravel
        Facade["Facade\nPhonePe"]:::laravel
    end

    subgraph "Business Logic"
        Core["PhonePe Core"]:::business
    end

    Config["Config\nphonepe.php"]:::config
    Routes["Routes\nweb.php"]:::routes
    Controller["PhonePeRedirectController"]:::routes

    subgraph "Views"
        Success["success.blade.php"]:::view
        Failure["failure.blade.php"]:::view
    end

    External["PhonePe API"]:::external

    subgraph "Package Metadata"
        composer["composer.json"]:::meta
        readme["README.md"]:::meta
        license["LICENSE"]:::meta
    end

    HostApp -->|"calls Facade"| Facade
    Facade -->|"delegates to"| Core
    Core -->|"uses config"| Config
    Core -->|"POST /standard/v1/pay"| External
    External -->|"callback/success"| Routes
    Routes -->|"invoke"| Controller
    Controller -->|"renders success"| Success
    Controller -->|"renders failure"| Failure
    Success -->|"display"| HostApp

    SP -->|"registers routes"| Routes
    SP -->|"publishes config"| Config
    SP -->|"publishes views"| Success
    SP -->|"publishes views"| Failure
    SP -->|"binds facade"| Facade
    SP -->|"binds core"| Core

    composer --> SP
    readme --> SP
    license --> SP

    click SP "https://github.com/visal-98/laravel-phonepe/blob/main/src/PhonePeServiceProvider.php"
    click Facade "https://github.com/visal-98/laravel-phonepe/blob/main/src/Facades/PhonePe.php"
    click Core "https://github.com/visal-98/laravel-phonepe/blob/main/src/PhonePe.php"
    click Routes "https://github.com/visal-98/laravel-phonepe/blob/main/routes/web.php"
    click Controller "https://github.com/visal-98/laravel-phonepe/blob/main/src/Http/Controllers/PhonePeRedirectController.php"
    click Config "https://github.com/visal-98/laravel-phonepe/blob/main/src/config/phonepe.php"
    click Success "https://github.com/visal-98/laravel-phonepe/blob/main/src/views/success.blade.php"
    click Failure "https://github.com/visal-98/laravel-phonepe/blob/main/src/views/failure.blade.php"
    click composer "https://github.com/visal-98/laravel-phonepe/blob/main/composer.json"
    click readme "https://github.com/visal-98/laravel-phonepe/blob/main/README.md"
    click license "https://github.com/visal-98/laravel-phonepe/tree/main/LICENSE"

    classDef laravel fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef business fill:#90EE90,stroke:#333,stroke-width:1px
    classDef routes fill:#FFA500,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef view fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef external fill:#FF6347,stroke:#333,stroke-width:1px
    classDef meta fill:#E0E0E0,stroke:#333,stroke-width:1px
```
