noorani-mm/laravel-saman-payment-gateway
Composer 安装命令:
composer require noorani-mm/laravel-saman-payment-gateway
包简介
Laravel package for Saman (SEP) payment gateway
README 文档
README
Laravel package for integrating Saman (SEP / Shaparak) payment gateway.
This package provides a clean, DTO-based, and IDE-friendly API for:
- Creating payment tokens
- Redirecting users to the payment page
- Verifying transactions via callback
Features
- ✅ Laravel 10 & 11 compatible
- ✅ DTO-based request & response models
- ✅ Facade support with full IDE autocomplete
- ✅ Configurable via config file &
.env - ✅ No external dependencies beyond Laravel components
- ✅ Clean service-based architecture
Installation
Install the package via Composer:
composer require noorani-mm/laravel-saman-payment-gateway
Publish Configuration
Publish the config file:
php artisan vendor:publish --tag=saman-config
This will create:
config/saman-gateway.php
Configuration
Set the following values in your .env file:
SAMAN_TERMINAL_ID=XXXXXXXX SAMAN_REDIRECT_URL=https://your-site.com/payment/callback SAMAN_TIMEOUT=30
Example config/saman-gateway.php:
return [ 'TerminalId' => env('SAMAN_TERMINAL_ID'), 'RedirectURL' => env('SAMAN_REDIRECT_URL'), 'Timeout' => env('SAMAN_TIMEOUT', 30), ];
Usage
Import Facade
use NooraniMm\SamanGateway\Facades\Saman;
1️⃣ Create Payment Token
Create a payment token using a DTO:
use NooraniMm\SamanGateway\DTO\Requests\CreatePaymentTokenRequestDTO; $dto = new CreatePaymentTokenRequestDTO( Amount: 100000, ResNum: 'ORDER-123' ); $response = Saman::createPaymentToken($dto);
2️⃣ Redirect User to Payment Page
Auto redirect (HTML form auto-submit)
Saman::redirectToPayment($response);
Manual handling (JS / frontend rendering)
$data = Saman::redirectToPayment($response, false); /* $data = [ 'token' => '...', 'url' => 'https://sep.shaparak.ir/OnlinePG/OnlinePG', 'method' => 'post', ]; */
3️⃣ Verify Payment (Callback)
In your callback controller:
use Illuminate\Http\Request; use NooraniMm\SamanGateway\Facades\Saman; public function callback(Request $request) { $result = Saman::verify($request); if ($result->isSuccessful()) { // Payment successful } else { // Payment failed } }
The callback data is mapped into a PaymentCallbackResponseDTO.
DTO Architecture
Requests
DTO/Requests/
├── CreatePaymentTokenRequestDTO
Responses
DTO/Responses/
├── CreatePaymentTokenResponseDTO
├── PaymentCallbackResponseDTO
Each DTO explicitly defines:
- Required fields
- Optional fields
- Exact data types
- IDE-friendly documentation
Facade Methods (IDE Autocomplete)
The Saman facade exposes the following methods:
Saman::createPaymentToken(CreatePaymentTokenRequestDTO $DTO); Saman::redirectToPayment( CreatePaymentTokenResponseDTO $DTO, bool $autoRedirect = true ); Saman::verify(Request $request);
All methods are documented via @method annotations for full IDE support.
Architecture Overview
Facade (Saman)
↓
Service (SamanPaymentGateway)
↓
DTOs (Request / Response)
↓
Saman (SEP) API
- Facade: simple static API
- Service: core business logic
- DTOs: explicit data contracts
- Config: environment-driven
Error Handling
- Network or HTTP errors throw
Exception - Gateway errors are returned inside response DTOs
- Verification failure is determined via gateway response codes
Requirements
- PHP ^8.1
- Laravel 10 or 11
License
MIT License © Mohammad Mahdi Noorani
noorani-mm/laravel-saman-payment-gateway 适用场景与选型建议
noorani-mm/laravel-saman-payment-gateway 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 12 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 noorani-mm/laravel-saman-payment-gateway 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 noorani-mm/laravel-saman-payment-gateway 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-22