Search by

nocustpay / nocustpay-php

nocustpay-core

PHP SDK for the NoCustPay crypto payment API.

Package info

github.com/nocustpay/nocustpay-php

pkg:composer/nocustpay/nocustpay-php

Statistics

Installs: 10

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-12-02 17:55 UTC

This package is not auto-updated.

Last update: 2026-12-03 16:22:57 UTC


README

PHP SDK for the NoCustPay crypto payment API. It covers every endpoint of the REST API: checkout sessions, payments, invoices, customers, wallets, branding, the webhook secret, reports and billing.

Requirements

  • PHP 7.4 or newer
  • ext-json
  • ext-curl for the default CurlTransport

Install

composer require nocustpay/nocustpay-php

Quick start

Create a checkout session and send the customer to its URL.

use NoCustPay\Client;
use NoCustPay\Data\CreateCheckoutSessionData;

$client = Client::make('your-api-key');

$session = $client->checkoutSessions->create(
    CreateCheckoutSessionData::make('Jane Doe', 'jane@example.com', '25.00', 'USD')
        ->withExternalId('order-42')
        ->withDescription('Order #42')
        ->withSuccessUrl('https://shop.example/thank-you')
        ->withCancelUrl('https://shop.example/cart')
        ->withMetadata(['order_id' => '42'])
);

header('Location: ' . $session->url());
exit;

When the customer comes back to success_url, NoCustPay adds ?session_id=… to it. Retrieve the session and check its status. Never trust the redirect alone.

$session = $client->checkoutSessions->retrieve($_GET['session_id']);

if ($session->isPaid()) {
    // fulfil the order
}

To put the ID somewhere else in the URL, use the {CHECKOUT_SESSION_ID} placeholder. NoCustPay replaces it and adds nothing else:

CreateCheckoutSessionData::make('Jane Doe', 'jane@example.com', '25.00', 'USD')
    ->withSuccessUrl('https://shop.example/orders/42?session={CHECKOUT_SESSION_ID}');

cancel_url works the same way. Sending an external_id you already used returns the existing session, so retries are safe.

Webhooks

use NoCustPay\Exception\InvalidSignature;
use NoCustPay\Webhook;

try {
    $event = Webhook::receive('your-webhook-secret');
} catch (InvalidSignature $e) {
    http_response_code(401);
    exit;
}

$payment = $event->payment();

if ($payment->isPaid()) {
    // the full amount arrived
} elseif ($payment->isOverpaid() || $payment->isUnderpaid()) {
    // a different amount arrived
} elseif ($payment->isExpired() || $payment->isCancelled()) {
    // nothing arrived in time
}

http_response_code(200);

Webhook::receive() reads the raw request body and the X-Webhook-Signature header itself, so you only pass your webhook secret. The same event can arrive more than once, so store $event->id() and skip ids you have already handled.

If your framework has already read the request, pass the raw body and the header yourself:

$event = Webhook::verify($rawBody, $signatureHeader, 'your-webhook-secret');

Checkout sessions

$session = $client->checkoutSessions->create(CreateCheckoutSessionData::make('Jane Doe', 'jane@example.com', '25.00', 'USD'));
$session = $client->checkoutSessions->retrieve($session->id());
$session = $client->checkoutSessions->expire($session->id());

The status is one of pending, paid, underpaid, overpaid, expired and cancelled. Check it with isPending(), isPaid(), isUnderpaid(), isOverpaid(), isExpired() and isCancelled(). Only a session that has not received a transfer can be expired.

Payments

use NoCustPay\Data\ListPaymentsData;
use NoCustPay\PaymentStatus;

$page = $client->payments->all(
    ListPaymentsData::make()
        ->withStatuses(PaymentStatus::PAID, PaymentStatus::OVERPAID)
        ->withNetwork('bsc')
        ->withCoin('usdt')
);

$payment = $client->payments->retrieve('payment-id');
echo $payment->total(), ' ', $payment->coin(), ' on ', $payment->network();

$result = $client->payments->cancel(['payment-id']);
$result = $client->payments->review(['payment-id'], true);
$result = $client->payments->delete(['payment-id']);
echo $result->affected(), ' done, ', $result->skipped(), ' skipped';

withSearch() and onlyNeedingReview() narrow the list further. The bulk actions take 1 to 100 IDs.

Invoices

use NoCustPay\Data\CreateInvoiceData;
use NoCustPay\Data\ListInvoicesData;
use NoCustPay\Data\UpdateInvoiceData;
use NoCustPay\InvoiceStatus;

$invoice = $client->invoices->create(
    CreateInvoiceData::make('customer-id', 'USD')
        ->addItem('Design work', 2, '150.50')
        ->addItem('Hosting', 1, '24.00')
        ->withDueOn('2026-12-31')
        ->withNotes('Thanks for your business.')
);

$invoice = $client->invoices->update($invoice->id(), UpdateInvoiceData::make()->withDueOn(null)->withNotes(null));
$invoice = $client->invoices->publish($invoice->id(), false);
$invoice = $client->invoices->send($invoice->id());

$client->invoices->void('open-invoice-id');
$client->invoices->delete('draft-invoice-id');

$page = $client->invoices->all(ListInvoicesData::make()->withStatuses(InvoiceStatus::OPEN)->onlyOverdue());
$invoice = $client->invoices->retrieve('invoice-id');

Invoices start as drafts. Publish one to make it payable at publicUrl(). An invoice is emailed at most once: pass true to publish() to email it right away, or call send() later. Sending items in an update replaces the whole list. Every call that returns a single invoice includes items() and customer(), but the list from all() leaves them out. Only retrieve() returns payments(), changeable() and deletable().

Customers

use NoCustPay\Data\CreateCustomerData;
use NoCustPay\Data\UpdateCustomerData;

$customer = $client->customers->create(
    CreateCustomerData::make('Ada Lovelace', 'ada@example.com')->withPhone('+44 20 7946 0958')
);

$customer = $client->customers->update($customer->id(), UpdateCustomerData::make()->withPhone(null));
$customer = $client->customers->retrieve($customer->id());
$page = $client->customers->all('Ada');
$client->customers->delete($customer->id());

An update sends only the fields you set. Passing null clears the phone or address.

Wallets

use NoCustPay\ChainFamily;
use NoCustPay\Data\CreateWalletData;
use NoCustPay\Data\UpdateWalletData;

$wallet = $client->wallets->create(
    CreateWalletData::make(ChainFamily::EVM, '0x476e5f2e01ece4e4e43b864c81b96c3b6230f91a', 'bsc:usdt', 'polygon:usdc')
        ->withLabel('Main')
        ->withFeePercent('1.50')
);

$wallet = $client->wallets->update($wallet->id(), UpdateWalletData::make()->withAssets('bsc:usdt')->inactive());

foreach ($client->wallets->all() as $listed) {
    echo $listed->address(), ' ', implode(', ', $listed->assets());
}

$client->wallets->delete($wallet->id());

Assets are network:coin keys such as bsc:usdt, tron:usdt or bitcoin:btc. A new wallet is active, with no fees and a 0.01 USD underpayment tolerance unless you set them. The wallet list is not paginated.

Branding

use NoCustPay\Data\UpdateBrandingData;

$branding = $client->branding->retrieve();

$branding = $client->branding->update(
    UpdateBrandingData::make()
        ->withName('Acme Pay')
        ->withPrimaryColor('#4f46e5')
        ->withSupportUrl(null)
        ->removeLogo()
);

$branding = $client->branding->uploadImages('/path/to/icon.png', '/path/to/logo.png');

uploadImages() sends a multipart request with at least one file. Pass null for the image you keep. Both images are PNG, JPG or WebP:

  • the icon is up to 1 MB and at least 64 × 64 pixels;
  • the logo is up to 2 MB and at least 32 pixels high.

Webhook secret

$secret = $client->webhookSecret->retrieve();
echo $secret->secret(), ' signs ', implode(', ', $secret->events());

$newSecret = $client->webhookSecret->rotate();

After a rotation every webhook is signed with the new secret, so switch your server to it right away.

Reports

use NoCustPay\DashboardPeriod;
use NoCustPay\Data\ReportRangeData;
use NoCustPay\ReportGranularity;

$report = $client->reports->payments(
    ReportRangeData::make()->from('2026-10-01')->to('2026-10-31')->withGranularity(ReportGranularity::WEEK)
);
echo $report->get('kpis.volume.current');

$dashboard = $client->reports->dashboard(DashboardPeriod::WEEK);
echo $dashboard->get('attention.pending_count');

$results = $client->reports->search('order-42');
foreach ($results['payments'] as $match) {
    echo $match['title'];
}

Reports return a read-only ApiObject. Read it with get('dot.path', $default), as an array, or with toArray().

Billing

use NoCustPay\BillingActivity;
use NoCustPay\Data\UpdateLowBalanceAlertData;

$balance = $client->billing->balance();
echo $balance->balance(), ' ', $balance->status();

$page = $client->billing->transactions(BillingActivity::FEES);

$alert = $client->billing->updateAlert(UpdateLowBalanceAlertData::make()->withThreshold('25.00')->enable());

$checkoutUrl = $client->billing->topUp('50.00');

Open the top-up URL and pay to add the funds.

Pagination

Lists return a Page: 25 items, newest first.

$page = $client->payments->all();

foreach ($page->data() as $payment) {
    echo $payment->id();
}

$cursor = $page->nextCursor();
if ($cursor !== null) {
    $next = $client->payments->all(ListPaymentsData::make()->withCursor($cursor));
}

autoPaginate() walks every page for you and keeps your filters:

foreach ($client->payments->all(ListPaymentsData::make()->withCoin('usdt'))->autoPaginate() as $payment) {
    echo $payment->id();
}

Errors

Every exception the API or the network causes extends NoCustPay\Exception\NoCustPayException.

Exception Raised when
ValidationError The API rejected the request (422). errors() lists the messages per field
InsufficientBalance The NoCustPay balance is too low (402)
AuthenticationError The API key is missing, wrong or lacks a permission (401 or 403)
RateLimited Too many requests (429). retryAfter() is the number of seconds to wait, or null
ApiError Any other API failure. status() is the HTTP status code
NetworkError The API could not be reached
InvalidSignature A webhook signature is missing or wrong, or the body is malformed

Mistakes in your own input are caught before any request is sent, with standard PHP exceptions:

  • InvalidArgumentException: CreateCheckoutSessionData::make() got an amount that is not a plain non-negative decimal, or an unsupported currency (Amount::format() throws the same). branding->uploadImages() got no file, or a path that cannot be read.
  • LogicException: you tried to write to or unset a key on an ApiObject, which is read-only.
use NoCustPay\Exception\RateLimited;
use NoCustPay\Exception\ValidationError;

try {
    $client->billing->topUp('50.00');
} catch (ValidationError $e) {
    $messages = $e->errors();
} catch (RateLimited $e) {
    sleep($e->retryAfter() ?? 60);
}

Sandbox

Pass true as the second argument to use the sandbox API with a sandbox API key. Sandbox payments use no real money.

$client = Client::make('your-sandbox-api-key', true);

Transports

The client uses CurlTransport by default. In WordPress, use withTransport() to send requests through the WordPress HTTP API. It returns a new client and leaves the original unchanged.

use NoCustPay\Client;
use NoCustPay\Http\WordPressTransport;

$client = Client::make('your-api-key')->withTransport(new WordPressTransport());