Advertisement
skazhikadyadya

Untitled

Dec 13th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.45 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', 1);
  5.  
  6.  
  7.  
  8.  
  9. require 'vendor/autoload.php';
  10.  
  11. use GuzzleHttp\Client;
  12.  
  13.  
  14.         $client = new \GuzzleHttp\Client(['headers' => ['API_USERNAME' => 'wandogren',  'API_PASSWORD' => 'aehebpbzcwwg']]);
  15.         $url = "https://www.netparcel.com/shipping_service";
  16.  
  17.         $ratesRequest = [
  18.             "rate" => [
  19.                 "origin" => [
  20.                     "country" => "CA",
  21.                     "postal_code" => "V3N4R3",
  22.                     "province" => "ON",
  23.                     "city" => "Burnaby",
  24.                     "name" => null,
  25.                     "address1" => "90 Maverick",
  26.                     "address2" => null,
  27.                     "address3" => null,
  28.                     "phone" => null,
  29.                     "fax" => null,
  30.                     "address_type" => null,
  31.                     "company_name" => null
  32.                 ],
  33.                 "destination" => [
  34.                     "country" => "CA",
  35.                     "postal_code" => "l4j7y9",
  36.                     "province" => "ON",
  37.                     "city" => "vaughan",
  38.                     "name" => "riz mer",
  39.                     "address1" => "90 street",
  40.                     "address2" => "",
  41.                     "address3" => null,
  42.                     "phone" => "6479988858",
  43.                     "fax" => null,
  44.                     "address_type" => null,
  45.                     "company_name" => ""
  46.                 ],                
  47.                 "items" => [
  48.                     [
  49.                         "name" => "My TEST - My PRODUCT",
  50.                         "sku" => "12345",
  51.                         "quantity" => 1,
  52.                         "weight" => 30,
  53.                         "weightUnit" => "lbs",
  54.                         "price" => 1200,
  55.                         "vendor" => "riznetparcel",
  56.                         "requires_shipping" => true,
  57.                         "taxable" => true,
  58.                         "fulfillment_service" => "manual",
  59.                         "product_id" => 179093853,
  60.                         "variant_id" => 410333945
  61.                     ]
  62.                 ],
  63.                 "packaging_information" => [
  64.                     [
  65.                         "packaging_type" => "My Packaging",
  66.                         "packages" => [
  67.                             "length" => 1,
  68.                             "width" => 1,
  69.                             "height" => 1,
  70.                             "weight" => 5,
  71.                             "weightUnit" => "lbs",
  72.                             "insurance_amount" => 200.00,
  73.                             "description" => "Test",
  74.                             "freight_class" => "77.5",
  75.                             "nmfc_code" => "12345",
  76.                             "type" => "pallet"
  77.                         ]
  78.                     ]              
  79.                 ]
  80.             ]
  81.         ];
  82.  
  83.  
  84.  
  85.         echo "<pre>";
  86.         print_r(json_encode($ratesRequest));
  87.         echo "</pre>";
  88.  
  89.         $postRequest = $client->post( $url,  ['body' => json_encode($ratesRequest)] );
  90.         $postStatusCode = $postRequest->getStatusCode();
  91.         $postReason = $postRequest->getReasonPhrase();
  92.         $postResponse = $postRequest->getBody();
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.         echo "Get Status code: " . $postStatusCode . "<br>";
  100.         echo "Reason:" . $postReason . "<br>";
  101.  
  102.         $stringBody = (string) $postResponse;
  103.  
  104.         echo $stringBody;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement