$this->api_key, 'action' => 'add'], $data); return json_decode((string)$this->connect($post)); } /** Get order status */ public function status($order_id) { return json_decode( $this->connect([ 'key' => $this->api_key, 'action' => 'status', 'order' => $order_id ]) ); } /** Get orders status */ public function multiStatus($order_ids) { return json_decode( $this->connect([ 'key' => $this->api_key, 'action' => 'status', 'orders' => implode(",", (array)$order_ids) ]) ); } /** Get services */ public function services() { return json_decode( $this->connect([ 'key' => $this->api_key, 'action' => 'services', ]) ); } /** Create refill */ public function refill($orderId) { return json_decode( $this->connect([ 'key' => $this->api_key, 'action' => 'refill', 'order' => $orderId, ]) ); } /** Create multiple refill */ public function multiRefill(array $orderIds) { return json_decode( $this->connect([ 'key' => $this->api_key, 'action' => 'refill', 'orders' => implode(',', $orderIds), ]), true ); } /** Get refill status */ public function refillStatus($refillId) { return json_decode( $this->connect([ 'key' => $this->api_key, 'action' => 'refill_status', 'refill' => $refillId, ]) ); } /** Get multiple refill status */ public function multiRefillStatus(array $refillIds) { return json_decode( $this->connect([ 'key' => $this->api_key, 'action' => 'refill_status', 'refills' => implode(',', $refillIds), ]), true ); } /** Cancel orders */ public function cancel(array $orderIds) { return json_decode( $this->connect([ 'key' => $this->api_key, 'action' => 'cancel', 'orders' => implode(',', $orderIds), ]), true ); } /** Get balance */ public function balance() { return json_decode( $this->connect([ 'key' => $this->api_key, 'action' => 'balance', ]) ); } private function connect($post) { $_post = []; if (is_array($post)) { foreach ($post as $name => $value) { $_post[] = $name . '=' . urlencode($value); } } $ch = curl_init($this->api_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); if (is_array($post)) { curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); } $result = curl_exec($ch); if (curl_errno($ch) != 0 && empty($result)) { $result = false; } curl_close($ch); return $result; } } // Examples $api = new Api(); $services = $api->services(); // Return all services $balance = $api->balance(); // Return account balance // Add an order $order = $api->order(['service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100]); $status = $api->status($order->order); // Return status, charge, remains, start count, currency $statuses = $api->multiStatus([1, 2, 3]); // Return status for several orders at once $refill = $api->refill($order->order); // Request a refill for one order $refillStatus = $api->refillStatus($refill->refill); // Check that refill's status $cancel = $api->cancel([1, 2]); // Request cancellation for one or more orders