Most PHP payment integrations fail on one line: reading the body after PHP has already parsed it. GaaPay signs the raw body, so file_get_contents("php://input") is the only correct source.
1 · Create an order
<?php
$path = "/api/v1/orders";
$raw = json_encode([
"amount" => number_format($amount, 2, ".", ""),
"merchant_order_ref" => $ref,
], JSON_UNESCAPED_SLASHES);
$ts = (string) time();
$nonce = bin2hex(random_bytes(16));
$payload = $ts."\n".$nonce."\nPOST\n".$path."\n".$raw;
$sig = hash_hmac("sha256", $payload, getenv("GAAPAY_SECRET"));
$ch = curl_init("https://api.gaapay.com".$path);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $raw,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"content-type: application/json",
"x-gaapay-app: ".getenv("GAAPAY_APP"),
"x-gaapay-timestamp: ".$ts,
"x-gaapay-nonce: ".$nonce,
"x-gaapay-signature: ".$sig,
],
]);
$result = json_decode(curl_exec($ch), true);
header("Location: ".$result["checkout_url"]);2 · Verify the IPN
<?php
$raw = file_get_contents("php://input");
$ts = $_SERVER["HTTP_X_GAAPAY_TIMESTAMP"] ?? "";
$sig = $_SERVER["HTTP_X_GAAPAY_SIGNATURE"] ?? "";
$expected = "v1=".hash_hmac("sha256", $ts.".".$raw, getenv("GAAPAY_WEBHOOK_SECRET"));
if (!hash_equals($expected, $sig)) { http_response_code(401); exit; }
if (abs(time() - (int) $ts) > 300) { http_response_code(401); exit; }
$event = json_decode($raw, true);
if ($event["type"] === "payment.succeeded") {
fulfil($event["data"]["order_id"]);
}
http_response_code(200);application/json differently depending on SAPI; php://input is stable. If you use a framework, grab the raw body before its middleware touches it.PHP pitfalls
json_encodeescapes slashes by default; useJSON_UNESCAPED_SLASHESand sign exactly what you send.hash_equalsbefore any comparison —==leaks timing and accepts type juggling.- Do not
urldecodeor re-encode the body; sign the bytes. - Behind a proxy, confirm
HTTP_X_GAAPAY_*headers are forwarded; some hosts strip unknownx-headers.
PHP questions
Is there a Laravel package?
No official package. The two snippets above fit a controller and a route; a package would only hide the two lines that matter.
How do I avoid duplicate delivery?
Store x-gaapay-event-id with a unique index. If the insert conflicts, return 200 and skip the work.
Can I run this on shared hosting?
Yes, if outbound HTTPS and hash_hmac are available (both are standard). The webhook route must be reachable from the internet.
Test the signature flow
The sandbox is the default. Create an app, create an order, watch a webhook arrive — then flip one environment variable.