PHP Library

The official Payid19 PHP library wraps the REST API in a simple client class, so you can create invoices and check payments with a few lines of code. It is open source and available on GitHub and Packagist.

Requirements

  • PHP 7.4 or newer
  • ext-curl and ext-json extensions

Installation

Install the library with Composer:

composer require payid19/payid19-api-php

Setup

Create a client with the public and private keys from your Settings page:

<?php
require 'vendor/autoload.php';

$payid19 = new \Payid19\ClientAPI('YOUR_PUBLIC_KEY', 'YOUR_PRIVATE_KEY');

Creating an invoice

Creates an invoice and returns the hosted payment page URL. Redirect your customer to that URL to complete the payment. All parameters of the create_invoice endpoint are supported:

$result = $payid19->create_invoice([
    'email'            => '[email protected]',
    'price_amount'     => 100,
    'price_currency'   => 'USD',
    'order_id'         => 42,
    'title'            => 'Order #42',
    'description'      => 'Payment for Order #42',
    'success_url'      => 'https://yoursite.com/payment/success',
    'cancel_url'       => 'https://yoursite.com/payment/cancel',
    'callback_url'     => 'https://yoursite.com/payment/callback',
]);

$response = json_decode($result);

if ($response->status == 'error') {
    // handle the error
    echo $response->message[0];
} else {
    // redirect your customer to the payment page
    header('Location: ' . $response->message);
}

Checking invoices

Fetch your invoices — for example by your own order ID — and check their status field (null = waiting, 1 = paid, 2 = refunded, 3 = underpaid):

$result = $payid19->get_invoices([
    'order_id' => 42,
]);

$response = json_decode($result);

Handling the payment callback

When an invoice is paid, Payid19 sends a POST request to the callback_url you set on the invoice. Always verify the privatekey field before trusting the data:

<?php
$data = json_decode(file_get_contents('php://input'));

if ($data->privatekey != 'YOUR_PRIVATE_KEY') {
    http_response_code(403);
    die;
}

// payment is confirmed - mark the order as paid
// $data->order_id, $data->price_amount, $data->amount ... are available
Respond with an HTTP 2xx status so the callback is not retried. See the create_invoice documentation for the full callback payload.

Other endpoints

The library currently covers create_invoice and get_invoices. For get_balance and create_withdraw, call the REST API directly — they are single POST requests and the documentation includes ready-to-use PHP samples.