Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php // merupakan tag pembuka php
- date_default_timezone_set('Asia/Jakarta');
- $sekarang = date("Y-m-d H:i:s");
- $tanggal = date("Y-m-d");
- $db_host = "localhost"; // umumnya cpanel berbayar menggunakan host yaitu localhost
- $db_user = "serverme_123"; // karena menggunakan xampp jadi user default db yaitu root
- $db_pass = "serverme_123"; // password default xampp yaitu kosong
- $db_name = "serverme_new"; // nama db yang digunakan/didaftarkan
- $MySQLi_CON = new MySQLi ($db_host, $db_user, $db_pass, $db_name);
- if($MySQLi_CON->connect_errno)
- {
- die ("KESALAHAN : ->".$MySQLi_CON->connect_errno);
- }
- $query = $MySQLi_CON->query("SELECT * FROM orders WHERE provider='SERVERMEDIA' AND status IN ('Pending','Processing','') ORDER BY id DESC");
- class Api {
- public $api_url = 'https://api.servermedia.xyz/'; // API Url
- public $api_key = 'mMHQY9cPITDFuA1SfqIW'; // API Key
- public function order($data) {
- return json_decode($this->connect($this->api_url.'order/sosial-media', array_merge(array('apikeys' => $this->api_key), $data)), true);
- }
- public function status($order_id) {
- return json_decode($this->connect($this->api_url.'status', array('apikeys' => $this->api_key, 'order_id' => $order_id)));
- }
- public function services() {
- return json_decode($this->connect($this->api_url.'service', array('apikeys' => $this->api_key)));
- }
- public function balance() {
- return json_decode($this->connect($this->api_url.'profil', array('apikeys' => $this->api_key)));
- }
- 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, true);
- 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;
- }
- }
- $api = new Api();
- while ($fetch = $query->fetch_array()) {
- $oid = $fetch['poid'];
- $order = $api->status($oid);
- $target = $order['check-order']['target'];
- echo "<pre>";
- print_r($order);
- echo "</pre>";
- // ambil status
- $status = $order['check-order']['status'];
- $start_count = $order['check-order']['start_count'];
- $remains = $order['check-order']['remains'];
- if($status == "Pending"){
- $status= "Pending";
- } else if ($status == "Processing") {
- $status= "Processing";
- }else if ($status == "Completed") {
- $status= "Success";
- }else if ($status == "Partial") {
- $status= "Partial";
- }else if ($status == "Canceled") {
- $status= "Error";
- }else if ($status == "In progress") {
- $status= "Processing";
- }else if ($status == "") {
- $status= "Error";
- }
- $update = $MySQLi_CON->query("UPDATE orders SET remains='$remains', status='$status', start_count='$start_count' WHERE poid='$oid' AND provider='SERVERMEDIA'");
- if($update) {
- echo "sukses";
- } else {echo "$msg -> $poid = Status : $statuse Jumlah Awal : $start_countnya Tersisa : $remains<br/>";
- echo "gagal";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement