Skip to content

Commit ec7bc57

Browse files
Set esign bsre for invisible
1 parent a8c66e4 commit ec7bc57

File tree

4 files changed

+112
-4
lines changed

4 files changed

+112
-4
lines changed

src/ESignBSrE.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,45 @@
22

33
namespace DiskominfotikBandaAceh\ESignBSrE;
44

5+
use Illuminate\Support\Facades\Http;
6+
57
class ESignBSrE
68
{
7-
public function sign(){
8-
return '';
9+
private $http;
10+
private $url;
11+
private $nik;
12+
13+
public function __construct($username=null, $password=null, $nik=null){
14+
if (!$username)
15+
$username = config('e-sign-bsre.username');
16+
17+
if (!$password)
18+
$password = config('e-sign-bsre.password');
19+
20+
if ($nik)
21+
$this->nik = $nik;
22+
23+
$this->url = config('e-sign-bsre.url');
24+
$this->http = Http::withBasicAuth($username, $password);
25+
}
26+
27+
public function setNIK($nik): ESignBSrE {
28+
$this->nik = $nik;
29+
30+
return $this;
31+
}
32+
33+
public function signInvisible($nik, $passphrase, $file, $fileName) {
34+
$response = $this->http->attach(
35+
'file',
36+
$file,
37+
$fileName)
38+
->post($this->url . 'api/sign/pdf', [
39+
'nik' => $nik,
40+
'passphrase' => $passphrase,
41+
'tampilan' => 'invisible',
42+
]);
43+
44+
return new ESignBSreResponse($response);
945
}
1046
}

src/ESignBSreResponse.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
4+
namespace DiskominfotikBandaAceh\ESignBSrE;
5+
6+
7+
class ESignBSreResponse
8+
{
9+
private $status;
10+
private $errors;
11+
private $data;
12+
private $response;
13+
private const STATUS_OK = 200;
14+
15+
public function __construct($response)
16+
{
17+
$this->response = $response;
18+
19+
$this->setStatus();
20+
$this->setErrors();
21+
$this->setData();
22+
}
23+
24+
private function setStatus(): void
25+
{
26+
$this->status = $this->response->status();
27+
}
28+
29+
/**
30+
* @return mixed
31+
*/
32+
public function getStatus(): int
33+
{
34+
return $this->status;
35+
}
36+
37+
/**
38+
* @param mixed $errors
39+
*/
40+
public function setErrors(): void
41+
{
42+
if ($this->status != self::STATUS_OK){
43+
$this->errors = json_decode($this->response->body())->error;
44+
}
45+
}
46+
47+
/**
48+
* @return mixed
49+
*/
50+
public function getErrors()
51+
{
52+
return $this->errors;
53+
}
54+
55+
/**
56+
* @param mixed $data
57+
*/
58+
public function setData(): void
59+
{
60+
if ($this->status == self::STATUS_OK){
61+
$this->data = $this->response->body();
62+
}
63+
}
64+
65+
/**
66+
* @return mixed
67+
*/
68+
public function getData()
69+
{
70+
return $this->data;
71+
}
72+
}

src/Facades/ESignBSrE.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Support\Facades\Facade;
66

77
/**
8-
* @method \DiskominfotikBandaAceh\ESignBSrE\ESignBSrE sign()
8+
* @method \DiskominfotikBandaAceh\ESignBSrE\ESignBSreResponse signInvisible($nik, $passphrase, $file, $fileName)
99
*
1010
* @see \DiskominfotikBandaAceh\ESignBSrE\ESignBSrE
1111
*/

src/Providers/ESignBSrEServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function register()
5555

5656
// Register the main class to use with the facade
5757
$this->app->singleton('e-sign-bsre', function () {
58-
return new ESignBSrE();
58+
return new ESignBSrE;
5959
});
6060
}
6161
}

0 commit comments

Comments
 (0)