PHP, Node.js & Java
Backend launch examples in PHP, Node.js, and Java, with response checks and retry guidance.
On this page
Before using these examples#
These examples send backend requests only. Replace the illustrative game ID, player, currency, and URLs with your entitled catalogue values. Reserve the starting funds and persist the idempotency key and request before dispatch. Reuse that operation record for recovery; do not generate a key inside a retry loop.
Check both HTTP status and numeric error: 0. Keep the x-request-id header. Do not expose your key or log launch URLs. These examples show request handling, not wallet persistence or automatic retries.
Launch a game#
Choose PHP, Node.js, or Java to see the same backend launch request. These are HTTP examples, not an SDK. PHP requires the cURL extension; Node.js requires native fetch; the Java fragment uses HttpClient and text blocks in your backend code.
PHP
<?php
$request = [
'method' => 'getGame', 'lang' => 'en',
'user_username' => 'player-1001', 'gameid' => '12/737',
'homeurl' => 'https://operator.example/lobby',
'cashierurl' => 'https://operator.example/cashier',
'currency' => 'USD', 'balance' => 1000,
];
// Load this operation's previously persisted key.
$operationKey = getenv('AGGREGATOR_OPERATION_KEY');
if (!$operationKey) throw new RuntimeException('Missing operation key');
$ch = curl_init('https://aggregatornetwork.com/v1/commands');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'X-API-Key: ' . getenv('AGGREGATOR_API_KEY'),
'Idempotency-Key: ' . $operationKey,
],
CURLOPT_POSTFIELDS => json_encode($request, JSON_THROW_ON_ERROR),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
]);
$raw = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$transportError = curl_error($ch);
curl_close($ch);
if ($raw === false) throw new RuntimeException('Reconcile: ' . $transportError);
$body = json_decode($raw, true, flags: JSON_THROW_ON_ERROR);
if ($status !== 200 || ($body['error'] ?? null) !== 0) {
throw new RuntimeException('Launch failed; inspect the operation record');
}
$launchUrl = $body['response']; // Pass to your authorized player securely.Node.js
const operationKey = process.env.AGGREGATOR_OPERATION_KEY;
if (!operationKey) throw new Error('Missing persisted operation key');
const response = await fetch('https://aggregatornetwork.com/v1/commands', {
method: 'POST',
headers: {
'content-type': 'application/json',
'x-api-key': process.env.AGGREGATOR_API_KEY,
'idempotency-key': operationKey,
},
body: JSON.stringify({
method: 'getGame',
lang: 'en',
user_username: 'player-1001',
gameid: '12/737',
homeurl: 'https://operator.example/lobby',
cashierurl: 'https://operator.example/cashier',
currency: 'USD',
balance: 1000,
}),
});
const requestId = response.headers.get('x-request-id');
const body = await response.json();
if (!response.ok || body.error !== 0) {
throw new Error(`Launch failed; reconcile operation, request ${requestId}`);
}
const launchUrl = body.response; // Deliver securely; do not log it.JSON.parse/response.json() is adequate for the launch URL response shown here. Monetary callback values require lossless decimal parsing.
Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
String operationKey = System.getenv("AGGREGATOR_OPERATION_KEY");
if (operationKey == null) throw new IllegalStateException("Missing operation key");
String json = """
{"method":"getGame","lang":"en","user_username":"player-1001",
"gameid":"12/737","homeurl":"https://operator.example/lobby",
"cashierurl":"https://operator.example/cashier","currency":"USD","balance":1000}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://aggregatornetwork.com/v1/commands"))
.timeout(Duration.ofSeconds(60))
.header("Content-Type", "application/json")
.header("X-API-Key", System.getenv("AGGREGATOR_API_KEY"))
.header("Idempotency-Key", operationKey)
.POST(HttpRequest.BodyPublishers.ofString(json)).build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
String requestId = response.headers().firstValue("x-request-id").orElse("");
// Parse response.body() with your JSON library. Require statusCode() == 200
// and numeric error == 0 before using response. A transport exception or
// unknown outcome requires reconciliation using the persisted operation.Recovery and wallet handling#
For a read-only Postman catalogue request, secret handling, and production prerequisites, follow the integration checklist. Postman is a request-testing tool; these PHP, Node.js, and Java examples remain backend implementations.
The gateway prepares provider authentication internally. Send only documented command fields. See validation and recovery before implementing retries. Your integration must persist wallet reservations and operation records; these examples do not implement that storage or guarantee payment settlement.