$value) { if (is_array($value) || is_object($value)) { throw new InvalidArgumentException('Only scalar values are supported'); } $parts[] = $key . '=' . (string)$value; } return strtoupper(hash('sha256', strtolower(implode('&', $parts) . '&HashKey=' . $apiKey))); } // Usage: set STARLINK_MERCHANT_CODE and STARLINK_API_KEY in your server environment. // $params = ['merchantCode' => getenv('STARLINK_MERCHANT_CODE'), 't' => time()]; // $params['EncryptValue'] = starlinkSign($params, getenv('STARLINK_API_KEY')); // POST JSON to https://api.xltd8899.com/api/pay/products // Callback: form data from $_POST, verified with your merchant key. // $received = $_POST['EncryptValue'] ?? ''; // if (!hash_equals(starlinkSign($_POST, getenv('STARLINK_API_KEY')), strtoupper($received))) { // http_response_code(401); exit('invalid signature'); // } // Then match mchOrderId, compare amount as a decimal, and check OrderStatusId == 2. // Persist the payment atomically and idempotently before acknowledging with HTTP 200 "ok". // Never acknowledge invalid data as a successful payment.