定制 oussamamadjmaa/sofizpay-laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

oussamamadjmaa/sofizpay-laravel

Composer 安装命令:

composer require oussamamadjmaa/sofizpay-laravel

包简介

A Laravel wrapper for the SofizPay API — CIB card payments and prepaid service operations (phone, internet, game recharge, bill payments) for Algeria, with typed DTOs, response objects, and built-in sandbox mocking.

README 文档

README

Table of Contents

  • Features
  • Installation
  • Configuration
  • Usage
  • Sandbox Mode
  • Testing
  • License

SofizPay Laravel

Latest Version PHP Version License

A clean, fluent Laravel wrapper for the SofizPay API — CIB card payments and prepaid service operations (phone recharge, internet recharge, game top-ups, and bill payments) for Algerian merchants, with strongly-typed DTOs, response objects, and built-in sandbox mocking for service operations.

Features

  • 💳 CIB Transactions — create and check the status of card payment transactions
  • 📱 Service Operations — phone recharge, internet recharge, game recharge, and bill payments (Sonelgaz, ADE, Algérie Télécom)
  • 🧾 Typed DTOs & Responses — no more digging through raw arrays; every request and response is a typed object
  • 🧪 Built-in Sandbox Mode — Since SofizPay does not provide a sandbox environment for service operations, the package automatically fakes service requests in sandbox mode, allowing you to develop and test locally without making real API calls.- 🧩 Container-bound singleton + Facade — resolve via dependency injection or SofizPay:: facade calls
  • ⚙️ Simple configuration — a single config file driven by environment variables
  • 🚨 Predictable, informative error handling — every failed request throws a SofizPayRequestException carrying the underlying HTTP response

Requirements

  • PHP ^8.1
  • Laravel 10, 11, 12 or 13 (illuminate/support, illuminate/http)

Installation

Install the package via Composer:

composer require oussamamadjmaa/sofizpay-laravel

The service provider and facade are auto-discovered. Optionally publish the config file:

php artisan vendor:publish --provider="OussamaMadjmaa\SofizPay\SofizPayServiceProvider" --tag="config"

Configuration

Add the following to your .env file:

SOFIZPAY_ACCOUNT_ID=your_account_id
SOFIZPAY_ENCRYPTED_SK=your_encrypted_secret_key
SOFIZPAY_SANDBOX=true
Variable Description Default
SOFIZPAY_ACCOUNT_ID Your SofizPay account ID, used for CIB transactions
SOFIZPAY_ENCRYPTED_SK Your encrypted secret key, used for service operations
SOFIZPAY_SANDBOX To enable sandbox mode true

Note: Set SOFIZPAY_SANDBOX=false in production to send real requests to the SofizPay API.

Usage

You can resolve SofizPay three ways — pick whichever fits your codebase:

use OussamaMadjmaa\SofizPay\SofizPay;
use OussamaMadjmaa\SofizPay\Facades\SofizPay as SofizPayFacade;

// 1. Instantiate directly (reads config automatically)
$sofizpay = new SofizPay();

// 2. Resolve the bound singleton from the container
$sofizpay = app(SofizPay::class);

// 3. Use the facade
SofizPayFacade::cibTransaction()->make($dto);

The rest of the examples below use the $sofizpay variable interchangeably with any of the three.

CIB Transactions

Create a transaction

use OussamaMadjmaa\SofizPay\DTOs\MakeCIBTransactionDTO;

$dto = new MakeCIBTransactionDTO(
    amount: 2500,
    fullName: 'Oussama Madjmaa',
    phone: '0555123456',
    email: 'amine@example.com',
    returnUrl: 'https://your-app.test/payments/callback',
    memo: 'Order #1042',
);

$response = $sofizpay->cibTransaction()->make($dto);

$response->success;          // bool
$response->transactionId;    // string
$response->cibTransactionId; // string
$response->paymentUrl;       // string — redirect the customer here
$response->status;           // string

Check a transaction's status

$status = $sofizpay->cibTransaction()->check($response->transactionId);

$status->isPaid();      // bool
$status->isPending();   // bool
$status->isFailed();    // bool
$status->isCancelled(); // bool

$status->orderNumber,
$status->orderStatus,
$status->errorCode,
$status->errorMessage,
$status->actionCodeDescription,
$status->respCodeDesc,
$status->respCode,
$status->destinationAccount,
$status->amount

Service Operations

Service operations share a common perform() flow. Convenience methods are provided for each operation type, each accepting a typed DTO.

Phone recharge

The operator is inferred automatically from the phone number prefix (05 → Ooredoo, 06 → Mobilis, 07 → Djezzy).

use OussamaMadjmaa\SofizPay\DTOs\PhoneRechargeDTO;

$dto = new PhoneRechargeDTO(
    phone: '0555123456',
    amount: 500,
    offer: 'prepaid',
);

$response = $sofizpay->serviceOperation()->performPhoneRecharge($dto);

Internet recharge

use OussamaMadjmaa\SofizPay\DTOs\InternetRechargeDTO;

$dto = new InternetRechargeDTO(
    phone: '021123456',
    amount: 2000,
    // operator defaults to 'idoom'
    // offer is inferred (ADSL vs 4G) from the phone number length if omitted
);

$response = $sofizpay->serviceOperation()->performInternetRecharge($dto);

Bill payment

use OussamaMadjmaa\SofizPay\DTOs\BillPaymentDTO;
use OussamaMadjmaa\SofizPay\Enums\BillPaymentOperator;

$dto = new BillPaymentDTO(
    amount: 3200,
    operator: BillPaymentOperator::SONELGAZ,
    bill: '123456789012',
    customerId: '00458712',
    ebb: '151541'
);

$response = $sofizpay->serviceOperation()->performBillPayment($dto);

Supported bill operators: BillPaymentOperator::ADE, BillPaymentOperator::SONELGAZ, BillPaymentOperator::ALGERIE_TELECOM.

Game recharge

use OussamaMadjmaa\SofizPay\DTOs\GameRechargeDTO;
use OussamaMadjmaa\SofizPay\Enums\GameRechargeOperator;

$dto = new GameRechargeDTO(
    amount: 1000,
    operator: GameRechargeOperator::FREEFIRE,
    playerId: 'player-id-1234',
    offer: '110'
);

$response = $sofizpay->serviceOperation()->performGameRecharge($dto);

Supported game operators: GameRechargeOperator::FREEFIRE, GameRechargeOperator::PUBG.

Every perform* call returns a PerformServiceOperationResponse:

$response->status;            // string
$response->message;           // string
$response->operationId;       // string
$response->transactionId;     // string
$response->transactionStatus; // string

Operation details

$details = $sofizpay->serviceOperation()->details($response->operationId);

$details->status;                 // string
$details->amount;                 // float
$details->blockchainTransactions; // array
$details->transactionLogs;        // array

Operation history

$history = $sofizpay->serviceOperation()->history(limit: 20, offset: 0);

$history->operations;             // ServiceOperationDetailsResponse[]
$history->pagination->totalCount; // int
$history->pagination->limit;    // int
$history->pagination->offset;    // int
$history->pagination->hasMore;    // bool

Error Handling

Any non-successful response from the SofizPay API throws a SofizPayRequestException, which carries the underlying HTTP response so you can inspect the status code and raw JSON body:

use OussamaMadjmaa\SofizPay\Exceptions\SofizPayRequestException;

try {
    $response = $sofizpay->serviceOperation()->performPhoneRecharge($dto);
} catch (SofizPayRequestException $e) {
    report($e);

    $e->getMessage();      // human-readable message
    $e->response?->status(); // e.g. 422
    $e->context();          // the decoded JSON body, e.g. ['message' => '...']
    $e->body();             // the original response body
    $e->getResponse()       // full Http response
}

Sandbox Mode

When SOFIZPAY_SANDBOX is true (the default), cibTransaction()->make(), cibTransaction()->check() will use sandbox api endpoint, and all serviceOperation() calls — is faked locally via Http::fake(), returning realistic sample payloads. This lets you build and test your integration end-to-end without a live account or network calls.

  • serviceOperation()->details('INVALID_OPERATION_ID') simulates a 404 "not found" response.
  • All other sandbox responses simulate success.

Switch to SOFIZPAY_SANDBOX=false to hit the real SofizPay endpoints.

Testing tip: if you want to override a sandboxed endpoint's response in your own tests (e.g. to assert your error-handling code), resolve the endpoint instance (e.g. $cib = $sofizpay->cibTransaction();) before calling Http::fake() with your override. Endpoint constructors register their own sandbox stubs, and the most recently registered Http::fake() stub wins — so faking after resolving the endpoint guarantees your override takes priority.

Testing

The package ships with a Pest test suite built on Orchestra Testbench, covering DTO serialization/inference logic, both endpoint classes, error handling, and the facade/singleton binding:

composer test

Static analysis via PHPStan:

composer analyse

License

The MIT License (MIT). Please see LICENSE for more information.

Author

Oussama Madjmaa oussama@madjmaa.com

oussamamadjmaa/sofizpay-laravel 适用场景与选型建议

oussamamadjmaa/sofizpay-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 07 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「payment」 「sdk」 「laravel」 「payment-gateway」 「api-wrapper」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 oussamamadjmaa/sofizpay-laravel 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-15