Every site that accepts online payments exposes an endpoint where the payment system sends notifications. When a customer confirms a payment, the Click or Payme server calls that URL and the site marks the order as paid. The endpoint is public, so anyone can send a request to it. If the site does not verify that the request really came from the payment system, an attacker can impersonate it with a single curl command and close orders without paying.
Example: a clothing shop and a forged notification
An online clothing shop in Fergana takes Click payments. To launch quickly, the developer's callback handler only checks that error equals zero. One day the warehouse ships several large orders, but the Click dashboard shows no matching income. The log reveals well-formed requests from an unknown IP whose signature was never checked. The shop lost both goods and money because of one unchecked field.
Three mandatory checks
Verify the source with the signature or authorisation header; verify that the order exists and the amount matches your database exactly; and handle repeats, because the same notification may arrive more than once and must not pay an order or top up a balance twice. Skip any one and the protection breaks.
Click: checking sign_string
Click sends sign_string, an MD5 hash of request fields plus your secret key. Per the documented formula, the Complete step (action = 1) also includes merchant_prepare_id. Always confirm the field order against Click's official documentation:
<?php
$secret = getenv('CLICK_SECRET_KEY');
$p = fn(string $k): string => (string)($_POST[$k] ?? '');
$action = $p('action');
$base = $p('click_trans_id') . $p('service_id') . $secret . $p('merchant_trans_id');
if ($action === '1') {
$base .= $p('merchant_prepare_id');
}
$base .= $p('amount') . $action . $p('sign_time');
if (!hash_equals(md5($base), $p('sign_string'))) {
header('Content-Type: application/json');
echo json_encode(['error' => -1, 'error_note' => 'SIGN CHECK FAILED']);
exit;
}
hash_equals compares in constant time, and the secret lives in an environment variable rather than in code.
Payme: checking the Authorization header
Payme Merchant API sends JSON-RPC requests with an Authorization header carrying the Paycom login and your cashbox key in Base64:
<?php
$req = json_decode(file_get_contents('php://input'), true) ?: [];
$auth = $_SERVER['HTTP_AUTHORIZATION'] ?? '';
$expected = 'Basic ' . base64_encode('Paycom:' . getenv('PAYME_KEY'));
header('Content-Type: application/json');
if (!hash_equals($expected, $auth)) {
echo json_encode([
'jsonrpc' => '2.0',
'id' => $req['id'] ?? null,
'error' => ['code' => -32504, 'message' => 'Insufficient privilege'],
]);
exit;
}
Under FastCGI on shared hosting the header may never reach PHP. Pass it through in .htaccess:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Payme sends amounts in tiyin, so multiply your sum amount by 100 before comparing.
Amount and idempotency
$stmt = $pdo->prepare(
"UPDATE orders SET status = 'paid', paid_at = NOW()
WHERE id = ? AND status = 'pending' AND amount = ?"
);
$stmt->execute([$orderId, $amount]);
if ($stmt->rowCount() === 0) {
// not found, wrong amount or already paid: check and reply accordingly
}
A repeated notification changes nothing and you return the appropriate "already done" response. For balance top-ups, store the transaction ID under a unique key.
Extra layers and common mistakes
Never mark orders paid from the customer's return page, which anyone can open by hand. An IP allow list from the provider is a useful extra but no substitute for signatures. Log every request and response, never the secret. Serve the callback over HTTPS only; the free Let's Encrypt certificate on sayt.uz hosting covers that. Finally, send yourself a request with a wrong signature: the order must stay unpaid and the response must be an error.