-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make 2 request icare and non icare and update readme
- Loading branch information
virusphp
committed
Sep 9, 2023
1 parent
04d374c
commit e24f79f
Showing
8 changed files
with
295 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Bpjs\Bridging\Icare; | ||
|
||
// use Bpjs\Bridging\Bridge; | ||
use Bpjs\Bridging\CurlFactory; | ||
|
||
class BridgeIcare extends CurlFactory | ||
{ | ||
protected $config; | ||
protected $response; | ||
protected $header; | ||
protected $headers; | ||
|
||
public function __construct() | ||
{ | ||
// parent::__construct(); | ||
$this->config = new ConfigIcare; | ||
$this->response = new ResponseIcare; | ||
$this->header = $this->config->setHeader(); | ||
} | ||
|
||
public function getRequest($endpoint) | ||
{ | ||
$result = $this->requestIcare($this->config->setUrl().$endpoint, $this->header); | ||
$result = $this->response->responseIcare($result, $this->config->keyDecrypt($this->header['X-timestamp'])); | ||
return $result; | ||
} | ||
|
||
public function getRequestNew($endpoint) | ||
{ | ||
$result = $this->requestIcare($this->config->setUrl().$endpoint, $this->header); | ||
$result = $this->response->responseIcare($result, $this->config->keyDecrypt($this->header['X-timestamp'])); | ||
return $result; | ||
} | ||
|
||
public function postRequest($endpoint, $data) | ||
{ | ||
$result = $this->requestIcare($this->config->setUrl().$endpoint, $this->header, "POST", $data); | ||
$result = $this->response->responseIcare($result, $this->config->keyDecrypt($this->header['X-timestamp'])); | ||
return $result; | ||
} | ||
|
||
public function putRequest($endpoint, $data) | ||
{ | ||
$result = $this->requestIcare($this->config->setUrl().$endpoint, $this->header, "PUT", $data); | ||
$result = $this->response->responseIcare($result, $this->config->keyDecrypt($this->header['X-timestamp'])); | ||
return $result; | ||
} | ||
|
||
public function deleteRequest($endpoint, $data) | ||
{ | ||
$result = $this->requestIcare($this->config->setUrl().$endpoint, $this->header, "DELETE", $data); | ||
$result = $this->response->responseIcare($result, $this->config->keyDecrypt($this->header['X-timestamp'])); | ||
return $result; | ||
} | ||
|
||
public function deleteResponseNoDecrypt($endpoint, $data) | ||
{ | ||
$result = $this->requestIcare($this->config->setUrl().$endpoint, $this->header, "DELETE", $data); | ||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace Bpjs\Bridging\Icare; | ||
|
||
use Bpjs\Bridging\ManageService; | ||
use Bpjs\Bridging\GenerateBpjs; | ||
use Dotenv\Dotenv; | ||
|
||
class ConfigIcare extends ManageService | ||
{ | ||
protected $urlEndpoint; | ||
protected $consId; | ||
protected $secretKey; | ||
protected $userKey; | ||
protected $header; | ||
protected $timestamps; | ||
|
||
public function __construct() | ||
{ | ||
$dotenv = Dotenv::createUnsafeImmutable(getcwd()); | ||
$dotenv->safeLoad(); | ||
|
||
$this->urlEndpoint = getenv('API_BPJS_ICARE'); | ||
$this->consId = getenv('CONS_ID'); | ||
$this->secretKey = getenv('SECRET_KEY'); | ||
$this->userKey = getenv('USER_KEY_VCLAIM'); | ||
} | ||
|
||
public function setUrl() | ||
{ | ||
return $this->urlEndpoint; | ||
} | ||
|
||
public function setConsId() | ||
{ | ||
return $this->consId; | ||
} | ||
|
||
public function setSecretKey() | ||
{ | ||
return $this->secretKey; | ||
} | ||
|
||
public function setUserKey() | ||
{ | ||
return $this->userKey; | ||
} | ||
|
||
public function setTimestamp() | ||
{ | ||
return GenerateBpjs::bpjsTimestamp(); | ||
} | ||
|
||
public function setsignature() | ||
{ | ||
return GenerateBpjs::generateSignature($this->setConsId(), $this->setSecretKey()); | ||
} | ||
|
||
public function setUrlEncode() | ||
{ | ||
return array('Content-Type' => 'Application/x-www-form-urlencoded'); | ||
} | ||
|
||
public function setUrlJson() | ||
{ | ||
return array('Content-Type' => 'Application/Json'); | ||
} | ||
|
||
public function setHeader() | ||
{ | ||
return [ | ||
'Accept' => 'application/json', | ||
'X-cons-id' => $this->setConsid(), | ||
'X-timestamp' => $this->setTimestamp(), | ||
'X-signature' => $this->setSignature(), | ||
'user_key' => $this->setUserKey() | ||
]; | ||
} | ||
|
||
public function keyDecrypt($timestamp) | ||
{ | ||
return $this->setConsid().$this->setSecretKey().$timestamp; | ||
} | ||
|
||
public function setHeaders($header) | ||
{ | ||
return array_merge($header, $this->setUrlEncode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Bpjs\Bridging\Icare; | ||
|
||
use LZCompressor\LZString; | ||
use Bpjs\Bridging\GenerateBpjs; | ||
|
||
class ResponseIcare | ||
{ | ||
public function responseIcare($response, $key) | ||
{ | ||
$result = json_decode($response); | ||
if ($result->metaData->code == "200" && is_string($result->response)) { | ||
return self::doMaping($result->metaData, $result->response, $key); | ||
} | ||
return json_encode($result); | ||
} | ||
|
||
public function doMaping($metaData, $response, $key) | ||
{ | ||
$data = [ | ||
"metaData" => $metaData, | ||
"response" => json_decode($this->decompressed(GenerateBpjs::stringDecrypt($key, $response))) | ||
]; | ||
return json_encode($data); | ||
} | ||
|
||
protected function decompressed($dataString) | ||
{ | ||
return LZString::decompressFromEncodedURIComponent($dataString); | ||
} | ||
} |
Oops, something went wrong.