Search by

cryptpays / laravel

cryptpays

Official Laravel integration for the CryptPays PHP SDK

v0.1.0 2026-12-01 15:11 UTC

This package is auto-updated.

Last update: 2026-12-01 15:20:39 UTC


README

Official Laravel integration for cryptpays/sdk-php. Version 0.1.0 is an initial, pre-stable release.

This package adds framework-native dependency injection, configuration, an optional facade, callback public-key caching, and signature-verification middleware. Payment, transport, decimal, response, and RSA-SHA256 logic remains in the PHP SDK and is not duplicated here.

Start with the secure Laravel quick start. Complete DI, facade, callback, QR, pricing, log, and exception examples are in Merchant integration examples; operational failures are covered by Troubleshooting.

Requirements

Laravel Package PHP requirement Framework PHP requirement
12.x PHP 8.2+ PHP 8.2+
13.x PHP 8.3+ PHP 8.3+

The integration itself requires PHP 8.2 or newer because cryptpays/sdk-php does. Laravel 13's own constraints raise that combination to PHP 8.3 or newer.

The initial release matrix is Laravel 12 and 13. Laravel 10 and 11 are not release targets; no security-advisory bypass is used to resolve dependencies.

Installation

The core PHP SDK is published as cryptpays/sdk-php. After this Laravel package is published:

composer require cryptpays/laravel:^0.1
php artisan vendor:publish --tag=cryptpays-config

Laravel discovers CryptPaysServiceProvider and the optional CryptPays facade automatically. See the installation guide for configuration and transport options.

Set the externally registered callback hostname in .env:

CRYPTPAYS_CALLBACK_HOSTNAME=merchant.example
CRYPTPAYS_CALLBACK_TRANSPORT=json_post

Do not derive this value from an incoming Host, Forwarded, or X-Forwarded-Host header.

Use the PHP SDK through dependency injection

<?php

namespace App\Http\Controllers;

use CryptPays\CryptPaysClient;
use CryptPays\Request\CreatePaymentRequest;

final class CheckoutController
{
    public function __invoke(CryptPaysClient $cryptPays)
    {
        $payment = $cryptPays->createPayment(new CreatePaymentRequest(
            ticker: 'bep20_usdt',
            callbackUrl: 'https://merchant.example/api/cryptpays/callback?order_id=opaque-reference',
            addressOut: '0x1111111111111111111111111111111111111111',
        ));

        return response()->json([
            'address' => $payment->addressIn,
            'minimum' => (string) $payment->minimumTransactionCoin,
        ]);
    }
}

Never retry payment creation automatically. The SDK enforces that invariant even when safe read retries are enabled. A repeated compatible creation request may return the backend's existing immutable payment configuration.

Currency and pricing discovery use the same injected client:

$currencies = $cryptPays->listCurrencies();
$currency = $cryptPays->getCurrencyInfo('bep20_usdt');
$pricing = $cryptPays->getPricing();
$tier = $pricing->tierForVolume('1000.000000000000000001');
$logs = $cryptPays->getPaymentLogs(
    'bep20_usdt',
    'https://merchant.example/api/cryptpays/callback?order_id=opaque-reference',
);

All money and percentage values remain decimal strings. Cast typed decimal objects to strings; never route them through a binary float. Pricing-tier selection is exact-decimal convenience over the gateway's published pricing schedule; it is not a fee or settlement guarantee. Payment logs and their callback URL are server-side reconciliation data and must not be exposed to browsers or routine logs.

The optional facade exposes the same client:

use CryptPays\Laravel\Facades\CryptPays;

$currencies = CryptPays::listCurrencies();

Verify callbacks

use App\Http\Controllers\CryptPaysCallbackController;
use Illuminate\Support\Facades\Route;

Route::post('/cryptpays/callback', CryptPaysCallbackController::class)
    ->middleware('cryptpays.callback:json_post');

The middleware verifies the timestamp and RSA-SHA256 signature over the exact raw body, request method, configured hostname, and exact request target before typed callback data is made available:

use CryptPays\Laravel\Callback\VerifiedCallbackContext;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Symfony\Component\HttpFoundation\Response;

public function __invoke(Request $request, VerifiedCallbackContext $callbacks)
{
    $payload = $callbacks->payload($request);

    DB::transaction(function () use ($payload): void {
        // Lock the application-owned payment row. Store receipts under a unique
        // (uuid, stage) key because pending and confirmed share one UUID.
        // Validate business policy and make confirmed fulfilment idempotent here.
    });

    // Acknowledge only after commit. CryptPays accepts exact HTTP 200 only.
    return response('OK', Response::HTTP_OK);
}

Read Callback verification before exposing the route. It covers trusted proxies, request-target preservation, key caching, replay boundaries, and transactional idempotency.

JSON POST is recommended. Signed form POST and GET callbacks are also supported with cryptpays.callback:form_post and cryptpays.callback:get. The explicit route parameter overrides CRYPTPAYS_CALLBACK_TRANSPORT; never auto-detect transport from unverified request data.

Configuration highlights

  • Retries are off by default. CRYPTPAYS_RETRY_SAFE_READS=true enables bounded retries only for safe SDK reads.
  • Default connect and total timeouts are 5 and 15 seconds.
  • Redirects and Guzzle HTTP exceptions are disabled by the default transport so the SDK can validate responses itself.
  • A custom PSR-18 client and PSR-17 factories may be supplied by container service ID. Configure timeouts and redirect behavior on a custom PSR-18 client because those settings are not portable through PSR-18.
  • The callback public key is cached with an explicit one-hour TTL by default. It may also be injected as a PEM public key.
  • Cache TTL is bounded to 24 hours. Cache misses and rotations are coordinated with Laravel cache locks where the selected store supports them. A verification failure permits one cooldown-bounded public-key refresh and then fails closed.
  • Payment logs are server-side reconciliation data. Keep callback URLs out of responses, logs, analytics, and client applications.

The public Merchant API is keyless. This package has no API-key setting, private keys, wallets, signing, Admin endpoints, internal Node endpoints, telemetry, fulfillment engine, migrations, or seeders.

Development

composer validate --strict
composer test
composer analyse
composer format:check
composer audit

Tests use mocked transports and the PHP SDK's synthetic language-neutral conformance fixture. They make no production requests. Hosted CI enforces at least 90% overall line coverage and at least 90% coverage for security-critical callback and key-cache components. Development and CI resolve cryptpays/sdk-php:^0.1.0 from Packagist.

See CONTRIBUTING.md before proposing changes. Report security issues privately as described in SECURITY.md, not through public issues.

License

MIT. See LICENSE.