Files
simrs-jatim/core/billing_service.php
2024-04-19 14:04:41 +07:00

58 lines
1.3 KiB
PHP

<?php
if(!session_id()) {
session_start();
}
require_once 'main.php';
use GuzzleHttp\Client;
use GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Exception\RequestException;
$dotenv = new Dotenv\Dotenv(_DOCROOT_);
$dotenv->load();
if(!array_key_exists('method', $_REQUEST)) {
echo 'Failed! Method doesnt exist.';
exit;
}
if(!array_key_exists('url', $_REQUEST)) {
echo 'Failed! Url requested doesnt exist.';
exit;
}
$main_url = $_ENV['BILLING_DB_URL'];
$url_request = $main_url.$_REQUEST['url'];
$method = $_REQUEST['method'];
$object_only = (array_key_exists('object_only', $_REQUEST)) ? $_REQUEST['object_only'] : FALSE;
if($method == 'GET') {
$content_type = 'application/json; charset=utf-8';
}
elseif($method == 'POST' || $method == 'PUT') {
$content_type = 'application/x-www-form-urlencoded';
}
$client = new GuzzleHttp\Client();
$request = new Request(
$method, // GET,POST,PUT
$url_request, // URL
[
'Accept' => 'application/json',
'Content-type' => $content_type
],
$body // Post / Put Body (text)
);
$obj_request = $client->send($request);
$json_request = ($obj_request->getStatusCode() == 200) ? $obj_request->getBody()->getContents() : [];
if($object_only == TRUE) {
echo $json_request;
}
else {
// echo (array) json_decode($json_request);
echo $json_request;
}