1. Go to this page and download the library: Download iplaygames/sdk-wrapper-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/ */
iplaygames / sdk-wrapper-php example snippets
use IPlayGamesApiClient\Client;
$client = new Client([
'api_key' => 'your-api-key',
'base_url' => 'https://api.iplaygames.ai',
]);
// Get games
$response = $client->games()->list(['currency' => 'USD']);
if ($response['success']) {
foreach ($response['games'] as $game) {
echo $game['title'] . "\n";
}
}
// Start a game session
$response = $client->sessions()->start([
'game_id' => 123,
'player_id' => 'player_456',
'currency' => 'USD',
'country_code' => 'US',
'ip_address' => '192.168.1.1',
]);
if ($response['success']) {
// Redirect player to game
header("Location: " . $response['game_url']);
}
// Start multi-session
$multiResponse = $client->multiSession()->start([
'player_id' => 'player_456',
'currency' => 'USD',
'country_code' => 'US',
'ip_address' => $_SERVER['REMOTE_ADDR'],
'device' => 'mobile',
'game_ids' => ['123', '456', '789'], // Optional: specific games
]);
if ($multiResponse['success']) {
echo "Swipe URL: " . $multiResponse['swipe_url'] . "\n";
echo "Total Games: " . $multiResponse['total_games'] . "\n";
// Get iframe HTML to embed the swipe UI
echo $client->multiSession()->getIframe($multiResponse['swipe_url'], [
'width' => '100%',
'height' => '100vh',
'id' => 'game-swiper',
]);
}
// Get status
$statusResponse = $client->multiSession()->status($multiResponse['multi_session_id']);
// End when player leaves
$endResponse = $client->multiSession()->end($multiResponse['multi_session_id']);
use IPlayGamesApiClient\Client;
use IPlayGamesApiClient\Webhooks\WebhookHandler;
class WebhookController
{
private Client $client;
public function __construct()
{
$this->client = new Client([
'api_key' => env('GAMEHUB_API_KEY'),
'webhook_secret' => env('GAMEHUB_WEBHOOK_SECRET'),
]);
}
public function handle(Request $request)
{
$payload = $request->getContent();
$signature = $request->header('X-Signature');
// Verify signature
$handler = $this->client->webhooks();
if (!$handler->verify($payload, $signature)) {
return response()->json(['error' => 'Invalid signature'], 401);
}
// Parse webhook
$webhook = $handler->parse($payload);
// Handle by type
switch ($webhook->type) {
case WebhookHandler::TYPE_AUTHENTICATE:
return $this->authenticate($webhook);
case WebhookHandler::TYPE_BALANCE_CHECK:
return $this->getBalance($webhook);
case WebhookHandler::TYPE_BET:
return $this->processBet($webhook);
case WebhookHandler::TYPE_WIN:
return $this->processWin($webhook);
case WebhookHandler::TYPE_ROLLBACK:
return $this->processRollback($webhook);
case WebhookHandler::TYPE_REWARD:
return $this->processReward($webhook);
}
}
private function authenticate($webhook)
{
$player = Player::find($webhook->playerId);
if (!$player) {
return response()->json(
$this->client->webhooks()->playerNotFoundResponse()
);
}
$balance = $player->getBalance($webhook->currency);
return response()->json(
$this->client->webhooks()->successResponse($balance, [
'player_name' => $player->name,
])
);
}
private function getBalance($webhook)
{
$player = Player::find($webhook->playerId);
if (!$player) {
return response()->json(
$this->client->webhooks()->playerNotFoundResponse()
);
}
return response()->json(
$this->client->webhooks()->successResponse(
$player->getBalance($webhook->currency)
)
);
}
private function processBet($webhook)
{
$player = Player::find($webhook->playerId);
$balance = $player->getBalance($webhook->currency);
$betAmount = $webhook->getAmountInDollars();
// Check funds
if ($balance < $betAmount) {
return response()->json(
$this->client->webhooks()->insufficientFundsResponse($balance)
);
}
// Check idempotency
if (Transaction::where('external_id', $webhook->transactionId)->exists()) {
return response()->json(
$this->client->webhooks()->alreadyProcessedResponse($balance)
);
}
// Process bet
DB::transaction(function () use ($player, $webhook, $betAmount) {
$player->debit($betAmount, $webhook->currency);
Transaction::create([
'external_id' => $webhook->transactionId,
'player_id' => $webhook->playerId,
'type' => 'bet',
'amount' => $betAmount,
'currency' => $webhook->currency,
]);
});
return response()->json(
$this->client->webhooks()->successResponse(
$player->fresh()->getBalance($webhook->currency)
)
);
}
private function processWin($webhook)
{
$player = Player::find($webhook->playerId);
$winAmount = $webhook->getAmountInDollars();
// Check idempotency
if (Transaction::where('external_id', $webhook->transactionId)->exists()) {
return response()->json(
$this->client->webhooks()->alreadyProcessedResponse(
$player->getBalance($webhook->currency)
)
);
}
// Process win
DB::transaction(function () use ($player, $webhook, $winAmount) {
$player->credit($winAmount, $webhook->currency);
Transaction::create([
'external_id' => $webhook->transactionId,
'player_id' => $webhook->playerId,
'type' => 'win',
'amount' => $winAmount,
'currency' => $webhook->currency,
]);
});
return response()->json(
$this->client->webhooks()->successResponse(
$player->fresh()->getBalance($webhook->currency)
)
);
}
private function processRollback($webhook)
{
// Find original transaction
$original = Transaction::where('external_id', $webhook->get('original_transaction_id'))->first();
if (!$original) {
// Transaction not found - might not have been processed
$player = Player::find($webhook->playerId);
return response()->json(
$this->client->webhooks()->successResponse(
$player->getBalance($webhook->currency)
)
);
}
// Reverse the transaction
$player = Player::find($webhook->playerId);
if ($original->type === 'bet') {
$player->credit($original->amount, $webhook->currency);
} else {
$player->debit($original->amount, $webhook->currency);
}
$original->update(['status' => 'rolled_back']);
return response()->json(
$this->client->webhooks()->successResponse(
$player->fresh()->getBalance($webhook->currency)
)
);
}
private function processReward($webhook)
{
$player = Player::find($webhook->playerId);
$rewardAmount = $webhook->getAmountInDollars();
$player->credit($rewardAmount, $webhook->currency);
return response()->json(
$this->client->webhooks()->successResponse(
$player->fresh()->getBalance($webhook->currency)
)
);
}
}
$webhook->type; // 'bet', 'win', 'rollback', 'reward', 'authenticate', 'balance_check'
$webhook->playerId; // Player's ID in your system
$webhook->currency; // 'USD', 'EUR', etc.
$webhook->gameId; // Game ID (nullable)
$webhook->gameType; // 'slot', 'live', 'table', etc.
$webhook->timestamp; // ISO 8601 timestamp
$webhook->transactionId; // Unique transaction ID
$webhook->amount; // Amount in cents
$webhook->getAmountInDollars(); // Amount in dollars
$webhook->sessionId; // Game session ID
$webhook->roundId; // Game round ID
$webhook->isFreespin; // Is this a freespin round?
$webhook->freespinId; // Freespin campaign ID
$webhook->freespinTotal; // Total freespins awarded
$webhook->freespinsRemaining; // Remaining freespins
$webhook->freespinRoundNumber; // Current spin number
$webhook->freespinTotalWinnings; // Cumulative winnings
$response = $client->sessions()->start([
'game_id' => 123,
'player_id' => 'player_456',
'currency' => 'USD',
'country_code' => 'US',
'ip_address' => '192.168.1.1',
]);
if (!$response['success']) {
echo "Error: " . $response['error'];
return;
}
// Use the data
echo "Session ID: " . $response['session_id'];
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.