paytabs/php-sdk

Official PayTabs PHP SDK for Payment Gateway integrations

Maintainers

Package info

github.com/paytabscom/php-sdk

pkg:composer/paytabs/php-sdk

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

3.0.0 2026-06-24 08:35 UTC

This package is auto-updated.

Last update: 2026-06-24 12:47:20 UTC


README

Official PHP SDK for integrating with PayTabs Payment Gateway.

Requirements

  • PHP ^8.4
  • cURL extension enabled

Install

composer require paytabs/php-sdk:^3.0

Quick Start

<?php

use Paytabs\Sdk\Http\Http;
use Paytabs\Sdk\Paytabs;
use Paytabs\Sdk\Profile\ProfilesFactory;
use Paytabs\Sdk\Request\Payload\PayloadsFactory;
use Paytabs\Sdk\Request\RequestsFactory;
use Paytabs\Sdk\Enums\TranClass;
use Paytabs\Sdk\Enums\TranType;

$profile = ProfilesFactory::createUaeProfile(
	(int) getenv('PAYTABS_PROFILE_ID'),
	(string) getenv('PAYTABS_SERVER_KEY')
);

$payload = PayloadsFactory::hostedPage();
$payload
	->buildTransaction(TranType::Sale, TranClass::Ecom)
	->buildCart('order-1001', 'AED', 100.00, 'Order 1001')
	->buildHideShipping(true);

$request = RequestsFactory::paymentRequest($profile, $payload);

$http = (new Http())
	->setLogger(Paytabs::getLogger())
	->setRequest($request);

try {
	$response = $http->submit();
} catch (\Paytabs\Sdk\Exceptions\HttpRequestException $e) {
	// Transport failure or non-2xx response.
	throw $e;
}

if ($response->isFailure()) {
	$failure = $response->getFailure();
	echo $failure->code.' - '.$failure->message;
	exit;
}

if ($response->isRedirect()) {
	$redirect = $response->getRedirect();
	header('Location: '.$redirect->redirect_url);
	exit;
}

Security Notes

  • Do not log card data, CVV, full tokens, or full webhook signatures.
  • Store credentials in environment variables, not in repository files.
  • Always verify webhook signatures and reject invalid requests.

See webhook verification guide: docs/usage/Webhooks.md

Logging Configuration

The SDK logger can be configured with environment variables:

  • PAYTABS_LOG_PATH: Directory where SDK log files are stored.
    • Default: /var/log/paytabs-sdk/
    • Fallback: system temporary directory when the configured/default path is empty.
  • PAYTABS_LOG_BROWSER: Enables browser logger mode when set to true.
    • Default behavior uses file logger mode.

Example:

export PAYTABS_LOG_PATH="/var/log/paytabs-sdk"
export PAYTABS_LOG_BROWSER="false"

Documentation

Project Governance

Samples Setup

  1. Copy Samples/.env.sample to Samples/.env.
  2. Replace placeholder values with sandbox credentials.
  3. Run samples locally and expose callback URL when needed.

Development Commands

composer lint
composer test

Live gateway tests are opt-in only:

PAYTABS_RUN_LIVE_TESTS=1 composer test

Versioning

This SDK follows semantic versioning. Breaking changes are introduced only in major versions.

Support

For integration support, use PayTabs official support channels. For security vulnerabilities, report via the PayTabs Bug Bounty Program and follow SECURITY.md. Public issues are intended for reproducible SDK bugs and enhancement requests.