1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FeiMx\Pac\Drivers; |
4
|
|
|
|
5
|
|
|
use FeiMx\Pac\Contracts\PacDriverInterface; |
6
|
|
|
use FeiMx\Pac\Exceptions\PacErrorException; |
7
|
|
|
use FeiMx\Pac\Exceptions\PacVerificationFailedException; |
8
|
|
|
use FeiMx\Pac\PacUser; |
9
|
|
|
use Illuminate\Support\Facades\Validator; |
10
|
|
|
|
11
|
|
|
class FinkokDriver extends AbstractDriver implements PacDriverInterface |
12
|
|
|
{ |
13
|
|
|
public function stamp() |
14
|
|
|
{ |
15
|
|
|
throw new \Exception('Method stamp() is not implemented.'); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function cancel() |
19
|
|
|
{ |
20
|
|
|
throw new \Exception('Method cancel() is not implemented.'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function addUser($rfc, $params = []) |
24
|
|
|
{ |
25
|
|
|
if (empty($rfc)) { |
26
|
|
|
throw new PacVerificationFailedException('The RFC is a necessary fields'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$rules = [ |
30
|
|
|
'type_user' => 'required|in:O,P', |
31
|
|
|
'added' => 'required', |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
if (Validator::make($params, $rules)->fails()) { |
35
|
|
|
throw new PacVerificationFailedException('The params did not contain the necessary fields'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$response = $this->request( |
39
|
|
|
$this->url('registration'), |
40
|
|
|
'add', |
41
|
|
|
$this->prepareGenericParams(array_merge(['taxpayer_id' => $rfc], $params)) |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
if (is_a($response, 'SoapFault')) { |
45
|
|
|
throw new PacErrorException($response->faultstring); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if (!$response->addResult->success) { |
49
|
|
|
throw new PacErrorException($response->addResult->message); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ($response->addResult->message == 'Account Already exists') { |
53
|
|
|
throw new PacErrorException('The RFC has been registered before'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return (new PacUser)->map(array_merge(['rfc' => $rfc], $params)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function editUser($rfc, $params = []) |
60
|
|
|
{ |
61
|
|
|
throw new \Exception('Method editUser() is not implemented.'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getUsers() |
65
|
|
|
{ |
66
|
|
|
throw new \Exception('Method getUsers() is not implemented.'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getUser($rfc = null) |
70
|
|
|
{ |
71
|
|
|
throw new \Exception('Method getUser() is not implemented.'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function assignStamps($rfc = null, $credit = 0) |
75
|
|
|
{ |
76
|
|
|
throw new \Exception('Method assignStamps() is not implemented.'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
protected function url($wsdl = null) |
80
|
|
|
{ |
81
|
|
|
return $this->sandbox |
82
|
|
|
? "https://demo-facturacion.finkok.com/servicios/soap/{$wsdl}.wsdl" |
83
|
|
|
: "https://facturacion.finkok.com/servicios/soap/{$wsdl}.wsdl"; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
protected function prepareGenericParams(array $params = []) |
87
|
|
|
{ |
88
|
|
|
return array_merge([ |
89
|
|
|
'reseller_username' => $this->username, |
90
|
|
|
'reseller_password' => $this->password, |
91
|
|
|
], $params); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|