rostam-sodagari/laravel-yekpay
Composer 安装命令:
composer require rostam-sodagari/laravel-yekpay
包简介
Laravel wrapper for YekPay payment API (request/start/verify).
README 文档
README
A clean, production-ready Laravel package for integrating with the YekPay payment gateway.
It wraps the full request → redirect → verify payment lifecycle using typed DTOs and PHP enums, with facade Laravel support.
Read Official Document
Features
- Full YekPay payment flow (Request / Start / Verify)
- Strong typing via DTOs and PHP 8.1+ enums
- Currency codes as enum (no magic numbers)
- Sandbox & production support
- Configurable endpoints and timeouts
- Testable architecture (Guzzle + Testbench)
- Laravel 10 / 11 compatible
Requirements
- PHP 8.1+
- Laravel 10.x or 11.x
Installation
Install via Composer:
composer require rostam-sodagari/laravel-yekpay
Publish the configuration file:
php artisan vendor:publish --tag=yekpay-config
Configuration
Set your credentials in .env:
YEKPAY_MERCHANT_ID=your-merchant-id
YEKPAY_SANDBOX=true
Main config file: config/yekpay.php
return [
'merchant_id' => env('YEKPAY_MERCHANT_ID'),
'sandbox' => env('YEKPAY_SANDBOX', false),
'timeouts' => [
'connect' => 5,
'request' => 20,
],
'endpoints' => [
'production' => [
'request' => 'https://gate.ypsapi.com/api/payment/request',
'start' => 'https://gate.ypsapi.com/api/payment/start/{AUTHORITY}',
'verify' => 'https://gate.ypsapi.com/api/payment/verify',
],
'sandbox' => [
'request' => 'https://api.ypsapi.com/api/sandbox/request',
'start' => 'https://api.ypsapi.com/api/sandbox/payment/{AUTHORITY}',
'verify' => 'https://api.ypsapi.com/api/sandbox/verify',
],
],
];
Payment Flow Overview
YekPay uses a three-step payment process:
- Request Payment → Receive Authority
- Redirect User → Gateway payment page
- Verify Payment → Confirm transaction
This package mirrors that flow explicitly.
Usage
Request Payment
use RostamSodagari\YekPay\Enums\Currency;
use RostamSodagari\YekPay\Facade\Yekpay;
use RostamSodagari\YekPay\DTO\RequestPaymentData;
$result = YekPay::request(new RequestPaymentData(
fromCurrency: Currency::EUR,
toCurrency: Currency::EUR,
email: 'user@example.com',
mobile: '+4474940000000',
firstName: 'John',
lastName: 'Doe',
address: 'Address Here',
postalCode: 'Postal Code',
country: "United Kingdomm",
city: "London",
callback: 'http://verify-callback-here',
orderNumber: 'unique-order-number',
amount: 1000,
description: 'Order #1001',
));
if (! $result->ok() || ! $result->authority) {
abort(400, $result->getDescription());
}
Redirect User to Gateway
return redirect()->away(
Yekpay::startUrl($result->getAuthority())
);
Verify Payment (Callback)
use Illuminate\Http\Request;
use RostamSodagari\YekPay\Facade\Yekpay;
public function callback(Request $request)
{
$authority = (string) $request->input('Authority');
if ($authority === '') {
abort(400, 'Missing Authority');
}
$verify = Yekpay::verify($authority);
if (! $verify->ok()) {
abort(400, $verify->description);
}
return response()->json([
'status' => 'paid',
'reference' => $verify->reference,
'order' => $verify->orderNo,
'amount' => $verify->amount,
]);
}
Test Cards (Sandbox Mode)
The following card details are sandbox-only test cards provided for integration testing with the Yekpay payment gateway.
⚠️ Important
- These cards work only in sandbox mode
- They are not real cards
- Do not use them in production
| Card Name | Card Number | Expiration Date | CVC | Expected Result |
|---|---|---|---|---|
| John Doe | 5269 5522 3333 4445 | 2028/12 | 000 | Unsuccessful transaction |
| David Doe | 4022 7711 2222 3334 | 2028/12 | 000 | Successful transaction |
Currency Enum
All supported currencies are defined as a PHP enum:
use RostamSodagari\YekPay\Enums\Currency;
Currency::EUR; // 978
Currency::IRR; // 364
Note on TRY currency:
YekPay documentation contains conflicting TRY codes. This package uses the official appendix value by default, but you should confirm via sandbox before production use.
Error Handling Philosophy
- Gateway responses are never trusted blindly
- ok() checks numeric result codes
- Raw gateway payload is preserved internally for logging
Testing
This package is fully testable and ships with:
- Orchestra Testbench
- Guzzle MockHandler
- No real HTTP calls
Security Best Practices
- Always verify payment before marking orders as paid
- Never trust callback parameters alone
- Persist gateway Reference for audit trails
- Enable sandbox during development
License
MIT © Rostam Sodagari
rostam-sodagari/laravel-yekpay 适用场景与选型建议
rostam-sodagari/laravel-yekpay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 rostam-sodagari/laravel-yekpay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rostam-sodagari/laravel-yekpay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-15