gabrielbull / php-ups-api

PHP Wrapper for all UPS API
MIT License
456 stars 255 forks source link

The requested accessory option is unavailable between the selected locations. (121211) #284

Closed atif-majeed closed 4 years ago

atif-majeed commented 4 years ago

I'm facing the issue above my To and From addresses is here

// To address $address = new \Ups\Entity\Address(); $address->setAddressLine1('Paasheuvelweg 39'); $address->setPostalCode('1105BG'); $address->setCity('Paasheuvelweg'); $address->setStateProvinceCode('NH'); // Required in US $address->setCountryCode('NL'); $shipTo = new \Ups\Entity\ShipTo(); $shipTo->setAddress($address); $shipTo->setCompanyName('Milnga Group'); $shipTo->setAttentionName('Larsa'); $shipTo->setEmailAddress('abc@gmail.com'); $shipTo->setPhoneNumber('03222222332'); $shipment->setShipTo($shipTo);

// From address
$address = new \Ups\Entity\Address();
$address->setAddressLine1('Vasteland 80');
$address->setPostalCode('3011BN');
$address->setCity('Rotterdam');
$address->setStateProvinceCode('SH');  
$address->setCountryCode('NL');
$shipFrom = new \Ups\Entity\ShipFrom();
$shipFrom->setAddress($address);
$shipFrom->setName('Milnga Group Rotterdam');
$shipFrom->setAttentionName($shipFrom->getName());
$shipFrom->setCompanyName($shipFrom->getName());
$shipFrom->setEmailAddress('abc@gmail.com');
$shipFrom->setPhoneNumber('03222222332');
$shipment->setShipFrom($shipFrom);
gabrielbull commented 4 years ago

@atif-majeed This library has no maintainer and is looking for one.

AlexTicsur commented 3 years ago

Hi @atif-majeed, i have the same problem, have you found any solution?

aatif604 commented 3 years ago

I think you are using an older version

aatif604 commented 3 years ago

require DIR . '/vendor/autoload.php'; $accessKey = ""; $userId= ""; $password=""; $return = false; $shipment = new Ups\Entity\Shipment; // Set shipper $shipper = $shipment->getShipper(); $shipper->setShipperNumber(""); $shipper->setName("Larsa Group"); $shipper->setAttentionName("Larsa Group"); $shipperAddress = $shipper->getAddress(); $shipperAddress->setAddressLine1('Paasheuvelweg 39'); //$shipperAddress->setAddressLine2('245 W'); //$shipperAddress->setAddressLine3('29th St'); $shipperAddress->setPostalCode('1105BG'); $shipperAddress->setCity('Paasheuvelweg'); $shipperAddress->setCountryCode('NL'); $shipperAddress->setStateProvinceCode('NH'); $shipper->setAddress($shipperAddress); $shipper->setEmailAddress(''); $shipper->setPhoneNumber('0675702114'); $shipment->setShipper($shipper);

// To address
$address = new \Ups\Entity\Address();
$address->setAddressLine1('Paasheuvelweg 39');
//$address->setAddressLine2('245 W');
//$address->setAddressLine3('29th St');
$address->setPostalCode('1105BG');
$address->setCity('Paasheuvelweg');
$address->setCountryCode('NL');
$address->setStateProvinceCode('NH');
$shipTo = new \Ups\Entity\ShipTo();
$shipTo->setAddress($address);
$shipTo->setCompanyName('Larsa Group');
$shipTo->setAttentionName('Larsa Group');
$shipTo->setEmailAddress('ups@larsa-group.com'); 
$shipTo->setPhoneNumber('0675702114');
$shipment->setShipTo($shipTo);

// From address

$address = new \Ups\Entity\Address();
$address->setAddressLine1('Trouwlaan 54');
//$address->setAddressLine2('795 E DRAGRAM');
$address->setPostalCode('5021WH');
$address->setCity('Tilburg');
$address->setCountryCode('NL');
$address->setStateProvinceCode('NB');
$shipFrom = new \Ups\Entity\ShipFrom();
$shipFrom->setAddress($address);
$shipFrom->setName('Joseph Daniel');
$shipFrom->setAttentionName($shipFrom->getName());
$shipFrom->setCompanyName($shipFrom->getName());
$shipFrom->setEmailAddress('ups@larsa-group.com');
$shipFrom->setPhoneNumber('0675702114');
$shipment->setShipFrom($shipFrom);

// // Sold to
// $address = new \Ups\Entity\Address();
// $address->setAddressLine1('350 5th Avenue');
// $address->setPostalCode('10118');
// $address->setCity('New York');
// $address->setCountryCode('US');
// $address->setStateProvinceCode('NY');
// $soldTo = new \Ups\Entity\SoldTo;
// $soldTo->setAddress($address);
// $soldTo->setAttentionName('Joseph Daniel');
// $soldTo->setCompanyName($soldTo->getAttentionName());
// $soldTo->setEmailAddress('sibi.nandhu@gmail.com');
// $soldTo->setPhoneNumber('8903444595');
// $shipment->setSoldTo($soldTo);

// Set service
$service = new \Ups\Entity\Service;
$service->setCode(\Ups\Entity\Service::S_STANDARD);
$service->setDescription($service->getName());
$shipment->setService($service);

// Mark as a return (if return)
if ($return) {
    $returnService = new \Ups\Entity\ReturnService;
    $returnService->setCode(\Ups\Entity\ReturnService::PRINT_RETURN_LABEL_PRL);
    $shipment->setReturnService($returnService);
}

// Set description
$shipment->setDescription('Test');

// Add Package
$package = new \Ups\Entity\Package();
$package->getPackagingType()->setCode(\Ups\Entity\PackagingType::PT_PACKAGE);
$package->getPackageWeight()->setWeight(1);
$unit = new \Ups\Entity\UnitOfMeasurement;
$unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KGS);
$package->getPackageWeight()->setUnitOfMeasurement($unit);

// Set dimensions
$dimensions = new \Ups\Entity\Dimensions();
$dimensions->setHeight(50);
$dimensions->setWidth(50);
$dimensions->setLength(50);
$unit = new \Ups\Entity\UnitOfMeasurement;
$unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_CM);
$dimensions->setUnitOfMeasurement($unit);
$package->setDimensions($dimensions);

// Add descriptions because it is a package
$package->setDescription('Test');

// Add this package
$shipment->addPackage($package);

// Set Reference Number
$referenceNumber = new \Ups\Entity\ReferenceNumber;
if ($return) {
    $referenceNumber->setCode(\Ups\Entity\ReferenceNumber::CODE_RETURN_AUTHORIZATION_NUMBER);
    $referenceNumber->setValue("12345678");
} else {
    $referenceNumber->setCode(\Ups\Entity\ReferenceNumber::CODE_INVOICE_NUMBER);
    $referenceNumber->setValue("98765432");
}
$shipment->setReferenceNumber($referenceNumber);

// Set payment information
$shipment->setPaymentInformation(new \Ups\Entity\PaymentInformation('prepaid', (object)array('AccountNumber' => '')));

// Ask for negotiated rates (optional)
// $rateInformation = new \Ups\Entity\RateInformation;
// $rateInformation->setNegotiatedRatesIndicator(1);
// $shipment->setRateInformation($rateInformation);

// Get shipment info
try {
    $api = new Ups\Shipping($accessKey, $userId, $password); 

    $confirm = $api->confirm(\Ups\Shipping::REQ_VALIDATE, $shipment);
    //echo "<pre>";var_dump($confirm, true);echo "</pre>"; // Confirm holds the digest you need to accept the result

    if ($confirm) {
        $accept = $api->accept($confirm->ShipmentDigest);
        //print_r( $accept);
         $label_file = "xyz" . ".jpeg"; 
            $base64_string = $accept->PackageResults->LabelImage->GraphicImage;

            $ifp = fopen($label_file, 'wb');
        fwrite($ifp, base64_decode($base64_string));
        // $dir = "ups/"; // trailing slash is important
  //        $file = $label_file;
  //         header('Content-Type: application/pdf');
  //        header('Content-Disposition: attachment; filename="gfgpdf.pdf"');
        // echo readfile($file);

        fclose($ifp);

        //echo "<pre>";var_dump($accept, true);echo "</pre>"; // Accept holds the label and additional information
    }
} catch (\Exception $e) {
    echo "<pre>";var_dump($e, true);echo "</pre>";
}
aatif604 commented 3 years ago

Kindly use above code