1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Giansalex |
5
|
|
|
* Date: 15/07/2017 |
6
|
|
|
* Time: 22:56 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Greenter\Ws\Services; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class FeSunat |
13
|
|
|
* @package Greenter\Ws\Services |
14
|
|
|
*/ |
15
|
|
|
class FeSunat extends BaseSunat |
16
|
|
|
{ |
17
|
|
|
const BETA = 'https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService'; |
18
|
|
|
const HOMOLOGACION = 'https://www.sunat.gob.pe/ol-ti-itcpgem-sqa/billService'; |
19
|
|
|
const PRODUCCION = 'https://e-factura.sunat.gob.pe/ol-ti-itcpfegem/billService'; |
20
|
|
|
const WSDL_ENDPOINT = 'https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService?wsdl'; |
21
|
|
|
|
22
|
6 |
|
public function __construct($user, $password) |
23
|
|
|
{ |
24
|
6 |
|
parent::__construct($user, $password); |
25
|
6 |
|
$this->setUrlWsdl(FeSunat::WSDL_ENDPOINT); |
26
|
6 |
|
} |
27
|
|
|
|
28
|
2 |
View Code Duplication |
public function send($filename, $content) |
|
|
|
|
29
|
|
|
{ |
30
|
2 |
|
$client = parent::getClient(); |
|
|
|
|
31
|
|
|
|
32
|
|
|
try { |
33
|
|
|
$params = [ |
34
|
2 |
|
'fileName' => $filename, |
35
|
2 |
|
'contentFile' => $content, |
36
|
2 |
|
]; |
37
|
2 |
|
$response = $client->__soapCall('sendBill', [ 'parameters' => $params ]); |
38
|
2 |
|
return $response->applicationResponse; |
39
|
|
|
// $entry = readXml( $response->applicationResponse, 'R-20600055519-01-F001-00000001.xml'); |
|
|
|
|
40
|
|
|
// if (!empty($entry)) { |
41
|
|
|
// header('Content-Type: text/xml'); |
42
|
|
|
// echo $entry; |
43
|
|
|
// } |
44
|
|
|
|
45
|
|
|
} |
46
|
|
|
catch (\Exception $e) { |
47
|
|
|
// $client->__getLastResponse() |
|
|
|
|
48
|
|
|
return $e->getMessage(); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
2 |
View Code Duplication |
public function sendSummary($filename, $content) |
|
|
|
|
53
|
|
|
{ |
54
|
2 |
|
$client = parent::getClient(); |
|
|
|
|
55
|
|
|
|
56
|
|
|
try { |
57
|
|
|
$params = [ |
58
|
2 |
|
'fileName' => $filename, |
59
|
2 |
|
'contentFile' => $content, |
60
|
2 |
|
]; |
61
|
2 |
|
$response = $client->__soapCall('sendSummary', [ 'parameters' => $params ]); |
62
|
2 |
|
return $response->ticket; |
63
|
|
|
// $entry = readXml( $response->applicationResponse, 'R-20600055519-01-F001-00000001.xml'); |
|
|
|
|
64
|
|
|
// if (!empty($entry)) { |
65
|
|
|
// header('Content-Type: text/xml'); |
66
|
|
|
// echo $entry; |
67
|
|
|
// } |
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
catch (\Exception $e) { |
71
|
|
|
// $client->__getLastResponse() |
|
|
|
|
72
|
|
|
return $e->getMessage(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
2 |
|
public function getStatus($ticket) |
77
|
|
|
{ |
78
|
2 |
|
$client = parent::getClient(); |
|
|
|
|
79
|
|
|
|
80
|
|
|
try { |
81
|
|
|
$params = [ |
82
|
2 |
|
'ticket' => $ticket, |
83
|
2 |
|
]; |
84
|
2 |
|
$response = $client->__soapCall('getStatus', [ 'parameters' => $params ]); |
85
|
|
|
return $response->statusResponse; |
86
|
|
|
// $entry = readXml( $response->applicationResponse, 'R-20600055519-01-F001-00000001.xml'); |
|
|
|
|
87
|
|
|
// if (!empty($entry)) { |
88
|
|
|
// header('Content-Type: text/xml'); |
89
|
|
|
// echo $entry; |
90
|
|
|
// } |
91
|
|
|
|
92
|
|
|
} |
93
|
2 |
|
catch (\Exception $e) { |
94
|
|
|
// $client->__getLastResponse() |
|
|
|
|
95
|
2 |
|
return $e->getMessage(); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
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.