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
| <html>
<head>
<title>Creation envoi bpost</title>
<link href="code-prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="code-prettify/prettify.js"></script>
</head>
<body onload="prettyPrint()">
<?php
if(isset($_GET['numerocommande'])) {$numerocommande = $_GET['numerocommande'];}
if(isset($_GET['prenom'])) {$prenom = $_GET['prenom'];}
if(isset($_GET['nom'])) {$nom = $_GET['nom'];}
if(isset($_GET['email'])) {$email = $_GET['email'];}
if(isset($_GET['tel'])) {$tel = $_GET['tel'];}
if(isset($_GET['rue'])) {$rue = $_GET['rue'];}
if(isset($_GET['codepostal'])) {$codepostal = $_GET['codepostal'];}
if(isset($_GET['ville'])) {$ville = $_GET['ville'];}
if(isset($_GET['pays'])) {$pays = $_GET['pays'];}
if(isset($_GET['mode'])) {$mode = $_GET['mode'];}
if(isset($_GET['pugoid'])) {$pugoid = $_GET['pugoid'];}
if(isset($pays)) {
if($pays == 'Belgique') {$pays = 'BE';}
if($pays == 'France') {$pays = 'FR';}
}
$webserviceUrl="https://api.bpost.be/services/shm/";
$username = "999033";
$password = "DEMO_SHM";
//J'ai pas mis les login et password correcte par sécurité, ceux-ci renvoi une erreur a chaque fois car non valide.
/*
echo '<br>'.$numerocommande.'<br>';
echo '<br>'.$prenom.'<br>';
echo '<br>'.$nom.'<br>';
echo '<br>'.$email.'<br>';
echo '<br>'.$tel.'<br>';
echo '<br>'.$rue.'<br>';
echo '<br>'.$codepostal.'<br>';
echo '<br>'.$ville.'<br>';
echo '<br>'.$pays.'<br>';
echo '<br>'.$mode.'<br>';
*/
// CREATE/REPLACE ORDER
switch ($mode)
{
//envoi en bpack 24h sans assurance
case 1:
$repmode= 'envoi en bpack 24h sans assurance';
$data = '
<order xmlns="http://schema.post.be/shm/deepintegration/v2/">
<accountId>115117</accountId>
<orderReference>'.$numerocommande.'</orderReference>
<status>OPEN</status>
<costCenter>'.$numerocommande.'</costCenter>
<orderLine>
<text>Commande Designnailart '.$numerocommande.'</text>
<nbOfItems>1</nbOfItems>
</orderLine>
<customer>
<firstName>'.$prenom.'</firstName>
<lastName>'.$nom.'</lastName>
<deliveryAddress>
<streetName>'.$rue.'</streetName>
<number></number>
<box></box>
<postalCode>'.$codepostal.'</postalCode>
<locality>'.$ville.'</locality>
<countryCode>'.$pays.'</countryCode>
</deliveryAddress>
<email>'.$email.'</email>
<phoneNumber>'.$tel.'</phoneNumber>
</customer>
<deliveryMethod>
<atHome>
<normal/>
</atHome>
</deliveryMethod>
<totalPrice>0</totalPrice>
</order>
';
break;
//envoi en bpack 24h avec assurance
case 2:
$repmode= 'envoi en bpack 24h avec assurance';
$data = '
<order xmlns="http://schema.post.be/shm/deepintegration/v2/">
<accountId>115117</accountId>
<orderReference>'.$numerocommande.'</orderReference>
<status>OPEN</status>
<costCenter>'.$numerocommande.'</costCenter>
<orderLine>
<text>Commande Designnailart '.$numerocommande.'</text>
<nbOfItems>1</nbOfItems>
</orderLine>
<customer>
<firstName>'.$prenom.'</firstName>
<lastName>'.$nom.'</lastName>
<deliveryAddress>
<streetName>'.$rue.'</streetName>
<number></number>
<box></box>
<postalCode>'.$codepostal.'</postalCode>
<locality>'.$ville.'</locality>
<countryCode>'.$pays.'</countryCode>
</deliveryAddress>
<email>'.$email.'</email>
<phoneNumber>'.$tel.'</phoneNumber>
</customer>
<deliveryMethod>
<atHome>
<insured>
<additionalInsurance value="1"/>
</insured>
</atHome>
</deliveryMethod>
<totalPrice>0</totalPrice>
</order>
';
break;
//envoi en bpack world sans assurance
case 3:
$repmode= 'envoi en bpack world sans assurance';
$data = '
<order xmlns="http://schema.post.be/shm/deepintegration/v2/">
<accountId>115117</accountId>
<orderReference>'.$numerocommande.'</orderReference>
<status>OPEN</status>
<costCenter>'.$numerocommande.'</costCenter>
<orderLine>
<text>Commande Designnailart '.$numerocommande.'</text>
<nbOfItems>1</nbOfItems>
</orderLine>
<customer>
<firstName>'.$prenom.'</firstName>
<lastName>'.$nom.'</lastName>
<deliveryAddress>
<streetName>'.$rue.'</streetName>
<number></number>
<box></box>
<postalCode>'.$codepostal.'</postalCode>
<locality>'.$ville.'</locality>
<countryCode>'.$pays.'</countryCode>
</deliveryAddress>
<email>'.$email.'</email>
<phoneNumber>'.$tel.'</phoneNumber>
</customer>
<deliveryMethod>
<intBusiness>
</intBusiness>
</deliveryMethod>
<totalPrice>30</totalPrice>
</order>
';
break;
//envoi en bpack world avec assurance
case 4:
$repmode= 'envoi en bpack world avec assurance';
$data = '
<order xmlns="http://schema.post.be/shm/deepintegration/v2/">
<accountId>115117</accountId>
<orderReference>'.$numerocommande.'</orderReference>
<status>OPEN</status>
<costCenter>'.$numerocommande.'</costCenter>
<orderLine>
<text>Commande Designnailart '.$numerocommande.'</text>
<nbOfItems>1</nbOfItems>
</orderLine>
<customer>
<firstName>'.$prenom.'</firstName>
<lastName>'.$nom.'</lastName>
<deliveryAddress>
<streetName>'.$rue.'</streetName>
<number></number>
<box></box>
<postalCode>'.$codepostal.'</postalCode>
<locality>'.$ville.'</locality>
<countryCode>'.$pays.'</countryCode>
</deliveryAddress>
<email>'.$email.'</email>
<phoneNumber>'.$tel.'</phoneNumber>
</customer>
<deliveryMethod>
<intBusiness>
<insured>
<basicInsurance/>
</insured>
</intBusiness>
</deliveryMethod>
<totalPrice>30</totalPrice>
</order>
';
break;
//envoi en bpack 24h sans assurance
case 5:
$repmode= 'envoi en point poste sans assurance';
$data = '
<order xmlns="http://schema.post.be/shm/deepintegration/v2/">
<accountId>115117</accountId>
<orderReference>201106241506</orderReference>
<status>OPEN</status>
<costCenter>costCenter0</costCenter>
<orderLine>
<text>Iphone 4 16GB Black</text>
<nbOfItems>1</nbOfItems>
</orderLine>
<orderLine>
<text>Earphones</text>
<nbOfItems>1</nbOfItems>
</orderLine>
<customer>
<firstName>Jan</firstName>
<lastName>Peeters</lastName>
<deliveryAddress>
<streetName>Dorpsstraat</streetName>
<number>132</number>
<box></box>
<postalCode>1800</postalCode>
<locality>Vilvoorde</locality>
<countryCode>BE</countryCode>
</deliveryAddress>
<email>jan.peeters@provider.be</email>
<phoneNumber>0032499123456</phoneNumber>
</customer>
<deliveryMethod>
<atShop>
<infoPugo language="NL">
<emailAddress>jan.peeters@provider.be</emailAddress>
<pugoId>807170</pugoId>
<pugoName>POINT POSTE SPAR RETAIL STRÉPY</pugoName>
</infoPugo>
<insurance>
<additionalInsurance value="2"/>
</insurance>
<infoDistributed language="NL">
<emailAddress>jan.peeters@provider.be</emailAddress>
</infoDistributed>
</atShop>
</deliveryMethod>
<totalPrice>500</totalPrice>
</order>
';
break;
}
$rc = new RestConnector();
$webserviceUrl = RestConnector::WEBSERVICE_END_POINT.$username.'/orders/';
$options = array (
CURLOPT_URL=>$webserviceUrl, // The webservice url to be called
CURLOPT_HTTPHEADER=>array('Content-type: application/vnd.bpost.shm-order-v2+XML', 'charset: UTF-8'), // Set the correct HTTP header.
CURLOPT_POSTFIELDS=>$data, // The data to post.
CURLOPT_USERPWD=>$username.':'.$password // Username and Password used for basic authentication.
);
$result = $rc->execute('POST',$options); // Perform a standard HTTP POST!
echo '<div><h2>Creation/Modification envoi webservice response:</h2>';
if(strstr($result, "200 OK")){
echo '<p><font color="lime"><span style="font-size:72pt;">OK<br>'.$repmode.'</span></font></p></div>';
} else {
echo '<p><span style="font-size:72pt;"><font color="red"><b>!!! Erreur !!!<br>'.$repmode.'</b></font></span></p><br>'.$result.'</div>';
}
class RestConnector {
const WEBSERVICE_END_POINT = 'https://api.bpost.be/services/shm/';
private $default_options = array (
CURLOPT_SSL_VERIFYPEER=>false, // Make sure to trust the HTTPS certificate.
CURLOPT_HTTPAUTH=>CURLAUTH_BASIC, // Use Basic Authentication.
CURLOPT_TIMEOUT=>30, // Maximum number of seconds to allow cURL functions to execute.
CURLOPT_RETURNTRANSFER=>true, // Return the output of the curl_exec() as a string, for display on screen in this example.
CURLOPT_FAILONERROR=>true // So we can do our own error handling.
);
function execute($httpMethod, $options) {
$ch = curl_init();
curl_setopt_array($ch, $this->default_options);
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod); // Set the HTTP method (GET, POST, PUT).
if ($httpMethod==='GET') {
curl_setopt($ch, CURLOPT_HEADER, false); // Don't include the header in the output.
} else {
curl_setopt($ch, CURLOPT_HEADER, true); // Include the header, because the response will only contain header info, no body.
}
$result = curl_exec($ch);
if (curl_errno($ch)) {
$result = 'ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch);
} else if ($httpMethod==='GET') {
// Parse the result, for pretty display on screen.
$xml = new SimpleXMLElement($result);
$formattedXml = str_replace('>', '>',str_replace('<', '<', $xml->asXML()));
$result = '<pre class="prettyprint">'.str_replace('><', '><br/><', $formattedXml).'</pre>';
}
curl_close($ch);
return $result;
}
}
?>
</body>
</html> |
Partager