|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FeiMx\Pac\Drivers; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
|
6
|
|
|
use FeiMx\Pac\Contracts\PacDriverInterface; |
|
7
|
|
|
use Meng\AsyncSoap\Guzzle\Factory as SoapFactory; |
|
8
|
|
|
|
|
9
|
|
|
abstract class AbstractDriver implements PacDriverInterface |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The driver username. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $username; |
|
17
|
|
|
/** |
|
18
|
|
|
* The driver password. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $password; |
|
23
|
|
|
/** |
|
24
|
|
|
* The driver sandbox. |
|
25
|
|
|
* |
|
26
|
|
|
* @var bool |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $sandbox; |
|
29
|
|
|
/** |
|
30
|
|
|
* The custom parameters to be sent with the request. |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $parameters = []; |
|
35
|
|
|
/** |
|
36
|
|
|
* The Guzzle Soap Factory. |
|
37
|
|
|
* |
|
38
|
|
|
* @var \Meng\AsyncSoap\Guzzle\Factory |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $factory; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Create a new driver instance. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $username |
|
46
|
|
|
* @param string $password |
|
47
|
|
|
* @param bool $sandbox |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct($username, $password, $sandbox = true) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->username = $username; |
|
52
|
|
|
$this->password = $password; |
|
53
|
|
|
$this->sandbox = $sandbox; |
|
54
|
|
|
$this->factory = new SoapFactory(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
abstract public function stamp(); |
|
58
|
|
|
|
|
59
|
|
|
abstract public function cancel(); |
|
60
|
|
|
|
|
61
|
|
|
abstract public function addUser($rfc, $params = []); |
|
62
|
|
|
|
|
63
|
|
|
abstract public function editUser($rfc, $params = []); |
|
64
|
|
|
|
|
65
|
|
|
abstract public function getUsers(); |
|
66
|
|
|
|
|
67
|
|
|
abstract public function getUser($rfc = null); |
|
68
|
|
|
|
|
69
|
|
|
abstract public function assignStamps($rfc = null, $credit = 0); |
|
70
|
|
|
|
|
71
|
|
|
abstract protected function url($wsdl = null); |
|
72
|
|
|
|
|
73
|
|
|
public function request($url = null, $method = null, $params = []) |
|
74
|
|
|
{ |
|
75
|
|
|
$url = $url ?? $this->url(); |
|
76
|
|
|
|
|
77
|
|
|
try { |
|
78
|
|
|
$response = $this->factory->create(new Client(), $url) |
|
79
|
|
|
->{$method}($params); |
|
80
|
|
|
|
|
81
|
|
|
return $response->wait(); |
|
82
|
|
|
} catch (\SoapFault $e) { |
|
83
|
|
|
return $e; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function xml() |
|
88
|
|
|
{ |
|
89
|
|
|
throw new \Exception('Method xml() is not implemented.'); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function user() |
|
93
|
|
|
{ |
|
94
|
|
|
throw new \Exception('Method user() is not implemented.'); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|