Skip to content

Commit

Permalink
Set esign bsre for invisible
Browse files Browse the repository at this point in the history
  • Loading branch information
maulidannashuha committed Aug 5, 2022
1 parent a8c66e4 commit ec7bc57
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 4 deletions.
40 changes: 38 additions & 2 deletions src/ESignBSrE.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
72 changes: 72 additions & 0 deletions src/ESignBSreResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php


namespace DiskominfotikBandaAceh\ESignBSrE;


class ESignBSreResponse
{
private $status;
private $errors;
private $data;
private $response;
private const STATUS_OK = 200;

public function __construct($response)
{
$this->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;
}
}
2 changes: 1 addition & 1 deletion src/Facades/ESignBSrE.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/ESignBSrEServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
}

0 comments on commit ec7bc57

Please sign in to comment.