gabrielbull / php-ups-api

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

Shiping api ups .. it show exception that this shipment/referenumber is not allowed for this shipment (120541). #327

Open 4455667788 opened 3 years ago

4455667788 commented 3 years ago

Hello below is my code and i face issue while creating shipping label , please do guide me

The error is : Notice: Undefined variable: return in /home/ocanalytica/public_html/ups/ups-test/check.php on line 92

Notice: Undefined variable: return in /home/ocanalytica/public_html/ups/ups-test/check.php on line 162 errorobject(Ups\Exception\InvalidResponseException)#52 (7) { ["message":protected]=> string(75) "Failure: Shipment/ReferenceNumber is not allowed for this shipment (120541)" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(120541) ["file":protected]=> string(89) "/home/ocanalytica/public_html/ups/ups-test/UPS/vendor/gabrielbull/ups-api/src/Request.php" ["line":protected]=> int(145) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(90) "/home/ocanalytica/public_html/ups/ups-test/UPS/vendor/gabrielbull/ups-api/src/Shipping.php" ["line"]=> int(81) .............

My code is : $accessKey = '***'; $userId = ''; $password = '786@Ups';

// Start shipment $shipment = new Ups\Entity\Shipment;

// Set shipper $shipper = $shipment->getShipper(); $shipper->setShipperNumber('69R237'); $shipper->setName('Profiix'); $shipper->setAttentionName('Umer'); $shipperAddress = $shipper->getAddress(); $shipperAddress->setAddressLine1('11709 South Orange Blossom Trail'); $shipperAddress->setPostalCode('32837'); $shipperAddress->setCity('Orlando'); $shipperAddress->setStateProvinceCode('FL'); // required in US $shipperAddress->setCountryCode('US'); $shipper->setAddress($shipperAddress); $shipper->setEmailAddress('umer.shahzad.softwareengineer@gmail.com'); $shipper->setPhoneNumber('16092142857'); $shipment->setShipper($shipper);

// To address $address = new \Ups\Entity\Address(); $address->setAddressLine1('591 Grand Avenue'); $address->setPostalCode('92069'); $address->setCity('San Marcos'); $address->setStateProvinceCode('CA'); // Required in US $address->setCountryCode('US'); $shipTo = new \Ups\Entity\ShipTo(); $shipTo->setAddress($address); $shipTo->setCompanyName('profiix'); $shipTo->setAttentionName('profiix Franchise'); $shipTo->setEmailAddress('umer.shahzad.softwareengineer@gmail.com'); //$shipTo->setPhoneNumber(''); $shipment->setShipTo($shipTo);

// From address $address = new \Ups\Entity\Address(); $address->setAddressLine1('11709 S Orange Blossom Trail #106'); $address->setPostalCode('32837'); $address->setCity('Orlando'); $address->setStateProvinceCode('FL'); $address->setCountryCode('US'); $shipFrom = new \Ups\Entity\ShipFrom(); $shipFrom->setAddress($address); $shipFrom->setName('Umer Shahzad'); $shipFrom->setAttentionName($shipFrom->getName()); $shipFrom->setCompanyName($shipFrom->getName()); $shipFrom->setEmailAddress('umer.shahzad@ocanalytica.com'); $shipFrom->setPhoneNumber('16092142857'); $shipment->setShipFrom($shipFrom);

/ // Sold to $address = new \Ups\Entity\Address(); $address->setAddressLine1('4002 Promenade Square Dr'); $address->setPostalCode('32837'); $address->setCity('Orlando'); $address->setCountryCode('US'); $address->setStateProvinceCode('FL'); $soldTo = new \Ups\Entity\SoldTo; $soldTo->setAddress($address); $soldTo->setAttentionName('Pro'); $soldTo->setCompanyName($soldTo->getAttentionName()); $soldTo->setEmailAddress('a.kungfu.man.umer@gmail.com'); $soldTo->setPhoneNumber('16092142857'); $shipment->setSoldTo($soldTo); /

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

//$return ='';

// 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('For testing');

/* // 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 Package Service Options $packageServiceOptions = new \Ups\Entity\PackageServiceOptions(); $packageServiceOptions->setShipperReleaseIndicator(true); $package->setPackageServiceOptions($packageServiceOptions);

// Set dimensions $dimensions = new \Ups\Entity\Dimensions(); $dimensions->setHeight(1); $dimensions->setWidth(1); $dimensions->setLength(1); $unit = new \Ups\Entity\UnitOfMeasurement; $unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_IN); $dimensions->setUnitOfMeasurement($unit); $package->setDimensions($dimensions); */ // Add Package $package = new \Ups\Entity\Package(); $package->getPackagingType()->setCode(\Ups\Entity\PackagingType::PT_PACKAGE); $package->getPackageWeight()->setWeight(10); $unit = new \Ups\Entity\UnitOfMeasurement; $unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KGS); $package->getPackageWeight()->setUnitOfMeasurement($unit);

// Set Package Service Options $packageServiceOptions = new \Ups\Entity\PackageServiceOptions(); $packageServiceOptions->setShipperReleaseIndicator(true); $package->setPackageServiceOptions($packageServiceOptions);

// Set dimensions $dimensions = new \Ups\Entity\Dimensions(); $dimensions->setHeight(10); $dimensions->setWidth(10); $dimensions->setLength(10); $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('Package weight');

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

$order_id = '69R237';

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

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

// 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); var_dump($confirm); // Confirm holds the digest you need to accept the result

if ($confirm) { $accept = $api->accept($confirm->ShipmentDigest); var_dump($accept); // Accept holds the label and additional information } } catch (\Exception $e) { echo "error"; var_dump($e); }

timramseyjr commented 2 years ago

I ran into a similar situation and fixed it by adding the reference number to the package instead of the shipment

$package->setReferenceNumber($referencenumber);

joyzalte commented 1 year ago

Hello All, If I implement the below code. $package->setReferenceNumber($referencenumber);

It's giving the below error. Invalid merchandise description of package

Can any one help on that?