1. Go to this page and download the library: Download devmatchable/whop-php-sdk 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/ */
devmatchable / whop-php-sdk example snippets
use Matchable\Whop\WhopApiClient;
use Symfony\Component\HttpClient\Psr18Client;
$client = new WhopApiClient(
httpClient: new Psr18Client(),
apiKey: $_ENV['WHOP_API_KEY'],
);
// Methods that map to a typed DTO return it directly:
$company = $client->companies->get('biz_xxxxxxxx');
echo $company->name;
// Methods without a DTO return the decoded response array:
$list = $client->companies->list(['page' => 1]);
use Matchable\Whop\Exception\WhopException;
try {
$payment = $client->payments->get('pay_xxxxxxxx');
} catch (WhopException $e) {
// always safe to catch here
echo $e->getMessage();
}
use Matchable\Whop\Exception\WhopApiException;
use Matchable\Whop\Exception\TransportException;
use Matchable\Whop\Exception\WhopException;
try {
$payment = $client->payments->get('pay_xxxxxxxx');
} catch (WhopApiException $e) {
// Non-2xx response from the Whop API
echo $e->statusCode; // int — HTTP status code
print_r($e->responseBody); // array — decoded response body
} catch (TransportException $e) {
// Network-level failure (DNS, connection refused, etc.)
echo $e->getMessage();
} catch (WhopException $e) {
// Anything else: SerializationException, MissingArgumentsException
echo $e->getMessage();
}
public function __construct(
ClientInterface $httpClient, // PSR-18 client — = 'https://api.whop.com/api/v1', // production default
?RequestFactoryInterface $requestFactory = null, // auto-discovered when null
?StreamFactoryInterface $streamFactory = null, // auto-discovered when null
)
$client = new WhopApiClient(
httpClient: new Psr18Client(),
apiKey: $_ENV['WHOP_SANDBOX_API_KEY'],
baseUrl: 'https://sandbox-api.whop.com/api/v1',
);
use Matchable\Whop\Exception\WebhookVerificationException;
use Matchable\Whop\Webhook\WebhookVerifier;
$verifier = new WebhookVerifier(webhookSecret: $_ENV['WHOP_WEBHOOK_SECRET']);
// From raw body and headers:
try {
$verifier->verify($rawBody, $requestHeaders);
} catch (WebhookVerificationException $e) {
// signature mismatch, stale timestamp, or missing headers
http_response_code(400);
exit;
}
// From a PSR-7 request object:
$verifier->verifyRequest($psr7Request);