Write the API client and the sign
Authentication is HTTP Basic: the user is the posId and the password is the reports key. Every important request carries a sign field: the SHA-384 hash of a JSON object with specific fields in a specific order, always ending with the CRC key.
The documentation requires the JSON_UNESCAPED_UNICODE and JSON_UNESCAPED_SLASHES flags. Without them a slash in an address or a Polish letter in a description changes the hash and the sign fails.
<?phpdeclare(strict_types=1);final class Przelewy24{ public function __construct( public readonly string $baseUrl, // https://sandbox.przelewy24.pl public readonly int $merchantId, public readonly int $posId, private string $apiKey, // reports (API) key from the panel private string $crc, // CRC key from the panel ) {} /** SHA-384 of JSON with a fixed field order, always ending with the CRC key. */ public function sign(array $fields): string { $fields['crc'] = $this->crc; return hash('sha384', json_encode($fields, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); } public function call(string $method, string $path, ?array $body = null): array { $curl = curl_init($this->baseUrl . $path); curl_setopt_array($curl, [ CURLOPT_CUSTOMREQUEST => $method, CURLOPT_USERPWD => $this->posId . ':' . $this->apiKey, CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, ]); if ($body !== null) { curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($body, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); } $raw = (string) curl_exec($curl); $status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE); curl_close($curl); return [$status, json_decode($raw, true)]; }}