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