Plaidly Docs

PHP Integration

Accept crypto payments in PHP applications

PHP Integration

Install the official Plaidly PHP SDK via Composer:

Not yet published to the package registry

plaidly/plaidly-php is not yet published to Packagist — install from source until registry publication ships.

git clone https://github.com/plaidly/plaidly-php.git
cd plaidly-php
composer install

Or point Composer at the GitHub repo directly by adding a VCS repository to your composer.json:

{
  "repositories": [
    { "type": "vcs", "url": "https://github.com/plaidly/plaidly-php.git" }
  ]
}
composer require plaidly/plaidly-php:dev-master

Once published to Packagist, the intended install command will be:

composer require plaidly/plaidly-php

Initialize the client

use Plaidly\PlaidlyClient;

$plaidly = new PlaidlyClient([
    'api_key' => $_ENV['PLAIDLY_API_KEY'],
]);

Create a payment session

$session = $plaidly->sessions->create([
    'amount'       => '10.00',
    'currency'     => 'USDC',
    'chain'        => 'solana',
    'network'      => 'mainnet',
    'callback_url' => 'https://yoursite.com/webhook',
    'metadata'     => ['order_id' => 'ord_123'],
]);

echo $session->wallet_address; // Show to customer
echo $session->id;             // Store for reference

Retrieve a session

$session = $plaidly->sessions->get('sess_01HX9K...');
echo $session->status; // 'pending' | 'confirming' | 'confirmed' | 'expired' | 'failed'

Verify webhooks

Laravel

// routes/api.php
Route::post('/webhook', [WebhookController::class, 'handle']);

// app/Http/Controllers/WebhookController.php
use Plaidly\Webhooks\Verifier;
use Illuminate\Http\Request;

class WebhookController extends Controller
{
    public function handle(Request $request): Response
    {
        $signature = $request->header('X-Plaidly-Signature', '');

        try {
            $event = Verifier::verify(
                $request->getContent(),
                $signature,
                config('services.plaidly.webhook_secret'),
            );
        } catch (\InvalidArgumentException $e) {
            return response('Invalid signature', 400);
        }

        if ($event['event'] === 'payment.confirmed') {
            FulfillOrder::dispatch($event['metadata']['order_id']);
        }

        return response('OK');
    }
}

Vanilla PHP

$rawBody  = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_PLAIDLY_SIGNATURE'] ?? '';

try {
    $event = \Plaidly\Webhooks\Verifier::verify(
        $rawBody,
        $signature,
        getenv('PLAIDLY_WEBHOOK_SECRET'),
    );
} catch (\InvalidArgumentException $e) {
    http_response_code(400);
    echo 'Invalid signature';
    exit;
}

if ($event['event'] === 'payment.confirmed') {
    fulfill_order($event['metadata']['order_id']);
}

http_response_code(200);
echo 'OK';

Requirements

  • PHP 8.1+
  • ext-curl
  • ext-json

On this page