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);
}

Payment page templates

The hosted payment page comes in four designs. Pass the one you want as the template parameter of create_invoice; the returned URL then points at that design (e.g. https://payid19.com/invoice/{alias}/paper). Omit it to keep the classic page.

$result = $payid19->create_invoice([
    'price_amount' => 100,
    'order_id'     => 42,
    'template'     => \Payid19\ClientAPI::TEMPLATE_MINT, // classic, slate, paper or mint
]);

Class constants let your editor autocomplete them and catch typos before the API does:

\Payid19\ClientAPI::TEMPLATE_CLASSIC  // 'classic'
\Payid19\ClientAPI::TEMPLATE_SLATE    // 'slate'
\Payid19\ClientAPI::TEMPLATE_PAPER    // 'paper'
\Payid19\ClientAPI::TEMPLATE_MINT     // 'mint'
\Payid19\ClientAPI::TEMPLATES         // all four, as an array

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.

Coins and estimates

List the coins and networks available for payment, or convert a fiat amount to a coin at the current rate:

// Coins and networks available for payment
$coins = json_decode($payid19->get_coins());

// Convert a fiat amount to a coin at the current rate
$estimate = json_decode($payid19->get_estimate([
    // see the get_estimate docs for parameters
]));

Full parameters: get_coins · get_estimate.

Withdrawals

Check your balance and request a withdrawal straight from the library:

// Your account balance
$balance = json_decode($payid19->get_balance());

// Request a withdrawal
$withdraw = json_decode($payid19->create_withdraw([
    // see the create_withdraw docs for parameters
]));

Full parameters: get_balance · create_withdraw.