Advertisement
Guest User

Untitled

a guest
Jan 4th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. <?php // merupakan tag pembuka php
  2. date_default_timezone_set('Asia/Jakarta');
  3. $sekarang = date("Y-m-d H:i:s");
  4. $tanggal = date("Y-m-d");
  5.  
  6.  
  7. $db_host = "localhost"; // umumnya cpanel berbayar menggunakan host yaitu localhost
  8. $db_user = "serverme_123"; // karena menggunakan xampp jadi user default db yaitu root
  9. $db_pass = "serverme_123"; // password default xampp yaitu kosong
  10. $db_name = "serverme_new"; // nama db yang digunakan/didaftarkan
  11.  
  12. $MySQLi_CON = new MySQLi ($db_host, $db_user, $db_pass, $db_name);
  13.  
  14. if($MySQLi_CON->connect_errno)
  15. {
  16. die ("KESALAHAN : ->".$MySQLi_CON->connect_errno);
  17. }
  18.  
  19.  
  20. $query = $MySQLi_CON->query("SELECT * FROM orders WHERE provider='SERVERMEDIA' AND status IN ('Pending','Processing','') ORDER BY id DESC");
  21.  
  22. class Api {
  23. public $api_url = 'https://api.servermedia.xyz/'; // API Url
  24.  
  25. public $api_key = 'mMHQY9cPITDFuA1SfqIW'; // API Key
  26.  
  27. public function order($data) {
  28. return json_decode($this->connect($this->api_url.'order/sosial-media', array_merge(array('apikeys' => $this->api_key), $data)), true);
  29. }
  30.  
  31. public function status($order_id) {
  32. return json_decode($this->connect($this->api_url.'status', array('apikeys' => $this->api_key, 'order_id' => $order_id)));
  33. }
  34.  
  35. public function services() {
  36. return json_decode($this->connect($this->api_url.'service', array('apikeys' => $this->api_key)));
  37. }
  38.  
  39. public function balance() {
  40. return json_decode($this->connect($this->api_url.'profil', array('apikeys' => $this->api_key)));
  41. }
  42.  
  43. private function connect($end_point, $post) {
  44. $_post = Array();
  45. if (is_array($post)) {
  46. foreach ($post as $name => $value) {
  47. $_post[] = $name.'='.urlencode($value);
  48. }
  49. }
  50. $ch = curl_init($end_point);
  51. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  52. curl_setopt($ch, CURLOPT_POST, 1);
  53. curl_setopt($ch, CURLOPT_HEADER, 0);
  54. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  55. if (is_array($post)) {
  56. curl_setopt($ch, CURLOPT_POSTFIELDS, join('&', $_post));
  57. }
  58. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  59. $result = curl_exec($ch);
  60. if (curl_errno($ch) != 0 && empty($result)) {
  61. $result = false;
  62. }
  63. curl_close($ch);
  64. return $result;
  65. }
  66. }
  67.  
  68.  
  69. $api = new Api();
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. while ($fetch = $query->fetch_array()) {
  78. $oid = $fetch['poid'];
  79.  
  80. $order = $api->status($oid);
  81. $target = $order['check-order']['target'];
  82. echo "<pre>";
  83. print_r($order);
  84. echo "</pre>";
  85. // ambil status
  86. $status = $order['check-order']['status'];
  87. $start_count = $order['check-order']['start_count'];
  88. $remains = $order['check-order']['remains'];
  89.  
  90.  
  91. if($status == "Pending"){
  92. $status= "Pending";
  93. } else if ($status == "Processing") {
  94. $status= "Processing";
  95. }else if ($status == "Completed") {
  96. $status= "Success";
  97. }else if ($status == "Partial") {
  98. $status= "Partial";
  99. }else if ($status == "Canceled") {
  100. $status= "Error";
  101. }else if ($status == "In progress") {
  102. $status= "Processing";
  103. }else if ($status == "") {
  104. $status= "Error";
  105. }
  106.  
  107. $update = $MySQLi_CON->query("UPDATE orders SET remains='$remains', status='$status', start_count='$start_count' WHERE poid='$oid' AND provider='SERVERMEDIA'");
  108. if($update) {
  109. echo "sukses";
  110. } else {echo "$msg -> $poid = Status : $statuse Jumlah Awal : $start_countnya Tersisa : $remains<br/>";
  111. echo "gagal";
  112. }
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement