token = $token; $this->baseUrl = rtrim($baseUrl, '/'); $this->headers = [ 'Authorization: Bearer ' . $this->token, 'Content-Type: application/json', 'Accept: application/json', ]; } // ── Charges ── /** * Create a new payment charge */ public function createCharge(array $body = []): array { return $this->request('POST', '/charge', [], $body); } /** * Retrieve a charge by ID */ public function getCharge(string $id): array { return $this->request('GET', '/charge/' . urlencode($id) . ''); } /** * List all charges with pagination */ public function listCharges(array $query = []): array { return $this->request('GET', '/charges', $query); } // ── Refunds ── /** * Refund a charge fully or partially */ public function createRefund(array $body = []): array { return $this->request('POST', '/refund', [], $body); } // ── HTTP helpers ── private function request(string $method, string $path, array $query = [], array $body = []): array { $url = $this->baseUrl . $path; if (!empty($query)) { $url .= '?' . http_build_query($query); } $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => $method, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $this->headers, CURLOPT_TIMEOUT => 30, ]); if (!empty($body) && in_array($method, ['POST', 'PUT', 'PATCH'])) { curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); } $response = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return ['status' => $status, 'data' => json_decode($response, true)]; } }