承接 farayaz/larapay 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

farayaz/larapay

Composer 安装命令:

composer require farayaz/larapay

包简介

iranian online payment gateways

README 文档

README

GitHub Repo stars Total Downloads Latest Stable Version License PHP Version

Larapay is a Laravel package for integrating Iranian payment gateways.

لاراپی یک پکیج لاراول برای اتصال به درگاه‌های پرداختی ایرانی است.

Requirements | نیازمندی‌ها

  • PHP: ^8.2
  • Laravel: ^12.0 | ^13.0

Installation | نصب

composer require farayaz/larapay

Configuration | تنظیمات

No configuration file is required. Just pass the gateway config directly when calling the gateway.

نیازی به فایل کانفیگ جداگانه نیست. تنظیمات درگاه را مستقیماً هنگام فراخوانی ارسال کنید.

Each gateway has its own required parameters. See the Gateways table below.

هر درگاه پارامترهای مورد نیاز خود را دارد. به جدول درگاه‌ها مراجعه کنید.

Gateways | درگاه‌ها

Class Name (en) Name (fa) Requirements Features
AsanPardakht AsanPardakht آسان پرداخت (آپ) username, password, merchant_configuration_id
Azkivam Azkivam ازکی وام merchant_id, api_key
BehPardakht Beh Pardakht Mellat به‌پرداخت ملت terminal_id, username, password, is_credit
Bitpay Bitpay بیت پی api, sandbox
Digipay Digipay دیجی‌پی username, password, client_id, client_secret
ECD Electronic Card Damavand پرداخت الکترونیک دماوند terminal_number, hash_key
FanavaCard FanavaCard فن‌آوا کارت user_id, password
IdPay IdPay آیدی‌پی apiKey, sandbox
IranDargah IranDargah ایران درگاه merchant_id, sandbox
IranKish Iran Kish ایران کیش terminalId, password, acceptorId, pubKey
IsipaymentSamin Isipayment Samin ایزایران ثمین merchant_code, merchant_password, terminal_code, type, number_of_installment
Keepa Keepa - Kipaa کیپا token
MehrIran MehrIran بانک مهر ایران terminal_id, merchant_nid, encrypt_key
NextPay NextPay نکست پی api_key
Omidpay Omidpay - Sayan Card امید پی (سایان کارت) user_id, password
PardakhtNovin Pardakht Novin پرداخت نوین userId, password, terminalId
Payir Pay.ir پی.آی‌آر api
PayPing PayPing پی پینگ token
PEC PEC تجارت الکترونیک پارسیان login_account
PEP PEP پرداخت الکترونیک پاسارگاد username, password, terminal_number
Polam Polam (Poolam) پولام api_key
RefahBeta Refah Beta بانک رفاه بتا client_id, client_secret, api_key, number_of_installments Bulk Check
Sadad Sadad پرداخت الکترونیک سداد (ملی) terminal_id, merchant_id, key
SadadBNPL SadadBNPL سداد BNPL terminal_id, merchant_id, key
Sep Saman Electronic Payment پرداخت الکترونیک سامان (سپ) terminalId
Sepal Sepal سپال api_key
SepehrPay Sepehr Pay پرداخت الکترونیک سپهر (مبنا) terminalId
Shepa Shepa شپا api
SnappPay SnappPay اسنپ‌پی username, password, client_id, client_secret
TabaPay TabaPay تاباپی token
TejaratBajet Tejarat Bajet بانک تجارت - باجت client_id, client_secret, sandbox Bulk Check
🧪 Test Test تست
Vandar Vandar وندار api_key
ZarinPal Zarin Pal زرین پال merchant_id
Zibal Zibal زیبال merchant

Features: Bulk Check = supports bulk transaction status checking.

اگر درگاه مورد نظر خود را پیدا نکردید، به ما اطلاع دهید یا در اضافه کردن آن مشارکت کنید.

Usage | نحوه استفاده

The payment flow consists of 3 steps: Request (get token), Redirect (send user to gateway), and Verify (confirm payment).

فرایند پرداخت شامل ۳ مرحله است: دریافت توکن، هدایت کاربر به درگاه، و تأیید پرداخت.

1. Request Token | دریافت توکن

use Farayaz\Larapay\Exceptions\LarapayException;
use Larapay;

$gateway = 'ZarinPal';
$config = [
    'merchant_id' => 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
];

$amount = 10000; // Rial | ریال
$id = 1230; // Transaction ID | شماره تراکنش
$callbackUrl = route('payment.callback', $id);
$nationalId = '1234567890';
$mobile = '09131234567';

try {
    $result = Larapay::gateway($gateway, $config)
        ->request(
            id: $id,
            amount: $amount,
            callbackUrl: $callbackUrl,
            nationalId: $nationalId,
            mobile: $mobile,
        );
} catch (LarapayException $e) {
    // handle error
}

// Save token for later verification
$token = $result['token'];
$fee = $result['fee'];

Response:

Key Type Description
token string Gateway token to use in redirect/verify
fee int Transaction fee in Rials

2. Redirect to Gateway | هدایت به درگاه

try {
    return Larapay::gateway($gateway, $config)
        ->redirect(id: $id, token: $token, callbackUrl: $callbackUrl);
} catch (LarapayException $e) {
    // handle error
}

This returns a redirect response (either a RedirectResponse to the gateway or a form view).

3. Verify Payment | تأیید پرداخت

$params = $request->all();

try {
    $result = Larapay::gateway($gateway, $config)
        ->verify(
            id: $id,
            amount: $amount,
            nationalId: $nationalId,
            mobile: $mobile,
            token: $token,
            params: $params,
        );
} catch (LarapayException $e) {
    // Transaction failed
}

// Transaction successful
$result['result'];       // Status message
$result['reference_id']; // Gateway reference ID
$result['tracking_code'];// Tracking code
$result['card'];         // Masked card number
$result['fee'];          // Transaction fee

Response:

Key Type Description
result string Status message from gateway
reference_id string|null Gateway reference number (شناسه پیگیری)
tracking_code string|null Transaction tracking code (شماره تراکنش)
card string|null Masked card number (شماره کارت)
fee int Transaction fee in Rials

Complete Controller Example | مثال کامل کنترلر

<?php

namespace App\Http\Controllers;

use Farayaz\Larapay\Exceptions\LarapayException;
use Illuminate\Http\Request;
use Larapay;

class PaymentController extends Controller
{
    protected string $gateway = 'ZarinPal';
    protected array $config = [
        'merchant_id' => env('ZARINPAL_MERCHANT_ID'),
    ];

    public function pay()
    {
        $amount = 100000; // Rial
        $id = rand(1000, 9999); // Unique transaction ID
        $callbackUrl = route('payment.callback', $id);
        $nationalId = '1234567890';
        $mobile = '09131234567';

        try {
            $result = Larapay::gateway($this->gateway, $this->config)
                ->request(
                    id: $id,
                    amount: $amount,
                    callbackUrl: $callbackUrl,
                    nationalId: $nationalId,
                    mobile: $mobile,
                );
        } catch (LarapayException $e) {
            return back()->with('error', $e->getMessage());
        }

        // Store $result['token'], $result['fee'], $id in session/db
        session(['payment_token' => $result['token'], 'payment_id' => $id, 'amount' => $amount]);

        return Larapay::gateway($this->gateway, $this->config)
            ->redirect($id, $result['token'], $callbackUrl);
    }

    public function callback(Request $request, int $id)
    {
        $token = session('payment_token');
        $amount = session('amount');

        try {
            $result = Larapay::gateway($this->gateway, $this->config)
                ->verify(
                    id: $id,
                    amount: $amount,
                    nationalId: '1234567890',
                    mobile: '09131234567',
                    token: $token,
                    params: $request->all(),
                );
        } catch (LarapayException $e) {
            return view('payment.failed', ['message' => $e->getMessage()]);
        }

        return view('payment.success', [
            'tracking_code' => $result['tracking_code'],
            'reference_id' => $result['reference_id'],
            'card' => $result['card'],
        ]);
    }
}

Advanced Usage | استفاده پیشرفته

Refund | بازگشت وجه

Only available on gateways that implement RefundableInterface.

فقط در درگاه‌هایی که RefundableInterface را پیاده‌سازی کرده‌اند در دسترس است.

try {
    $result = Larapay::gateway($gateway, $config)
        ->refund(
            id: $transactionId,
            amount: $amount,
            referenceId: $referenceId,
            reason: 'Customer request',
        );
} catch (LarapayException $e) {
    // Refund failed
}

Bulk Check | بررسی گروهی

Only available on gateways that implement BulkCheckableInterface.

فقط در درگاه‌هایی که BulkCheckableInterface را پیاده‌سازی کرده‌اند در دسترس است.

try {
    Larapay::gateway($gateway, $config)
        ->bulkCheck(
            successCallback: function ($id, $data) {
                // Transaction $id is successful
                // $data contains: result, card, tracking_code, reference_id, amount, fee
            },
            unsuccessCallback: function ($id) {
                // Transaction $id failed
            },
        );
} catch (LarapayException $e) {
    // handle error
}

Check Gateway Capabilities | بررسی قابلیت‌های درگاه

$gateway = Larapay::gateway($gateway, $config);

if ($gateway->supports('refund')) {
    // Gateway supports refund
}

if ($gateway->supports('bulk_check')) {
    // Gateway supports bulk check
}

Error Handling | مدیریت خطا

All exceptions are thrown as Farayaz\Larapay\Exceptions\LarapayException.

تمام خطاها به صورت LarapayException پرتاب می‌شوند.

use Farayaz\Larapay\Exceptions\LarapayException;

try {
    // ...
} catch (LarapayException $e) {
    $message = $e->getMessage(); // Persian or English error message
    $code = $e->getCode();       // Optional error code
}

Benefits | مزایا

  • Simple | ساده: Unified API for all gateways | API یکسان برای همه درگاه‌ها
  • Flexible | انعطاف‌پذیر: Easy to add new gateways | اضافه کردن درگاه جدید آسان
  • Fee Calculation | محاسبه هزینه: Built-in transaction fee calculation | محاسبه خودکار کارمزد
  • Maintained | به‌روز: Actively maintained and updated | نگهداری و به‌روزرسانی فعال
  • Open Source | متن‌باز: MIT license | مجوز MIT

Contributing | مشارکت

If you don't find the gateway you want, feel free to contribute!

اگر درگاه مورد نظر خود را پیدا نکردید، در اضافه کردن آن مشارکت کنید!

  1. Create a new class in src/Gateways/ extending GatewayAbstract
  2. Implement request(), redirect(), and verify() methods
  3. Optionally implement RefundableInterface or BulkCheckableInterface
  4. Add the gateway to the table in this README
  5. Submit a Pull Request

License | مجوز

This package is open-source software licensed under the MIT license.

این پکیج تحت مجوز MIT منتشر شده است.

farayaz/larapay 适用场景与选型建议

farayaz/larapay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 549 次下载、GitHub Stars 达 20, 最近一次更新时间为 2023 年 10 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 farayaz/larapay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 farayaz/larapay 我们能提供哪些服务?
定制开发 / 二次开发

基于 farayaz/larapay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 549
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 20
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-25