How visal-98/laravel-phonepe works
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.