PHP code example of ridebuilder / affiliate

1. Go to this page and download the library: Download ridebuilder/affiliate 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/ */

    

ridebuilder / affiliate example snippets


use RideBuilder\Affiliate\{RideBuilderClient, Capture, CheckoutInput};

// 1. On landing, read a validated click_id off the request URL and persist it onto YOUR cart record.
$clickId = Capture::fromUrl($_SERVER['REQUEST_URI']);
if ($clickId !== null) {
    $cart->ridebuilderClickId = $clickId;
}

// 2. At order time, send the postback from your backend.
$rb = new RideBuilderClient(apiKey: getenv('RIDEBUILDER_API_KEY'));
$rb->reportCheckout(new CheckoutInput(
    orderId: $order->id,
    subtotal: '199.99',   // major units; string keeps it exact
    currency: 'USD',
    clickId: $order->ridebuilderClickId,
));

// Same registrable domain — the cookie rides along; read it off the Cookie header:
$clickId = Capture::fromCookieHeader($_SERVER['HTTP_COOKIE'] ?? null);

// Cross-domain / mobile — the frontend forwards it in the checkout call:
$clickId = Capture::fromHeaders(getallheaders());   // default header: X-RideBuilder-Click-Id

$rb->reportReturn(new ReturnInput(
    returnId: $refund->id, orderId: $order->id, refundAmount: '49.95', currency: 'USD',
));

$rb = new RideBuilderClient(apiKey: $apiKey, environment: 'production'); // or 'sandbox'

$reg = $rb->register();   // handshake on install/startup; returns a stable integration id
$rb->verify();            // deploy/CI self-test — throws RideBuilderException on a bad/rotated key
$rb->heartbeat();         // periodic liveness (call from cron; PHP has no persistent process)

new RideBuilderClient(
    apiKey: $key,
    baseUrl: null,          // defaults to https://api.ridebuilder.com/v1
    maxRetries: 3,          // retries on network errors, timeouts, 5xx, 429
    timeoutMs: 10000,       // per-attempt timeout
    environment: 'production',
    transport: null,        // inject a RideBuilder\Affiliate\Transport\Transport (e.g. wrap a PSR-18 client)
);
bash
php tests/conformance.php   # the shared cross-language fixtures
php tests/unit.php          # validation, capture, money, retry/error, identity