PHPackages                             machour/clictopay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. machour/clictopay

ActiveLibrary[Payment Processing](/categories/payments)

machour/clictopay
=================

ClicToPay PHP SDK

1.0.0(5mo ago)64.6k↓50%BSD-3-ClausePHPPHP ^8.3CI passing

Since Sep 7Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/machour/clictopay)[ Packagist](https://packagist.org/packages/machour/clictopay)[ Docs](https://www.clictopay.com.tn/)[ RSS](/packages/machour-clictopay/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

ClicToPay PHP SDK
=================

[](#clictopay-php-sdk)

 [ ![ClicToPay](./ClicToPay.png) ](https://clictopay.com.tn/)

 [![Tests](https://github.com/machour/clictopay/workflows/Tests/badge.svg)](https://github.com/machour/clictopay/actions) [![Total Downloads](https://camo.githubusercontent.com/9aa34dce981b8a655b543ca5035793c25d6cfeb59863a99eea3d9dae9449f85f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6163686f75722f636c6963746f706179)](https://packagist.org/packages/machour/clictopay) [![Latest Stable Version](https://camo.githubusercontent.com/96cab013b0f4520d6f8ef8447d44130d00c244701f0bf0a766928f4327ba7b60/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6163686f75722f636c6963746f706179)](https://packagist.org/packages/machour/clictopay) [![License](https://camo.githubusercontent.com/4968b0a49c9a31d47946702002405cc07888491f82a79193ea83fca7e22e1c1f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d6163686f75722f636c6963746f706179)](https://packagist.org/packages/machour/clictopay)

A modern, type-safe PHP SDK for ClicToPay payment gateway integration. **Framework-agnostic** - works with any PHP 8.3+ project (Laravel, Symfony, WordPress, or vanilla PHP).

Features
--------

[](#features)

- ✅ **Framework-independent** - Uses Guzzle HTTP client
- ✅ **Type-safe** - Full type hints and return types using Spatie Laravel Data

Installation
------------

[](#installation)

```
composer require machour/clictopay
```

Requirements
------------

[](#requirements)

- PHP 8.3 or higher
- Guzzle HTTP client (installed automatically)

Quick Start
-----------

[](#quick-start)

```
use Machour\ClicToPay\Gateway;
use Machour\ClicToPay\Endpoints\Register;
use Machour\ClicToPay\Exception;

// Initialize the gateway
$gateway = Gateway::make(
    login: 'your-username',
    password: 'your-password',
    testMode: true  // Use false for production
);

try {
    // Create a payment
    $response = $gateway->register(Register::from([
        'orderNumber' => 'ORDER-123',
        'amount' => 10000,  // Amount in millimes (100 TND)
        'returnUrl' => 'https://yoursite.com/payment/success',
        'description' => 'Order #123',
    ]));

    if ($response->isOk()) {
        // Store $response->orderId in your database
        // Redirect customer to payment page
        header('Location: ' . $response->formUrl);
        exit;
    }
} catch (Exception $e) {
    echo "Payment error: " . $e->getMessage();
}
```

Complete API Reference
----------------------

[](#complete-api-reference)

### 1. Register Payment (Authorization)

[](#1-register-payment-authorization)

Creates a new payment and returns a URL to redirect the customer to the payment page.

```
use Machour\ClicToPay\Endpoints\Register;

$response = $gateway->register(Register::from([
    // Required fields
    'orderNumber' => 'ORDER-123',          // Your unique order number
    'amount' => 10000,                     // Amount in millimes (100 TND)
    'returnUrl' => 'https://example.com/success',

    // Optional fields
    'failUrl' => 'https://example.com/fail',
    'description' => 'Order description',
    'language' => 'fr',                    // 'fr' or 'en'
    'clientId' => 'client-123',
    'jsonParams' => ['email' => 'customer@example.com'],
    'sessionTimeoutSecs' => 1800,
    'bindingId' => 'binding-id',
]));

// Response: UrlResponse
echo $response->orderId;   // Store this in your database
echo $response->formUrl;   // Redirect customer here
```

### 2. Pre-Authorize Payment

[](#2-pre-authorize-payment)

Creates a pre-authorization that will need to be deposited later.

```
use Machour\ClicToPay\Endpoints\PreAuthorize;

$response = $gateway->preAuthorize(PreAuthorize::from([
    'orderNumber' => 'ORDER-123',
    'amount' => 10000,
    'returnUrl' => 'https://example.com/success',
    // ... same optional fields as register
]));

// Response: UrlResponse
echo $response->orderId;
echo $response->formUrl;
```

### 3. Deposit (Capture Pre-Authorization)

[](#3-deposit-capture-pre-authorization)

Captures a previously pre-authorized payment.

```
use Machour\ClicToPay\Endpoints\Deposit;

$response = $gateway->deposit(Deposit::from([
    'orderId' => '70906e55-7114-41d6-8332-4609dc6590f4',
    'amount' => 10000,  // Can be less than pre-authorized amount
]));

// Response: Response
if ($response->isOk()) {
    echo "Payment captured successfully";
}
```

### 4. Cancel (Reverse) Payment

[](#4-cancel-reverse-payment)

Cancels a payment or pre-authorization.

```
use Machour\ClicToPay\Endpoints\Cancel;

$response = $gateway->cancel(Cancel::from([
    'orderId' => '70906e55-7114-41d6-8332-4609dc6590f4',
]));

// Response: Response
if ($response->isOk()) {
    echo "Payment cancelled";
}
```

### 5. Refund Payment

[](#5-refund-payment)

Refunds a completed payment (partial or full).

```
use Machour\ClicToPay\Endpoints\Refund;

$response = $gateway->refund(Refund::from([
    'orderId' => '70906e55-7114-41d6-8332-4609dc6590f4',
    'amount' => 5000,  // Refund amount (can be partial)
]));

// Response: Response
if ($response->isOk()) {
    echo "Refund processed";
}
```

### 6. Check Payment Status

[](#6-check-payment-status)

Gets the current status of a payment.

```
use Machour\ClicToPay\Endpoints\Status;

$response = $gateway->status(Status::from([
    'orderId' => '70906e55-7114-41d6-8332-4609dc6590f4',
]));

// Response: StatusResponse
echo $response->OrderStatus;      // 0=registered, 1=held, 2=authorized, etc.
echo $response->OrderNumber;      // Your order number
echo $response->Pan;              // Masked card number (411111**1111)
echo $response->amount;
echo $response->currency;
echo $response->approvalCode;
echo $response->cardholderName;
echo $response->expiration;
```

### 7. Extended Payment Status

[](#7-extended-payment-status)

Gets detailed payment status including 3D Secure information.

```
use Machour\ClicToPay\Endpoints\ExtendedStatus;

$response = $gateway->extendedStatus(ExtendedStatus::from([
    'orderId' => '70906e55-7114-41d6-8332-4609dc6590f4',
    'orderNumber' => 'ORDER-123',
]));

// Response: ExtendedStatusResponse
echo $response->orderStatus;
echo $response->actionCode;
echo $response->actionCodeDescription;
echo $response->amount;
echo $response->currency;
echo $response->ip;
echo $response->orderDescription;
print_r($response->cardAuthInfo);      // Card and 3DS info
print_r($response->merchantOrderParams);
```

HTTP Client Customization
-------------------------

[](#http-client-customization)

The SDK uses [Guzzle](https://docs.guzzlephp.org/) as its HTTP client. You can customize the Guzzle instance with your own configuration:

### Custom Timeout

[](#custom-timeout)

```
use GuzzleHttp\Client;
use Machour\ClicToPay\Gateway;

$client = new Client([
    'timeout' => 30,           // Request timeout in seconds
    'connect_timeout' => 10,   // Connection timeout
]);

$gateway = new Gateway(
    login: 'username',
    password: 'password',
    endpoint: 'https://test.clictopay.com/payment/rest/',
    client: $client
);
```

### Using a Proxy

[](#using-a-proxy)

```
$client = new Client([
    'proxy' => 'tcp://proxy.example.com:8080',
    'timeout' => 30,
]);

$gateway = new Gateway(
    login: 'username',
    password: 'password',
    endpoint: 'https://test.clictopay.com/payment/rest/',
    client: $client
);
```

### Logging Requests

[](#logging-requests)

```
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use Psr\Log\LoggerInterface;

$stack = HandlerStack::create();
$stack->push(Middleware::log($logger, new MessageFormatter()));

$client = new Client([
    'handler' => $stack,
]);

$gateway = new Gateway(
    login: 'username',
    password: 'password',
    endpoint: 'https://test.clictopay.com/payment/rest/',
    client: $client
);
```

For more Guzzle configuration options, see the [official Guzzle documentation](https://docs.guzzlephp.org/en/stable/request-options.html).

Response Handling
-----------------

[](#response-handling)

All API methods return typed response objects with helper methods:

```
$response = $gateway->register(/* ... */);

// Access properties with autocomplete
echo $response->orderId;
echo $response->formUrl;
```

Error Handling
--------------

[](#error-handling)

The SDK throws `Machour\ClicToPay\Exception` for all errors:

```
use Machour\ClicToPay\Exception;

try {
    $response = $gateway->register(/* ... */);
} catch (Exception $e) {
    // ClicToPay API error (e.g., duplicate order number)
    // or HTTP communication error
    echo $e->getMessage();
}
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Run static analysis with PHPStan:

```
composer phpstan
```

Run tests with coverage:

```
composer test:coverage
```

Framework Integration Examples
------------------------------

[](#framework-integration-examples)

### Laravel

[](#laravel)

```
// config/services.php
'clictopay' => [
    'username' => env('CLICTOPAY_USERNAME'),
    'password' => env('CLICTOPAY_PASSWORD'),
    'test_mode' => env('CLICTOPAY_TEST_MODE', true),
],

// In your controller
use Machour\ClicToPay\Gateway;

$gateway = Gateway::make(
    config('services.clictopay.username'),
    config('services.clictopay.password'),
    config('services.clictopay.test_mode')
);
```

### Symfony

[](#symfony)

```
# config/services.yaml
parameters:
    clictopay.username: '%env(CLICTOPAY_USERNAME)%'
    clictopay.password: '%env(CLICTOPAY_PASSWORD)%'
    clictopay.test_mode: '%env(bool:CLICTOPAY_TEST_MODE)%'

services:
    Machour\ClicToPay\Gateway:
        factory: ['Machour\ClicToPay\Gateway', 'make']
        arguments:
            - '%clictopay.username%'
            - '%clictopay.password%'
            - '%clictopay.test_mode%'
```

### Vanilla PHP

[](#vanilla-php)

```
require 'vendor/autoload.php';

$gateway = Machour\ClicToPay\Gateway::make(
    $_ENV['CLICTOPAY_USERNAME'],
    $_ENV['CLICTOPAY_PASSWORD'],
    $_ENV['APP_ENV'] === 'development'
);
```

License
-------

[](#license)

BSD-3-Clause

Links
-----

[](#links)

- [Official ClicToPay Website](http://www.clictopay.com.tn/)
- [GitHub Repository](https://github.com/machour/clictopay)
- [Report Issues](https://github.com/machour/clictopay/issues)

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance74

Regular maintenance activity

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1163 days

Total

2

Last Release

176d ago

Major Versions

0.0.1 → 1.0.02025-11-14

PHP version history (2 changes)0.0.1PHP ^7.3|^7.4|^8.0|^8.1

1.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/50430982793b695a5a9a886a81b976606c71062b49cf38c12509801b1845b1b2?d=identicon)[machour](/maintainers/machour)

---

Top Contributors

[![machour](https://avatars.githubusercontent.com/u/304450?v=4)](https://github.com/machour "machour (7 commits)")

---

Tags

paymentsmtclictopaytunisia

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/machour-clictopay/health.svg)

```
[![Health](https://phpackages.com/badges/machour-clictopay/health.svg)](https://phpackages.com/packages/machour-clictopay)
```

###  Alternatives

[shetabit/multipay

PHP Payment Gateway Integration Package

291348.2k3](/packages/shetabit-multipay)[sebdesign/laravel-viva-payments

A Laravel package for integrating the Viva Payments gateway

4845.9k](/packages/sebdesign-laravel-viva-payments)[bitpay/sdk

Complete version of the PHP library for the new cryptographically secure BitPay API

42337.5k4](/packages/bitpay-sdk)[henryejemuta/laravel-monnify

A laravel package to seamlessly integrate monnify api within your laravel application

132.1k](/packages/henryejemuta-laravel-monnify)[tsaiyihua/laravel-linepay

linepay library for laravel

102.9k](/packages/tsaiyihua-laravel-linepay)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
