Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.46 KB | None | 0 0
  1. <?php
  2. require_once("../config/config.php");
  3. require_once("../config/setting.php");
  4. header("Content-Type: application/json");
  5.  
  6. if (isset($_POST['key']) AND isset($_POST['action'])) {
  7. $post_key = $tur->real_escape_string(trim(stripslashes(strip_tags(htmlspecialchars($_POST['key'],ENT_QUOTES)))));
  8. $post_action = $_POST['action'];
  9. if (empty($post_key) || empty($post_action)) {
  10. $array = array("status" => false, "data" => array("msg" => "Incorrect Request"));
  11. } else {
  12. $check_user = $tur->query("SELECT * FROM users WHERE api_key = '$post_key'");
  13. $data_user = mysqli_fetch_assoc($check_user);
  14. if (mysqli_num_rows($check_user) == 1) {
  15. $username = $data_user['username'];
  16. if ($post_action == "add") {
  17. if (isset($_POST['service']) AND isset($_POST['target']) AND isset($_POST['quantity'])) {
  18. $post_service = $tur->real_escape_string(trim(stripslashes(strip_tags(htmlspecialchars($_POST['service'],ENT_QUOTES)))));
  19. $post_link = $tur->real_escape_string(trim(stripslashes(strip_tags(htmlspecialchars($_POST['target'],ENT_QUOTES)))));
  20. $post_quantity = $tur->real_escape_string(trim(stripslashes(strip_tags(htmlspecialchars($_POST['quantity'],ENT_QUOTES)))));
  21. if (empty($post_service) || empty($post_link) || empty($post_quantity)) {
  22. $array = array("status" => false, "data" => array("msg" => "Incorrect Request"));
  23. } else {
  24. $check_service = $tur->query("SELECT * FROM services WHERE sid = '$post_service' AND status = 'Active'");
  25. $data_service = mysqli_fetch_assoc($check_service);
  26. if (mysqli_num_rows($check_service) == 0) {
  27. $array = array("status" => false, "data" => array("msg" => "Service Not Found"));
  28. } else {
  29. $oid = rand(10000,99999);
  30. $rate = $data_service['price'] / 1000;
  31. $price = $rate*$post_quantity;
  32. $service = $data_service['service'];
  33. $provider = $data_service['provider'];
  34. $pid = $data_service['pid'];
  35. if ($post_quantity < $data_service['min']) {
  36. $array = array("status" => false, "data" => array("msg" => "Quantity Incorrect"));
  37. } else if ($post_quantity > $data_service['max']) {
  38. $array = array("status" => false, "data" => array("msg" => "Quantity Incorrect"));
  39. } else if ($data_user['balance'] < $price) {
  40. $array = array("status" => false, "data" => array("msg" => "Low Balance"));
  41. } else {
  42. $check_provider = $tur->query("SELECT * FROM provider WHERE code = '$provider'");
  43. $data_provider = mysqli_fetch_assoc($check_provider);
  44. $provider_key = $data_provider['api_key'];
  45. $provider_link = $data_provider['link'];
  46.  
  47. if ($provider == "MANUAL") {
  48. $api_postdata = "";
  49. $poid = $oid;
  50. } else if ($provider == "MEDAN") {
  51. $api_postdata = "api_key=$provider_key&action=order&service=$pid&data=$post_link&quantity=$post_quantity";
  52. $ch = curl_init();
  53. curl_setopt($ch, CURLOPT_URL, "$provider_link");
  54. curl_setopt($ch, CURLOPT_POST, 1);
  55. curl_setopt($ch, CURLOPT_POSTFIELDS, $api_postdata);
  56. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  57. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  58. $chresult = curl_exec($ch);
  59. curl_close($ch);
  60. $json_result = json_decode($chresult, true);
  61. }
  62.  
  63. if ($provider == "MEDAN" AND $json_result['status'] == false) {
  64. $array = array("status" => false, "data" => array("msg" => "".$json_result['data']['msg'].""));
  65. } else {
  66. if ($provider == "MEDAN") {
  67. $poid = $json_result['data']['id'];
  68. }
  69. $update_user = $tur->query("UPDATE users SET balance = balance-$price WHERE username = '$username'");
  70. $update_user = $tur->query("INSERT INTO catatan (username, note, waktu) VALUES ('$username', 'Kamu telah melakukan aktifitas Order $service', '$date $time')");
  71. if ($update_user == TRUE) {
  72. $insert_order = $tur->query("INSERT INTO hof (type, user, price) VALUES ('Sosmed', '$username', '$price')");
  73. $insert_order = $tur->query("INSERT INTO orders (oid, poid, user, service, link, quantity, price, status, date, provider, place_from) VALUES ('$oid', '$poid', '$username', '$service', '$post_link', '$post_quantity', '$price', 'Pending', '$date', '$provider', 'API')");
  74. if ($insert_order == TRUE) {
  75. $array = array("status" => true, "data" => array("id" => $oid));
  76. } else {
  77. $array = array("status" => false, "data" => array("msg" => "System Error"));
  78. }
  79. } else {
  80. $array = array("status" => false, "data" => array("msg" => "System Error"));
  81. }
  82. }
  83. }
  84. }
  85. }
  86. } else {
  87. $array = array("status" => false, "data" => array("msg" => "System Error"));
  88. }
  89. } else if ($post_action == "status") {
  90. if (isset($_POST['id'])) {
  91. $post_oid = $tur->real_escape_string(trim(stripslashes(strip_tags(htmlspecialchars($_POST['id'],ENT_QUOTES)))));
  92. $check_order = mysqli_query($db, "SELECT * FROM orders WHERE oid = '$post_oid' AND user = '$username'");
  93. $data_order = mysqli_fetch_array($check_order);
  94. if (mysqli_num_rows($check_order) == 0) {
  95. $array = array("status" => false, "data" => array("msg" => "Order Not Found"));
  96. } else {
  97. $array = array("status" => true, "data" => array("id" => $data_order['oid'], "status" => $data_order['status'], "start_count" => $data_order['start_count'], "remains" => $data_order['remains']));
  98. }
  99. } else {
  100. $array = array("status" => false, "data" => array("msg" => "Incorrect Request"));
  101. }
  102. } else if ($post_action == "services") {
  103. $check_service = $tur->query("SELECT * FROM services WHERE status = 'Active' ORDER BY sid ASC");
  104. while($row = mysqli_fetch_array($check_service)){
  105. $array = "-";
  106. $datas[] = array("sid" => $row['sid'], "category" => $row['category'], "service" => $row['service'], "note" => $row['note'], "min" => $row['min'], "max" => $row['max'], "status" => $row['status'], "price" => $row['price']);
  107. }
  108. $array = array("status" => true, "data" => $datas);
  109. } else {
  110. $array = array("status" => false, "data" => array("msg" => "Wrong Action"));
  111. }
  112. } else {
  113. $array = array("status" => false, "data" => array("msg" => "Invalid Api Key"));
  114. }
  115. }
  116. } else {
  117. $array = array("status" => false, "data" => array("msg" => "Incorrect Request"));
  118. }
  119.  
  120. $print = json_encode($array);
  121. print_r($print);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement