1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sausin\Signere\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Sausin\Signere\ExternalSign; |
7
|
|
|
use Sausin\Signere\Http\Controllers\Controller; |
8
|
|
|
|
9
|
|
|
class MobileExternalSignController extends Controller |
10
|
|
|
{ |
11
|
|
|
/** @var \Sausin\Signere\ExternalSign */ |
12
|
|
|
protected $extSign; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Create a new controller instance. |
16
|
|
|
* |
17
|
|
|
* @param \Sausin\Signere\ExternalSign $extSign |
18
|
|
|
*/ |
19
|
|
|
public function __construct(ExternalSign $extSign) |
20
|
|
|
{ |
21
|
|
|
parent::__construct(); |
22
|
|
|
|
23
|
|
|
$this->extSign = $extSign; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Get status of the BankID mobile Sign session. |
28
|
|
|
* |
29
|
|
|
* @param string $signeeRefId |
30
|
|
|
* @return \Illuminate\Http\Response |
31
|
|
|
*/ |
32
|
|
|
public function show(string $signeeRefId) |
33
|
|
|
{ |
34
|
|
|
return $this->extSign->getSessionStatus($signeeRefId) |
35
|
|
|
->getBody() |
36
|
|
|
->getContents(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Starts a BankID mobile sign session for the given document. |
41
|
|
|
* |
42
|
|
|
* @param Request $request |
43
|
|
|
* @return \Illuminate\Http\Response |
44
|
|
|
*/ |
45
|
|
View Code Duplication |
public function store(Request $request) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$this->validate($request, [ |
48
|
|
|
'birth_date' => [ |
49
|
|
|
'required', |
50
|
|
|
'string', |
51
|
|
|
'size:6', |
52
|
|
|
'regex:/^\d{6}$/i', |
53
|
|
|
], |
54
|
|
|
'document_id' => 'required|string|size:36', |
55
|
|
|
'phone_number' => [ |
56
|
|
|
'required', |
57
|
|
|
'regex:/^\+47\d{8}$/i', |
58
|
|
|
], |
59
|
|
|
'signee_ref' => 'required|string|size:36', |
60
|
|
|
]); |
61
|
|
|
|
62
|
|
|
// this is used to only set the keys which have been sent in |
63
|
|
|
$useKeys = [ |
64
|
|
|
'birth_date' => 'DateOfBirth', |
65
|
|
|
'document_id' => 'DocumentID', |
66
|
|
|
'phone_number' => 'Mobile', |
67
|
|
|
'signee_ref' => 'SigneeRef', |
68
|
|
|
]; |
69
|
|
|
|
70
|
|
|
// check which keys are available in the request |
71
|
|
|
$available = array_intersect(array_keys($useKeys), array_keys($request->all())); |
72
|
|
|
|
73
|
|
|
$body = []; |
74
|
|
|
|
75
|
|
|
// set the body up |
76
|
|
|
foreach ($available as $use) { |
77
|
|
|
$body[$useKeys[$use]] = $request->$use; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $this->extSign->startMobile($body) |
81
|
|
|
->getBody() |
82
|
|
|
->getContents(); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.