0% found this document useful (0 votes)
3 views2 pages

PHP API Class for Profile and Orders

The document is a PHP class named 'api' that provides methods to interact with an API, including retrieving user profiles, available services, placing orders, and checking order statuses. It utilizes cURL for making HTTP POST requests to specified endpoints with necessary authentication details. Example usage of the class is also provided, demonstrating how to check profiles, list services, and place orders with custom comments.

Uploaded by

gdridho50
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

PHP API Class for Profile and Orders

The document is a PHP class named 'api' that provides methods to interact with an API, including retrieving user profiles, available services, placing orders, and checking order statuses. It utilizes cURL for making HTTP POST requests to specified endpoints with necessary authentication details. Example usage of the class is also provided, demonstrating how to check profiles, list services, and place orders with custom comments.

Uploaded by

gdridho50
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

<?

php
class api {
public $api_url = 'apiurl'; // API URL
public $api_id = 'apiid'; // API ID
public $api_key = 'apikey'; // API KEY

public function profile() {


return json_decode($this->connect($this->api_url.'profile',
array('api_id' => $this->api_id, 'api_key' => $this->api_key)));
}

public function services() {


return json_decode($this->connect($this->api_url.'services',
array('api_id' => $this->api_id, 'api_key' => $this->api_key)));
}

public function order($data) {


return json_decode($this->connect($this->api_url.'order',
array_merge(array('api_id' => $this->api_id, 'api_key' => $this->api_key),
$data)));
}

public function status($order_id) {


return json_decode($this->connect($this->api_url.'status',
array('api_id' => $this->api_id, 'api_key' => $this->api_key, 'id' => $order_id)));
}

public function refill($order_id) {


return json_decode($this->connect($this->api_url.'refill',
array('api_id' => $this->api_id, 'api_key' => $this->api_key, 'id_order' =>
$order_id)));
}

public function refill_status($refill_id) {


return json_decode($this->connect($this->api_url.'refill_status',
array('api_id' => $this->api_id, 'api_key' => $this->api_key, 'id_refill' =>
$refill_id)));
}

private function connect($end_point, $post) {


$_post = Array();
if (is_array($post)) {
foreach ($post as $name => $value) {
$_post[] = $name.'='.urlencode($value);
}
}
$ch = curl_init($end_point);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if (is_array($post)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, join('&', $_post));
}
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE
5.01; Windows NT 5.0)');
$result = curl_exec($ch);
if (curl_errno($ch) != 0 && empty($result)) {
$result = false;
}
curl_close($ch);
return $result;
}
}

// contoh penggunaan

$api = new api();

// cek profil
$profile = $api->profile();
print_r($profile);
print('<br /><br />');

// daftar layanan
$services = $api->services();
print_r($services);
print('<br /><br />');

// membuat pesanan
$order = $api->order(array(
'service' => 1, // id layanan
'target' => 'herusuandanaa', // target pesanan
'quantity' => 100 // jumlah pesan
));
print_r($order);
print('<br /><br />');

// membuat pesanan custom komentar


$order = $api->order(array(
'service' => 1, // id layanan
'target' => 'linkpost', // target pesanan
'custom_comments' => "wow keren\r\nkeren banget" // daftar komentar
'custom_link' => "linkpost" // kustom link
));
print_r($order);
print('<br /><br />');

// cek status pesanan


$status = $api->status('123'); // 123 = id pesanan
print_r($status);

You might also like