diff --git a/app/api/premium/approveRequest.php b/app/api/premium/approveRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..c0e6783bb030c4895147e12d4e2d5a852800ffb8 --- /dev/null +++ b/app/api/premium/approveRequest.php @@ -0,0 +1,59 @@ +<?php + +require_once __DIR__ . '/../../../config/config.php'; + +if (isset($_ENV['SOAP_URL'])) { + $url = $_ENV['SOAP_URL']; +} else if (isset($_ENV['SOLO_DOCKER'])) { + $url = "http://host.docker.internal:8888/ws/subscription"; +} else { + $url = "http://localhost:8888/ws/subscription"; +} +$id = $_POST['user_id']; +$request_param = '<?xml version="1.0" encoding="utf-8"?> +<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> +<soap:Body> + <approveRequest xmlns="http://services.appnote/"> + <arg0 xmlns="">'. $id . '</arg0> + <arg1 xmlns="">'. $_ENV['REST_API_KEY'] . '</arg1> + </approveRequest> +</soap:Body> +</soap:Envelope> +'; + +printf("ppp"); +printf($_ENV['REST_API_KEY']); +printf($id); +printf("ppp"); + +$headers = array( + "Content-Type: text/xml;charset=\"utf-8\"", + 'Content-Length: ' .strlen($request_param), + 'X-API-Key: ' . $_ENV['SOAP_API_KEY'] +); + +$ch = curl_init(); +curl_setopt($ch, CURLOPT_POST, true); +curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); +curl_setopt($ch, CURLOPT_POSTFIELDS, $request_param); +curl_setopt($ch, CURLOPT_URL, $url); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + +$response = curl_exec($ch); +curl_close($ch); +if ($response === FALSE) { + printf("CURL error (#%d): %s<br>\n", curl_errno($ch), + htmlspecialchars(curl_error($ch))); +} +$response1 = str_replace('<?xml version=\'1.0\' encoding=\'UTF-8\'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:approveRequestResponse xmlns:ns2="http://services.appnote/"><return>',"",$response); +$response2 = str_replace("</return></ns2:approveRequestResponse></S:Body></S:Envelope>","",$response1); +printf($response); + +$obj = json_decode($response2); +$data = $obj->data; +// $row_count = 0; +// for ($i = 0; $i < count($data); $i++) { +// $row_count += $subscription_model->upsertSubscription($data[$i]->creator_id, $data[$i]->subscriber_id, $data[$i]->status); +// } +http_response_code(200); +echo json_encode($data); \ No newline at end of file diff --git a/app/api/premium/getAllRequest.php b/app/api/premium/getAllRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..4e8ef62037069525f34225863c77a81f8701b846 --- /dev/null +++ b/app/api/premium/getAllRequest.php @@ -0,0 +1,67 @@ +<?php + +require_once __DIR__ . '/../../../config/config.php'; + +if (isset($_ENV['SOAP_URL'])) { + $url = $_ENV['SOAP_URL']; +} else if (isset($_ENV['SOLO_DOCKER'])) { + $url = "http://host.docker.internal:8888/ws/subscription"; +} else { + $url = "http://localhost:8888/ws/subscription"; +} +$request_param = '<?xml version="1.0" encoding="utf-8"?> +<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> +<soap:Body> + <getAllRequest xmlns="http://services.appnote/"> + <arg0 xmlns="">'. $_ENV['REST_API_KEY'] . '</arg0> + </getAllRequest> +</soap:Body> +</soap:Envelope> +'; + +$headers = array( + "Content-Type: text/xml;charset=\"utf-8\"", + 'Content-Length: ' .strlen($request_param), + 'X-API-Key: ' . $_ENV['SOAP_API_KEY'] +); + +$ch = curl_init(); +curl_setopt($ch, CURLOPT_POST, true); +curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); +curl_setopt($ch, CURLOPT_POSTFIELDS, $request_param); +curl_setopt($ch, CURLOPT_URL, $url); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + +$response = curl_exec($ch); +curl_close($ch); +if ($response === FALSE) { + printf("CURL error (#%d): %s<br>\n", curl_errno($ch), + htmlspecialchars(curl_error($ch))); +} +$response = trim($response); // Remove leading/trailing whitespace + +// Remove any extra content after </S:Envelope> +$response = preg_replace('/<\/S:Envelope>.*$/s', '</S:Envelope>', $response); + +$doc = new DOMDocument(); +$doc->loadXML($response); + +// Mendapatkan semua elemen 'return' +$returns = $doc->getElementsByTagName('return'); + +$data = array(); +foreach ($returns as $return) { + // Mendapatkan elemen-elemen di dalam 'return' + $status = $return->getElementsByTagName('status')->item(0)->nodeValue; + $userId = $return->getElementsByTagName('userId')->item(0)->nodeValue; + + // Menambahkan ke dalam array data + $data[] = array('status' => $status, 'userId' => $userId); +} + +// Menghasilkan format JSON yang diinginkan +$result = json_encode(array('data' => $data)); + +// Mengirimkan response JSON +http_response_code(200); +echo $result; diff --git a/app/api/premium/rejectRequest.php b/app/api/premium/rejectRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..a3e6cb24bea1e1a645678efe064142f25b271306 --- /dev/null +++ b/app/api/premium/rejectRequest.php @@ -0,0 +1,52 @@ +<?php + +require_once __DIR__ . '/../../../config/config.php'; + +if (isset($_ENV['SOAP_URL'])) { + $url = $_ENV['SOAP_URL']; +} else if (isset($_ENV['SOLO_DOCKER'])) { + $url = "http://host.docker.internal:8888/ws/subscription"; +} else { + $url = "http://localhost:8888/ws/subscription"; +} +$id = $_POST['user_id']; +$request_param = '<?xml version="1.0" encoding="utf-8"?> +<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> +<soap:Body> + <rejectRequest xmlns="http://services.appnote/"> + <arg0 xmlns="">'. $id . '</arg0> + <arg1 xmlns="">'. $_ENV['REST_API_KEY'] . '</arg1> + </rejectRequest> +</soap:Body> +</soap:Envelope> +'; + +$headers = array( + "Content-Type: text/xml;charset=\"utf-8\"", + 'Content-Length: ' .strlen($request_param), + 'X-API-Key: ' . $_ENV['SOAP_API_KEY'] +); + +$ch = curl_init(); +curl_setopt($ch, CURLOPT_POST, true); +curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); +curl_setopt($ch, CURLOPT_POSTFIELDS, $request_param); +curl_setopt($ch, CURLOPT_URL, $url); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + +$response = curl_exec($ch); +curl_close($ch); +if ($response === FALSE) { + printf("CURL error (#%d): %s<br>\n", curl_errno($ch), + htmlspecialchars(curl_error($ch))); +} +$response1 = str_replace('<?xml version=\'1.0\' encoding=\'UTF-8\'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:rejectRequestResponse xmlns:ns2="http://services.appnote/"><return>',"",$response); +$response2 = str_replace("</return></ns2:rejectRequestResponse></S:Body></S:Envelope>","",$response1); +$obj = json_decode($response2); +$data = $obj->data; +// $row_count = 0; +// for ($i = 0; $i < count($data); $i++) { +// $row_count += $subscription_model->upsertSubscription($data[$i]->creator_id, $data[$i]->subscriber_id, $data[$i]->status); +// } +http_response_code(200); +echo json_encode($data); \ No newline at end of file