Php

Getting Started

Vatly PHP SDK - Getting Started

Getting Started

Official PHP SDK for the Vatly API. Handle subscriptions, one-off payments, tax compliance, and billing for your SaaS.

Installation

Install the SDK via Composer.

composer require vatly/vatly-api-php

Quick start

Initialize the client with your API key and create a checkout.

API Keys

Get your API keys from the Vatly Dashboard under Settings > API.

NameTypeDescription
live_prefixProduction transactions, real charges.
test_prefixSandbox testing, no real charges.
use Vatly\Api\VatlyApiClient;

$vatly = new VatlyApiClient();
$vatly->setApiKey('live_your_api_key_here');

// Create a checkout
$checkout = $vatly->checkouts->create([
    'products' => [
        ['id' => 'plan_abc123', 'quantity' => 1]
    ],
    'redirectUrlSuccess' => 'https://yourapp.com/success',
    'redirectUrlCanceled' => 'https://yourapp.com/canceled',
]);

// Redirect customer to checkout
header('Location: ' . $checkout->getCheckoutUrl());

Resources

The SDK provides access to all Vatly API resources.

ResourceDescription
CheckoutsCreate hosted payment pages
CustomersManage customer records
SubscriptionsRecurring billing
Subscription PlansDefine subscription products
One-Off ProductsSingle purchase products
OrdersTransaction records
RefundsProcess refunds
ChargebacksHandle disputes
WebhooksReal-time event notifications

Error handling

The SDK throws specific exceptions for different error types.

Exception types

NameTypeDescription
ValidationExceptionexceptionInvalid request parameters. Check getErrors() for field-level details.
ApiExceptionexceptionAPI errors (network, authentication, etc.). Check getStatusCode() for HTTP status.
use Vatly\Api\Exceptions\ApiException;
use Vatly\Api\Exceptions\ValidationException;

try {
    $checkout = $vatly->checkouts->create([...]);
} catch (ValidationException $e) {
    // Invalid request parameters
    echo $e->getMessage();
    print_r($e->getErrors());
} catch (ApiException $e) {
    // API error (network, auth, etc.)
    echo $e->getMessage();
    echo $e->getStatusCode();
}

Requirements

  • PHP 8.1+
  • cURL extension
  • JSON extension
Copyright © 2026