fork download
  1. <?php
  2.  
  3.  
  4. class testSandoog
  5. {
  6. private $token;
  7.  
  8. public function auth()
  9. {
  10. $url = "https://i...content-available-to-author-only...g.net/auth";
  11. $apiKey = "1fBlWHGUXQ6Cf9uj1nmheMDlQ6YWAdqtiLTdjgxth9c_t2";
  12.  
  13. $ch = curl_init($url);
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15. curl_setopt($ch, CURLOPT_POST, true);
  16. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  17. "Api-Key: $apiKey"
  18. ]);
  19. curl_setopt($ch, CURLOPT_POSTFIELDS, "");
  20.  
  21. $response = curl_exec($ch);
  22.  
  23. if (curl_errno($ch)) {
  24. echo "Auth cURL Error: " . curl_error($ch);
  25. curl_close($ch);
  26. return false;
  27. }
  28.  
  29. curl_close($ch);
  30.  
  31. $data = json_decode($response, true);
  32. if (isset($data['access_token'])) {
  33. $this->token = $data['access_token'];
  34. return $this->token;
  35. }
  36.  
  37. echo "Auth failed: " . $response;
  38. return false;
  39. }
  40.  
  41. public function order()
  42. {
  43. if (!$this->token) {
  44. echo "No token found. Please authenticate first.";
  45. return;
  46. }
  47.  
  48. $url = "https://i...content-available-to-author-only...g.net/orders";
  49.  
  50. $payload = [
  51. "customer" => [
  52. "name" => "saadeh temp ttttt",
  53. "email" => "temp7444111222@temp.com",
  54. "phone" => "7444111222",
  55. "second_phone" => "",
  56. "address" => "Sulaymaniyah, aa, aa",
  57. "state" => "Baghdad",
  58. "latitude" => 123,
  59. "longitude" => 123
  60. ],
  61. "delivery" => [
  62. "delivery_type" => "Standard",
  63. "delivery_region" => "Center",
  64. "delivery_items" => [
  65. [
  66. "sku" => "test_sku",
  67. "quantity" => 1
  68. ]
  69. ]
  70. ],
  71. "payment" => [
  72. "lines" => [
  73. [
  74. "type" => "Cash",
  75. "value" => 5000,
  76. "currency" => "IraqDinar",
  77. "is_paid" => false
  78. ]
  79. ],
  80. "total_price" => 5000,
  81. "payment_charge_type" => "Customer",
  82. "amount_include_delivery_charge" => true
  83. ],
  84. "entity_id" => "ent_u4qompmtje5ethqgpmlqit6zfm",
  85. "notes" => "testttt",
  86. "external_reference" => "000000971"
  87. ];
  88.  
  89. $ch = curl_init($url);
  90. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  91. curl_setopt($ch, CURLOPT_POST, true);
  92. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  93. "Content-Type: application/json",
  94. "Authorization: Bearer " . $this->token
  95. ]);
  96. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
  97.  
  98. $response = curl_exec($ch);
  99.  
  100. if (curl_errno($ch)) {
  101. echo "Order cURL Error: " . curl_error($ch);
  102. } else {
  103. echo "Order Response: " . $response;
  104. }
  105.  
  106. curl_close($ch);
  107. }
  108. }
  109.  
  110. $testSandoog = new testSandoog();
  111. //$testSandoog->order();
  112. if ($testSandoog->auth()) {
  113. $testSandoog->order();
  114. }
  115.  
Success #stdin #stdout 0.04s 26272KB
stdin
Standard input is empty
stdout
Auth cURL Error: Could not resolve host: iq.api.sandbox.sandoog.net