UPS API wsdl soap call - cannot set multiple packages

早过忘川 提交于 2019-12-11 05:17:36

问题


I am using wsdl SOAP call in PHP for UPS API. The request object have package information, from/to zipcodes, and other information. I want to set multiple packages but it shows error when more than one package is added in the request object.

I am trying to assign multiple packages by pushing package array in the $request['Shipment']['Package'] array. Something is wrong in this part.

Here is my code:

$request['Request'] = array('RequestOption' => 'Shop');
    $request['PickupType'] = array('Code' => '01', 'Description' => 'Daily Pickup');
    $request['CustomerClassification'] = array('Code' => '01', 'Description' => 'Classfication');
    $request['Shipment']['Shipper'] = array(
          // Shipper information here
        )
    );
    $request['Shipment']['ShipFrom'] = array('Address' => array(
        'PostalCode' => XX,
        'CountryCode' => 'US'
    )
    );
    $request['Shipment']['ShipTo'] = array('Address' => array(
        'PostalCode' => XX,
        'CountryCode' => 'US'
    )
    );
    $request['Shipment']['Service'] = array('Code' => '03', 'Description' => 'Service Code');

   // Multiple packages are added to the request
    $request['Shipment']['Package'] = array();
    foreach ($packages as $package) {
        $pkg = array();
        $pkg['PackagingType'] = array(
            'Code' => '02',
            'Description' => 'Rate'
        );
        $pkg['PackageWeight'] = array(
            'Weight' => (int)$package["weight"],
            'UnitOfMeasurement' => array('Code' => 'LBS', 'Description' => 'Pounds')
        );
        $pkg['Dimensions'] = array(
            'Length' => (int)$package["length"],
            'Width' => (int)$package["width"],
            'Height' => (int)$package["height"],
            'UnitOfMeasurement' => array('Code' => 'IN', 'Description' => 'inches')
        );

        array_push($request['Shipment']['Package'], $pkg);
    }
   // END packages

    $request['Shipment']['ShipmentServiceOptions'] = '';
    $request['Shipment']['LargePackageIndicator'] = '';

    $mode = array(
        'trace' => 1
    );
    $wsdl = PATH_WSDL . DS . 'RateWS.wsdl';
    $ups_client = new SoapClient($wsdl, $mode);
    $usernameToken['Username'] = XX);
    $usernameToken['Password'] = XX;
    $serviceAccessLicense['AccessLicenseNumber'] = XX;
    $upss['UsernameToken'] = $usernameToken;
    $upss['ServiceAccessToken'] = $serviceAccessLicense;

    $header = new SoapHeader('http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0', 'UPSSecurity', $upss);
    $ups_client->__setSoapHeaders($header);
    $resp = $ups_client->__soapCall('ProcessRate', array($request));
    if ($resp->Response->ResponseStatus->Description == 'Success') {
        // Dealing with response here.
    }

来源:https://stackoverflow.com/questions/47240148/ups-api-wsdl-soap-call-cannot-set-multiple-packages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!