PHP code example of pinvandaag / my-buckaroo-api-php

1. Go to this page and download the library: Download pinvandaag/my-buckaroo-api-php 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/ */

    

pinvandaag / my-buckaroo-api-php example snippets




use PinVandaag\BuckarooAPI\BuckarooAPIClient;

final class BuckarooController
{
    private BuckarooAPIClient $apiClient;

    public function __construct()
    {
        $this->apiClient = (new BuckarooAPIClient())
            ->configure(
                clientId: 'your-client-id',
                clientSecret: 'your-client-secret',
                baseUri: 'https://api.buckaroo.io'
            );
    }

    public function getAccessToken()
    {
        $token = $this->apiClient->getAccessToken();

        $authHeader = $token->authorizationHeader();

        print_r($token);
        print_r($authHeader);
        print_r($token->accessToken);
    }
}



use PinVandaag\BuckarooAPI\BuckarooAPIClient;

get_contents('php://input') ?: '';
$secret = getenv('BUCKAROO_WEBHOOK_SECRET') ?: '';

$headers = function_exists('getallheaders')
    ? getallheaders()
    : [];

$host = $_SERVER['HTTP_HOST'] ?? '';
$requestTarget = $_SERVER['REQUEST_URI'] ?? '';

if (!$client->validateWebhookSignature(
    rawBody: $rawBody,
    secret: $secret,
    headers: $headers,
    host: $host,
    requestTarget: $requestTarget,
)) {
    http_response_code(401);
    echo 'Invalid webhook signature';
    exit;
}

$payload = json_decode($rawBody, true);

if (!is_array($payload)) {
    http_response_code(400);
    echo 'Invalid JSON payload';
    exit;
}

$eventType = $_SERVER['HTTP_BUCK_EVENT_TYPE'] ?? '';
$idempotencyKey = $_SERVER['HTTP_IDEMPOTENCY_KEY'] ?? '';

// Recommended:
// - Store/check the idempotency key before processing.
// - Ignore duplicate webhook deliveries.
// - Handle the event based on $eventType.

switch ($eventType) {
    case 'SALE.CREATE':
        // Process sale creation event.
        break;

    case 'INSTALLATION.CREATE':
        // Process installation creation event.
        break;

    default:
        // Ignore unsupported events.
        break;
}

http_response_code(200);
echo 'OK';