1. Go to this page and download the library: Download itsjustmoha/laravel-x402 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/ */
itsjustmoha / laravel-x402 example snippets
use Illuminate\Support\Facades\Route;
Route::get('/api/report', ReportController::class)->paid('$0.01');
use Itsjustmoha\X402\Core\Facilitator\AuthHeadersProvider;
use Itsjustmoha\X402\Core\Http\HttpRequest;
final class CdpAuthHeaders implements AuthHeadersProvider
{
public function headersFor(string $operation, HttpRequest $request): array
{
// $operation is "verify", "settle" or "supported"; $request has method + URL.
return ['Authorization' => 'Bearer ' . $this->jwtFor($request->method, $request->url)];
}
}
Event::listen(PaymentSettled::class, function (PaymentSettled $event) {
Revenue::record($event->
Route::get('/api/weather', WeatherController::class)->paid('$0.001', [
'description' => 'Current weather for a city',
'discovery' => [
'input' => ['city' => 'Berlin'], // example query params (or body for POST/PUT/PATCH)
'input_schema' => ['properties' => ['city' => ['type' => 'string']], '
text
GET /api/report -> 402, PAYMENT-REQUIRED: base64(PaymentRequired)
GET /api/report + PAYMENT-SIGNATURE: ... -> server: POST {facilitator}/verify
your controller runs
server: POST {facilitator}/settle
<- 200 + PAYMENT-RESPONSE: base64(SettlementResponse)
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.