PHP code example of petzsch / laravel-btcpay

1. Go to this page and download the library: Download petzsch/laravel-btcpay library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

petzsch / laravel-btcpay example snippets


use Petzsch\LaravelBtcpay\Support\BTCPay;
use BTCPayServer\Util\PreciseNumber;

/** @var \BTCPayServer\Client\Invoice $invoiceClient */
$invoiceClient = BTCPay::invoice();

$invoiceClient->createInvoice(
    storeId: 'your-store-id',
    currency: 'USD',
    amount: new \BTCPayServer\Util\PreciseNumber('100.00'),
);

// or use the shorthand method provided by the package

$invoice = BTCPay::createInvoice(
    amount: 100.00,
    currency: 'USD',
);

use Petzsch\LaravelBtcpay\Http\Controllers\WebhookController;

Route::post('/your-custom-webhook-path', [WebhookController::class, 'handle'])
    ->name('btcpay.webhook')
    ->middleware(\Petzsch\LaravelBtcpay\Http\Middleware\ValidateWebhookSignature::class);

use Petzsch\LaravelBtcpay\Events\WebhookReceived;
use Petzsch\LaravelBtcpay\Enums\WebhookType;
use Illuminate\Support\Arr;

public function handle(WebhookReceived $event): void
{
    match($event->webhook->type) {
        WebhookType::InvoiceSettled => $this->handleInvoiceSettled($event),
        // handle other webhook types...
        default => null,
    };
}

protected function handleInvoiceSettled(WebhookReceived $event): void
{
    // do something with the settled invoice
}
bash
php artisan vendor:publish --provider="Petzsch\LaravelBtcpay\BTCPayServiceProvider"
bash
php artisan make:listener BTCPayWebhookListener --event=\Petzsch\LaravelBtcpay\Events\WebhookReceived