> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fyatu.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP SDK

> Official Fyatu PHP SDK — integrate card issuing API, payment collections, and payouts into PHP applications.

<Warning>
  This SDK is coming soon. Subscribe to our [changelog](/v3/changelog/overview) to be notified when it's released.
</Warning>

The official PHP SDK for FYATU API v3, compatible with Laravel, Symfony, and vanilla PHP.

## Requirements

* PHP 8.1 or higher
* Composer

## Installation

```bash theme={null}
composer require fyatu/sdk
```

## Quick Start

```php theme={null}
<?php

use Fyatu\Sdk\Fyatu;

$fyatu = new Fyatu([
    'appId' => 'your_app_id',
    'secretKey' => 'your_secret_key',
]);

// Create a collection
$collection = $fyatu->collections->create([
    'amount' => 10.00,
    'currency' => 'USD',
    'reference' => 'order_123',
    'description' => 'Payment for Order #123',
    'customer' => [
        'email' => 'customer@example.com',
        'name' => 'Alice Example',
    ],
    'redirectUrl' => 'https://yoursite.com/payment/success',
    'webhookUrl' => 'https://yoursite.com/webhooks/fyatu',
]);

echo $collection->checkoutUrl;
```

## Laravel Integration

### Service Provider

Add the service provider to your `config/app.php`:

```php theme={null}
'providers' => [
    // ...
    Fyatu\Sdk\Laravel\FyatuServiceProvider::class,
],
```

### Configuration

Publish the configuration file:

```bash theme={null}
php artisan vendor:publish --provider="Fyatu\Sdk\Laravel\FyatuServiceProvider"
```

Add to your `.env`:

```env theme={null}
FYATU_APP_ID=your_app_id
FYATU_SECRET_KEY=your_secret_key
```

### Usage with Facade

```php theme={null}
use Fyatu\Sdk\Laravel\Facades\Fyatu;

$collection = Fyatu::collections()->create([
    'amount' => 10.00,
    'currency' => 'USD',
    'reference' => 'order_123',
]);
```

## Features

* **PHP 8.1+ Support** - Modern PHP with full type declarations
* **Framework Agnostic** - Works with any PHP framework
* **Laravel Integration** - First-class Laravel support with Facade
* **Automatic Token Management** - Handles JWT refresh automatically
* **PSR-18 Compatible** - Use your preferred HTTP client

## Configuration Options

```php theme={null}
$fyatu = new Fyatu([
    'appId' => 'your_app_id',
    'secretKey' => 'your_secret_key',

    // Optional configuration
    'baseUrl' => 'https://api.fyatu.com/api/v3',
    'timeout' => 30,
    'retries' => 3,
]);
```

## Available Services

| Service               | Description                    |
| --------------------- | ------------------------------ |
| `$fyatu->collections` | Accept payments via checkout   |
| `$fyatu->refunds`     | Manage refunds                 |
| `$fyatu->payouts`     | Send money to recipients       |
| `$fyatu->cardholders` | Manage cardholders             |
| `$fyatu->cards`       | Issue and manage virtual cards |

\| `$fyatu->account` | Access account information |

## Error Handling

```php theme={null}
use Fyatu\Sdk\Exceptions\FyatuException;
use Fyatu\Sdk\Exceptions\ValidationException;
use Fyatu\Sdk\Exceptions\AuthenticationException;

try {
    $payout = $fyatu->payouts->create([
        'amount' => 100,
        'currency' => 'USD',
        'recipientId' => 'invalid_id',
    ]);
} catch (ValidationException $e) {
    echo "Validation failed: " . print_r($e->getDetails(), true);
} catch (AuthenticationException $e) {
    echo "Authentication failed: " . $e->getMessage();
} catch (FyatuException $e) {
    echo "API error [{$e->getErrorCode()}]: " . $e->getMessage();
}
```

## Webhook Verification

```php theme={null}
use Fyatu\Sdk\Webhook;

// Verify webhook signature
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_FYATU_SIGNATURE'] ?? '';

$isValid = Webhook::verifySignature(
    $payload,
    $signature,
    'your_webhook_secret'
);

if (!$isValid) {
    http_response_code(401);
    exit('Invalid signature');
}

$event = json_decode($payload, true);
echo "Received event: " . $event['type'];
```

## Resources

* [API Reference](/v3/api-reference/introduction)
* [Webhooks Guide](/v3/concepts/webhooks)
* [GitHub Repository](https://github.com/fyatu/fyatu-php) *(Coming soon)*
