DEV Community

Yasser Elgammal
Yasser Elgammal

Posted on

Building a Tabby PHP SDK: A Framework-Agnostic Payment Integration

Tabby PHP SDK is a framework-agnostic PHP package designed to make Tabby payment integrations easier to build and maintain without coupling the integration to a specific PHP framework.

What does it support?

The SDK currently provides support for:

  • Checkout creation
  • Multiple checkout items
  • Payment retrieval and management
  • Capture and refunds
  • Payment closing
  • Webhook management
  • Webhook secret verification
  • Strongly typed DTOs
  • Fluent builders
  • Local validation
  • Structured exceptions
  • Injectable HTTP client

The package requires PHP 8.2+ and Guzzle 7.

Simple example

Creating a checkout looks like this:

$checkout = $tabby->checkout()
    ->amount('250.00')
    ->currency('SAR')
    ->referenceId('order-1')
    ->buyer($buyer)
    ->shippingAddress($address)
    ->item(
        $tabby->item()
            ->title('Product Name')
            ->quantity(1)
            ->unitPrice('250.00')
            ->referenceId('product-1')
            ->build()
    )
    ->merchantUrls(
        'https://shop.test/success',
        'https://shop.test/cancel',
        'https://shop.test/failure',
    )
    ->build();

$response = $tabby->checkouts()->create($checkout);
Enter fullscreen mode Exit fullscreen mode

The SDK separates request building and validation from sending the request to the Tabby API.

Payment operations

Payment management is available through a dedicated resource:

$payment = $tabby->payments()->getResponse('payment-id');

$tabby->payments()->capture(
    'payment-id',
    'capture-ref-123'
);

$tabby->payments()->refund(
    'payment-id',
    'refund-ref-456',
    '50.00',
    'Customer requested refund'
);
Enter fullscreen mode Exit fullscreen mode

Webhooks

Webhook registration and verification are supported as well:

$webhook = $tabby->webhooks()->create(
    'https://shop.example/webhooks/tabby'
);

if (! $tabby->webhookVerifier()->verify($providedSecret)) {
    http_response_code(401);
    exit('Invalid webhook secret');
}
Enter fullscreen mode Exit fullscreen mode

Why framework agnostic?

The SDK is designed to work independently from Laravel or any other PHP framework.

The HTTP client is injectable, making the package easier to test and allowing the transport layer to be replaced when needed.

The project also includes a PHPUnit test suite, so integrations can be tested without making requests to the real Tabby API.

What's next?

Tabby PHP SDK is an open-source project that will continue to evolve alongside Tabby API integrations and PHP development.

If you're working with Tabby + PHP, feedback and contributions are welcome.

The full documentation, installation instructions, API details, examples, and source code are available on GitHub:

GitHub:
https://github.com/YasserElgammal/tabby-php

Tabby API Documentation:
https://docs.tabby.ai/

The goal is to provide a simple, reusable PHP integration for Tabby without tying it to a specific framework.

Top comments (1)

Collapse
 
codearea_shop_1f1def9b532 profile image
Codearea •

This is a really useful SDK for PHP developers working with Tabby. I especially like the framework-agnostic approach, typed DTOs, webhook verification, and injectable HTTP client. It makes the integration cleaner and easier to test. Developers looking for more PHP tools and resources can also check out codearea.net.