How shetabit/payment works
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: PaymentServiceProvider.php Payment service provider · Payment.php Payment facade · InvoicePurchasedEvent.php Invoice purchased event · InvoiceVerifiedEvent.php Invoice verified event
Components 14
Laravel package
- Composer package · Declares Laravel and Multipay dependencies.
composer.json - Payment service provider · Registers container bindings, aliases, and publishable assets.
src/Provider/PaymentServiceProvider.php - Payment facade · Exposes purchase, pay, and verify operations.
src/Facade/Payment.php - Multipay manager · Resolves configured drivers and implements invoice mechanics.
- Redirect form · Renders the gateway redirect response and can be overridden.
resources/views/redirectForm.blade.php - Invoice purchased event
src/Events/InvoicePurchasedEvent.php - Invoice verified event
src/Events/InvoiceVerifiedEvent.php
Host application
- Multipay invoice · Carries amount and payment details.
- Published payment config · Supplies credentials, callbacks, default driver, and driver map.
- Host transaction record · Stores the transaction ID for callback verification.
- Host callback endpoint · Supplies persisted transaction data to verification.
- Order fulfillment listeners · Performs idempotent payment-state updates and fulfillment.
External services
- Selected gateway driver · Encapsulates provider purchase, redirect, and verification protocols.
- Payment provider API · Processes customer payment and sends the callback redirect.
Connections 17
- 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