1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MÓDULO DE EMISIÓN ELECTRÓNICA F72X |
5
|
|
|
* UBL 2.1 |
6
|
|
|
* Version 1.1 |
7
|
|
|
* |
8
|
|
|
* Copyright 2018, Jaime Cruz |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace F72X\Sunat; |
12
|
|
|
|
13
|
|
|
use F72X\F72X; |
14
|
|
|
use F72X\Company; |
15
|
|
|
use SoapClient; |
16
|
|
|
use SoapHeader; |
17
|
|
|
use SoapVar; |
18
|
|
|
|
19
|
|
|
class SunatSoapClient extends SoapClient { |
20
|
|
|
|
21
|
|
|
public function __construct($wsdl, $options) { |
22
|
|
|
$prodMode = F72X::isProductionMode(); |
23
|
|
|
$ruc = Company::getRUC(); |
24
|
|
|
$solUser = $prodMode ? Company::getSolUser() : SunatVars::SUNAT_SOL_USER_BETA; |
25
|
|
|
$solKey = $prodMode ? Company::getSolKey() : SunatVars::SUNAT_SOL_KEY_BETA; |
26
|
|
|
|
27
|
|
|
$nsWsse = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'; |
28
|
|
|
$WSHeader = <<<SEC |
29
|
|
|
<wsse:Security xmlns:wsse="$nsWsse"> |
30
|
|
|
<wsse:UsernameToken> |
31
|
|
|
<wsse:Username>$ruc$solUser</wsse:Username> |
32
|
|
|
<wsse:Password>$solKey</wsse:Password> |
33
|
|
|
</wsse:UsernameToken> |
34
|
|
|
</wsse:Security> |
35
|
|
|
SEC; |
36
|
|
|
|
37
|
|
|
$headers = new SoapHeader($nsWsse, 'Security', new SoapVar($WSHeader, XSD_ANYXML)); |
38
|
|
|
//set the Headers of Soap Client. |
39
|
|
|
$this->__setSoapHeaders($headers); |
40
|
|
|
parent::__construct($wsdl, $options); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public static function getService() { |
44
|
|
|
$serviceUrl = F72X::isProductionMode() ? |
45
|
|
|
SunatVars::SUNAT_SERVICE_URL_PROD : SunatVars::SUNAT_SERVICE_URL_BETA; |
46
|
|
|
|
47
|
|
|
return new SunatSoapClient("$serviceUrl?wsdl", ['trace' => true]); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public static function getCdrService() { |
51
|
|
|
$serviceUrl = SunatVars::SUNAT_CDR_SERVICE_URL; |
52
|
|
|
return new SunatSoapClient("$serviceUrl?wsdl", ['trace' => true]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
|