Bonjour à tous,

Je met en place un service d'impression d'étiquette Chronopost à l'aide du webservice en SOAP pour une e-boutique.
J'avoue c'est ma première utilisation de SOAP.

Pour que l'appel se fasse bien il faut que les paramètres soient dans un ordre bien précis.

Dans l'exemple ci-dessous (à partir de la librairie de Benoit VRIGNAUD https://github.com/bvrignaud/chronopost), j'essaie d'ajouter des paramètres mais ils ne sont pas pris en compte dans la requête.

Fichier de remplissage des paramètres :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
 
 
require_once 'chronopost.php';
 
 
 
 
$shipping = new Shipping();
 
$shipping->headerValue->accountNumber = 19869502; // Numéro de compte Test
//$shipping->headerValue->subAccount = '';
 
// adresse expéditeur
$shipping->shipperValue->shipperAdress1 = '111 adresse expe';
//$shipping->shipperValue->shipperAdress2 = '';
$shipping->shipperValue->shipperCity = 'MaVilleExpe';
$shipping->shipperValue->shipperCivility = 'M';
$shipping->shipperValue->shipperContactName = 'Jean Dupond';
$shipping->shipperValue->shipperCountry = 'FR';
//$shipping->shipperValue->shipperCountryName = 'FRANCE';
$shipping->shipperValue->shipperEmail = 'email@test.com';
//$shipping->shipperValue->shipperMobilePhone = '0611223344';
$shipping->shipperValue->shipperName = 'La Société expé';
//$shipping->shipperValue->shipperName2 = '';
$shipping->shipperValue->shipperPhone = '0100000000';
$shipping->shipperValue->shipperPreAlert = 0;
$shipping->shipperValue->shipperZipCode = '01000';
 
// adresse client
$shipping->customerValue->customerAdress1 ='111 adresse expe';
//$shipping->customerValue->customerAdress2 = '';
$shipping->customerValue->customerCity ='MaVilleExpe';
$shipping->customerValue->customerCivility ='M';
$shipping->customerValue->customerContactName ='Jean Dupond';
$shipping->customerValue->customerCountry ='FR';
$shipping->customerValue->customerCountryName ='FRANCE';
$shipping->customerValue->customerEmail ='email@test.com';
//$shipping->customerValue->customerMobilePhone ='0611223344';
$shipping->customerValue->customerName ='La Société expé';
//$shipping->customerValue->customerName2 = '';
$shipping->customerValue->customerPhone ='0100000000';
//$shipping->customerValue->customerPreAlert = 0;
$shipping->customerValue->customerZipCode ='01000';
$shipping->customerValue->printAsSender ='N';
 
// adresse destinataire
$shipping->recipientValue->recipientAdress1 = '111 Adresse test';
//$shipping->recipientValue->recipientAdress2 = '';
$shipping->recipientValue->recipientCity = 'MaVille';
//$shipping->recipientValue->recipientContactName = 'Michel Dupond';
$shipping->recipientValue->recipientCountry = 'FR';
$shipping->recipientValue->recipientCountryName = 'FRANCE';
$shipping->recipientValue->recipientEmail = 'test@test.com';
//$shipping->recipientValue->recipientMobilePhone = '0611223344';
$shipping->recipientValue->recipientName = 'Michel Dupond';
//$shipping->recipientValue->recipientName2 = '';
$shipping->recipientValue->recipientPhone = '0611223344';
//$shipping->recipientValue->recipientPreAlert = 0;
$shipping->recipientValue->recipientZipCode = '01000';
//$shipping->recipientValue->recipientCivility = 'M';
 
// Références expéditeur et destinataire, code barre client
//$shipping->refValue->shipperRef = $commandeNo;              // Référence Expéditeur (ex: '000000000000001')
//$shipping->refValue->recipientRef = $articleNo;             // Référence Destinataire (ex: '24')
//$shipping->refValue->customerSkybillNumber = '123456789';
 
 
// Caractéristique de colis : poids, produit, ...
$shipping->skybillValue->productCode = '2R';            // Code Produit Chronopost
$shipping->skybillValue->shipDate = date('c');          // Date d'expédition
$shipping->skybillValue->shipHour = date('G');
$shipping->skybillValue->weight = 2;
$shipping->skybillValue->service = '0';                 // Jour de livraison
$shipping->skybillValue->objectType = 'MAR';            // Type de colis (DOC/MAR)
 
$shipping->scheduledValue->expirationDate = "2021-12-10";
 
$shipping->password = '255562';               // Mot de passe correspondant au numéro de compte Test
$shipping->modeRetour = '2';
$shipping->numberOfParcel = 1;
 
 
 
$client = new Chronopost();
 
try {
    $result = $client->genereEtiquette($shipping);
} catch (SoapFault $soapFault) {
    //var_dump($soapFault);
    exit($soapFault->faultstring);
}
 
if ($result->return->errorCode) {
    echo 'Erreur n° ' . $result->return->errorCode . ' : ' . $result->return->errorMessage;
    //var_dump($result);
} else {
    // écriture dans un fichier pdf
    $fp = fopen('test.pdf', 'w');
    fwrite($fp, $result->return->skybill);
    fclose($fp);
    echo 'OK<br>';
	echo $result->return->skybillNumber;
}
Fichier chronopost.php contenant les classes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
/**
 * Paramètres Enlèvement Sur Demande
 */
class EsdValue
{
  public $closingDateTime;          // dateTime
  public $height;                   // float
  public $length;                   // float
  public $retrievalDateTime;        // dateTime
  public $shipperBuildingFloor;     // string
  public $shipperCarriesCode;       // string
  public $shipperServiceDirection;  // string
  public $specificInstructions;     // string
  public $width;                    // float
}
 
 
class HeaderValue
{
    /**
     * Numéro de compte
     * @var int
     */
    public $accountNumber;
 
    public $idEmit = 'CHRFR';   // Valeur fixe : CHRFR (string)
    public $identWebPro;        // string
    public $subAccount;         // Numéro de sous-compte (int)
}
 
 
class ShipperValue
{
  public $shipperAdress1;       // string
  public $shipperAdress2;       // string
  public $shipperCity;          // string
  public $shipperCivility;      // string
  public $shipperContactName;   // string
  public $shipperCountry;       // string
  public $shipperCountryName;   // string
  public $shipperEmail;         // string
  public $shipperMobilePhone;   // string
  public $shipperName;          // string
  public $shipperName2;         // string
  public $shipperPhone;         // string
 
  /**
   * Type de préalerte (MAS)<ul>
   *    <li>0 : pas de préalerte</li>
   *    <li>11 : abonnement tracking expéditeur</li></ul>
   * @var int
   */
  public $shipperPreAlert;
 
  public $shipperZipCode;       // string
}
 
 
class CustomerValue
{
    public $customerAdress1;        // string
    public $customerAdress2;        // string
    public $customerCity;           // string
    public $customerCivility;       // string
    public $customerContactName;    // string
    public $customerCountry;        // string
    public $customerCountryName;    // string
    public $customerEmail;          // string
    public $customerMobilePhone;    // string
    public $customerName;           // string
    public $customerName2;          // string
    public $customerPhone;          // string
 
    /**
     * Type de préalerte (Non utilisé pour le moment)
     * @var int
     */
    public $customerPreAlert;
 
    public $customerZipCode;        // string
}
 
 
class RecipientValue
{
    public $recipientAdress1;       // string
    public $recipientAdress2;       // string
    public $recipientCity;          // string
    public $recipientContactName;   // string
    public $recipientCountry;       // string
    public $recipientCountryName;   // string
    public $recipientEmail;         // string
    public $recipientMobilePhone;   // string
    public $recipientName;          // string
    public $recipientName2;         // string
    public $recipientPhone;         // string
 
    /**
     * Type de préalerte ( MAS )<ul>
     * <li>0 : pas de préalerte</li>
     * <li>22 : préalerte mail destinataire</li></ul>
     * @var int
     */
    public $recipientPreAlert;
 
    public $recipientZipCode;       // string
}
 
 
class RefValue
{
    /**
     * Numéro de colis client
     * Ce numéro de colis s’il est renseigné apparaitera sous forme de code barre sur
     * l’étiquette si celle-ci est de format A4 (champs mode positionné à SPD ou à PDF)
     * ou en format ZPL pour imprimante thermique (champs mode positionné à Z2D).
     * A noter que ce numéro sera automatiquement tronqué s’il dépasse 15 caractères.
     * @var string
     */
    public $customerSkybillNumber;
 
    //public $PCardTransactionNumber; // string
 
    /**
     * Référence Destinataire
     * Champ libre (imprimable sur la facture).
     * Cette valeur peut être utilisée ensuite comme critère de recherche dans le suivi.
     * Dans le cas des produits Chrono Relais (86), Chrono Relais 9 (80), Chrono Relais Europe (3T)
     *  et Chrono Zengo Relais 13 (3K) ce champs doit être rempli avec le code du point relais.
     *
     * @var string
     */
    public $recipientRef;
 
    /**
     * Référence Expéditeur
     * Champ libre (imprimable sur la facture).
     * Cette valeur peut être utilisée ensuite comme critère de recherche dans le suivi.
     * @var string
     */
    public $shipperRef; // string
}
 
 
/**
 * Caractéristique de colis : poids, produit, ...
 */
class SkybillValue
{
    public $bulkNumber = 1;         // Nombre total de colis
    public $codCurrency = 'EUR';    // Devise  du  Retour  Express de paiement EUR (Euro) par defaut (string)
    public $codValue;               // Valeur  Retour  Express  de paiement (int)
    public $content1;               // Détail contenu du colis 1 (string)
    public $content2;               // Détail contenu du colis 2 (string)
    public $content3;               // Détail contenu du colis 3 (string)
    public $content4;               // Détail contenu du colis 4 (string)
    public $content5;               // Détail contenu du colis 5 (string)
    public $customsCurrency;        // Devise   de   la   valeur déclarée en douane (string)
    public $customsValue;           // Valeur déclarée en douane (int)
    public $evtCode = 'DC';         // Code  événement  de  suivi Chronopost - Champ fixe : DC (string)
    public $insuredCurrency;        // Devise   de   la   valeur assurée (string)
    public $insuredValue;           // Valeur assurée (int)
 
    /**
     * Type de colis :
     *      DOC : Document
     *      MAR : Marchandise
     * @var string
     */
    public $objectType;
 
    public $portCurrency;           // string
    public $portValue;              // float
 
    /**
     * Code Produit Chronopost<ul>
     * <li>0 : Chrono Retrait Bureau</li>
     * <li>1 : Chrono 13</li>
     * <li>...</li>
     * <li>86 : Chrono Relais</li>
     * <li>...</li></ul>cf ANNEXE 8 : CODES PRODUITS ACCEPTES PAR LE WS SHIPPING
     * @var string
     */
    public $productCode;
 
    /**
     * Jour de livraison<ul>
     * <li>0 - Normal</li>
     * <li>1 - Livraison  lundi (uniquement  pour  les codes produits nationaux)</li>
     * <li>6 - Livraison  samedi (uniquement  pour  les codes produits nationaux)</li>
     * </ul>
     * @var string
     */
    public $service;
 
    public $shipDate;               // Date d'expédition (dateTime)
 
    /**
     * Heure d'expédition
     * Heure de  génération  de  l'envoi  (heure  courante), doit être compris entre 0 et 23
     * @var int
     */
    public $shipHour;
 
    public $skybillRank;            // string
 
    /**
     * Poids
     * @var float
     */
    public $weight;
 
    /**
     * Unité de poids
     *      par defaut: KGM (Kilogrammes)
     *      Sous-ensemble  de  la  recommandation 20 de l’UN/ECE
     * @var string
     */
    public $weightUnit = 'KGM';
}
 
 
/**
 * Indique sous quelle forme doit être récupérée l’étiquette.
 */
class SkybillParamsValue
{
    public $mode = 'PDF'; // string
}
 
/**
 * CHRONOFRESH
 */
class ScheduledValue
{
    public $expirationDate = ""; // YYYY-MM-DD
}
 
class Shipping
{
    /**
     * Paramètres Enlèvement Sur Demande
     * @var EsdValue
     */
    //public $esdValue;
 
    /** @var HeaderValue */
    public $headerValue;
 
    /**
     * Adresse expéditeur
     * @var ShipperValue
     */
    public $shipperValue;
 
    /**
     * Adresse du client
     * @var CustomerValue
     */
    public $customerValue;
 
    /**
     * Adresse du destinataire
     * @var recipientValue
     */
    public $recipientValue;
 
    /**
     * Références expéditeur et destinataire, code barre client
     * @var RefValue
     */
    public $refValue;
 
    /**
     * Caractéristique de colis : poids, produit, ...
     * @var SkybillValue
     */
    public $skybillValue;
 
    /**
     * @var skybillParamsValue
     */
    public $skybillParamsValue;
 
    /**
     * Mot de passe correspondant au numéro de compte
     * @var string
     */
    public $password = '';
    public $modeRetour = '';
    public $numberOfParcel;
 
    /**
     * @var scheduledValue
     */
    public $scheduledValue;
 
    public function __construct()
    {
        //$this->esdValue = new EsdValue();
        $this->headerValue = new HeaderValue();
        $this->shipperValue = new ShipperValue();
        $this->customerValue = new CustomerValue();
        $this->recipientValue = new RecipientValue();
        $this->refValue = new refValue();
        $this->skybillValue = new SkybillValue();
        $this->skybillParamsValue = new SkybillParamsValue();
        $this->scheduledValue = new ScheduledValue();
    }
}
 
class ShippingResponse
{
    public $return; // resultExpeditionValue
}
 
 
class Chronopost
{
    const WSDL_SHIPPING_SERVICE = "https://ws.chronopost.fr/shipping-cxf/ShippingServiceWS?wsdl";
 
    public function __construct()
    {
        // Check is SOAP is available
        if (!extension_loaded('soap')) {
            die('The SOAP extension is not available or configured on the server ; The module will not work without this extension ! Please contact your host to activate it in your PHP installation.');
        }
    }
 
 
    /**
     * Génère une étiquette
     *
     * @param Shipping $parameters
     * @return ShippingResponse
     * @throws SoapFault
     */
    public function genereEtiquette(Shipping $params)
    {
        $client_ch = new soapClient(self::WSDL_SHIPPING_SERVICE, array('trace' => 1));
        $client_ch->soap_defencoding = 'UTF-8';
        $client_ch->decode_utf8 = false;
		$r = $client_ch->shipping($params);
		echo htmlentities($client_ch->__getLastRequest()) . "<br><br>";
 
        return $r;
    }
}
?>
Et voici la requête envoyée :
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://cxf.shipping.soap.chronopost.fr/">
	<SOAP-ENV:Body>
		<ns1:shipping>
			<headerValue>
				<accountNumber>19869502</accountNumber>
				<idEmit>CHRFR</idEmit>
				<subAccount/>
			</headerValue>
			<shipperValue>
				<shipperAdress1>111 adresse expe</shipperAdress1>
				<shipperCity>MaVilleExpe</shipperCity>
				<shipperCivility>M</shipperCivility>
				<shipperContactName>Jean Dupond</shipperContactName>
				<shipperCountry>FR</shipperCountry>
				<shipperEmail>email@test.com</shipperEmail>
				<shipperName>La Société expé</shipperName>
				<shipperPhone>0100000000</shipperPhone>
				<shipperPreAlert>0</shipperPreAlert>
				<shipperZipCode>01000</shipperZipCode>
			</shipperValue>
			<customerValue>
				<customerAdress1>111 adresse expe</customerAdress1>
				<customerCity>MaVilleExpe</customerCity>
				<customerCivility>M</customerCivility>
				<customerContactName>Jean Dupond</customerContactName>
				<customerCountry>FR</customerCountry>
				<customerCountryName>FRANCE</customerCountryName>
				<customerEmail>email@test.com</customerEmail>
				<customerName>La Société expé</customerName>
				<customerPhone>0100000000</customerPhone>
				<customerPreAlert/>
				<customerZipCode>01000</customerZipCode>
				<printAsSender>N</printAsSender>
			</customerValue>
			<recipientValue>
				<recipientAdress1>111 Adresse test</recipientAdress1>
				<recipientCity>MaVille</recipientCity>
				<recipientCountry>FR</recipientCountry>
				<recipientCountryName>FRANCE</recipientCountryName>
				<recipientEmail>test@test.com</recipientEmail>
				<recipientName>Michel Dupond</recipientName>
				<recipientPhone>0611223344</recipientPhone>
				<recipientPreAlert/>
				<recipientZipCode>01000</recipientZipCode>
			</recipientValue>
			<refValue/>
			<skybillValue>
				<bulkNumber>1</bulkNumber>
				<codCurrency>EUR</codCurrency>
				<evtCode>DC</evtCode>
				<objectType>MAR</objectType>
				<productCode>2R</productCode>
				<service>0</service>
				<shipDate>2021-12-08T11:09:21+01:00</shipDate>
				<shipHour>11</shipHour>
				<weight>2</weight>
				<weightUnit>KGM</weightUnit>
			</skybillValue>
			<skybillParamsValue>
				<mode>PDF</mode>
			</skybillParamsValue>
			<password>255562</password>
		</ns1:shipping>
	</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Le problème est qu'après le pramètre "password" je devrais avoir les paramètres "modeRetour" et "numberOfParcel", puis ensuite la partie "scheduledValue->expirationDate".
Comme ceci :
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
         <password>255562</password>
         <modeRetour>2</modeRetour>
         <numberOfParcel>1</numberOfParcel>
         <scheduledValue>
            <expirationDate>2020-08-21</expirationDate>
         </scheduledValue>

J'espère que vous pourrez m'aider.
Un grand merci d'avance !