@@ -21,20 +21,17 @@ public function findDeliveryPoints(array $request)
21
21
try {
22
22
$ request = $ this ->decorateRequest ($ request );
23
23
$ result = $ this ->client ->WSI3_PointRelais_Recherche ($ request );
24
- $ this ->checkResponse ($ result );
24
+ $ this ->checkResponse (' WSI3_PointRelais_Recherche ' , $ result );
25
25
$ delivery_points = [];
26
26
if (!property_exists ($ result ->WSI3_PointRelais_RechercheResult ->PointsRelais , 'PointRelais_Details ' )){
27
27
return $ delivery_points ;
28
28
}
29
29
$ label_position = 1 ;
30
+ if (is_object ($ result ->WSI3_PointRelais_RechercheResult ->PointsRelais ->PointRelais_Details )){
31
+ return $ this ->createPoint ($ result ->WSI3_PointRelais_RechercheResult ->PointsRelais ->PointRelais_Details );
32
+ }
30
33
foreach ($ result ->WSI3_PointRelais_RechercheResult ->PointsRelais ->PointRelais_Details as $ destination_point ){
31
- $ delivery_points [] = new Point (
32
- $ destination_point ->Num ,
33
- trim ($ destination_point ->LgAdr1 ),
34
- str_replace (", " ,". " ,$ destination_point ->Latitude ),
35
- str_replace (", " ,". " ,$ destination_point ->Longitude ),
36
- $ destination_point ->CP
37
- );
34
+ $ delivery_points [] = $ this ->createPoint ($ destination_point );
38
35
$ label_position ++;
39
36
}
40
37
return $ delivery_points ;
@@ -44,6 +41,19 @@ public function findDeliveryPoints(array $request)
44
41
45
42
}
46
43
44
+ public function findDeliveryPoint ($ id , $ country )
45
+ {
46
+ try {
47
+ return $ this ->findDeliveryPoints (array (
48
+ 'NumPointRelais ' => $ id ,
49
+ 'Pays ' => $ country
50
+ ));
51
+
52
+ } catch ( \SoapFault $ e ) {
53
+ throw new \Exception ();
54
+ }
55
+ }
56
+
47
57
private function decorateRequest ($ request )
48
58
{
49
59
$ key = $ this ->websiteId ;
@@ -56,17 +66,27 @@ private function decorateRequest($request)
56
66
return $ request ;
57
67
}
58
68
59
- private function checkResponse ($ result )
69
+ private function checkResponse ($ method , $ result )
60
70
{
61
- if ($ result ->WSI3_PointRelais_RechercheResult ->STAT != 0 ) {
71
+ $ method = $ method . "Result " ;
72
+ if ($ result ->{$ method }->STAT != 0 ) {
62
73
$ request = $ this ->decorateRequest ([
63
- 'STAT_ID ' => $ result ->WSI3_PointRelais_RechercheResult ->STAT ,
74
+ 'STAT_ID ' => $ result ->{ $ method } ->STAT ,
64
75
'Langue ' => 'ES ' ,
65
76
]);
66
77
$ error_response = $ this ->client ->WSI2_STAT_Label ($ request );
67
78
throw new \InvalidArgumentException ($ error_response ->WSI2_STAT_LabelResult );
68
79
}
69
80
}
70
81
82
+ private function createPoint ($ response ) {
83
+ return new Point (
84
+ $ response ->Num ,
85
+ trim ($ response ->LgAdr1 ),
86
+ str_replace (", " ,". " ,$ response ->Latitude ),
87
+ str_replace (", " ,". " ,$ response ->Longitude ),
88
+ $ response ->CP
89
+ );
90
+ }
71
91
72
92
}
0 commit comments