From ec7bc57137af854f35003af692c6d7ac96867775 Mon Sep 17 00:00:00 2001 From: Maulidan Nashuha Date: Fri, 5 Aug 2022 16:44:57 +0700 Subject: [PATCH] Set esign bsre for invisible --- src/ESignBSrE.php | 40 +++++++++++- src/ESignBSreResponse.php | 72 ++++++++++++++++++++++ src/Facades/ESignBSrE.php | 2 +- src/Providers/ESignBSrEServiceProvider.php | 2 +- 4 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 src/ESignBSreResponse.php diff --git a/src/ESignBSrE.php b/src/ESignBSrE.php index b730951..b0733c0 100644 --- a/src/ESignBSrE.php +++ b/src/ESignBSrE.php @@ -2,9 +2,45 @@ namespace DiskominfotikBandaAceh\ESignBSrE; +use Illuminate\Support\Facades\Http; + class ESignBSrE { - public function sign(){ - return ''; + private $http; + private $url; + private $nik; + + public function __construct($username=null, $password=null, $nik=null){ + if (!$username) + $username = config('e-sign-bsre.username'); + + if (!$password) + $password = config('e-sign-bsre.password'); + + if ($nik) + $this->nik = $nik; + + $this->url = config('e-sign-bsre.url'); + $this->http = Http::withBasicAuth($username, $password); + } + + public function setNIK($nik): ESignBSrE { + $this->nik = $nik; + + return $this; + } + + public function signInvisible($nik, $passphrase, $file, $fileName) { + $response = $this->http->attach( + 'file', + $file, + $fileName) + ->post($this->url . 'api/sign/pdf', [ + 'nik' => $nik, + 'passphrase' => $passphrase, + 'tampilan' => 'invisible', + ]); + + return new ESignBSreResponse($response); } } diff --git a/src/ESignBSreResponse.php b/src/ESignBSreResponse.php new file mode 100644 index 0000000..e3f09c0 --- /dev/null +++ b/src/ESignBSreResponse.php @@ -0,0 +1,72 @@ +response = $response; + + $this->setStatus(); + $this->setErrors(); + $this->setData(); + } + + private function setStatus(): void + { + $this->status = $this->response->status(); + } + + /** + * @return mixed + */ + public function getStatus(): int + { + return $this->status; + } + + /** + * @param mixed $errors + */ + public function setErrors(): void + { + if ($this->status != self::STATUS_OK){ + $this->errors = json_decode($this->response->body())->error; + } + } + + /** + * @return mixed + */ + public function getErrors() + { + return $this->errors; + } + + /** + * @param mixed $data + */ + public function setData(): void + { + if ($this->status == self::STATUS_OK){ + $this->data = $this->response->body(); + } + } + + /** + * @return mixed + */ + public function getData() + { + return $this->data; + } +} diff --git a/src/Facades/ESignBSrE.php b/src/Facades/ESignBSrE.php index 53e71aa..86b4ac2 100644 --- a/src/Facades/ESignBSrE.php +++ b/src/Facades/ESignBSrE.php @@ -5,7 +5,7 @@ use Illuminate\Support\Facades\Facade; /** - * @method \DiskominfotikBandaAceh\ESignBSrE\ESignBSrE sign() + * @method \DiskominfotikBandaAceh\ESignBSrE\ESignBSreResponse signInvisible($nik, $passphrase, $file, $fileName) * * @see \DiskominfotikBandaAceh\ESignBSrE\ESignBSrE */ diff --git a/src/Providers/ESignBSrEServiceProvider.php b/src/Providers/ESignBSrEServiceProvider.php index 72ae75e..0b202fa 100644 --- a/src/Providers/ESignBSrEServiceProvider.php +++ b/src/Providers/ESignBSrEServiceProvider.php @@ -55,7 +55,7 @@ public function register() // Register the main class to use with the facade $this->app->singleton('e-sign-bsre', function () { - return new ESignBSrE(); + return new ESignBSrE; }); } }