gavroche / ups-api
PHP UPS API
Requires
- php: ^7.3 || ^8.0
- ext-dom: *
- ext-simplexml: *
- guzzlehttp/guzzle: ^6.0 || ^7.0
- psr/log: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- phpunit/phpunit: ^9.5.4
Suggests
- ext-soap: Required if you need the Tradeability API of UPS
- v2.x-dev
- 2.1.0
- dev-master / 2.0.x-dev
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.2.2
- 1.2.0
- 1.0.0
- 0.8.0
- 0.7.14
- 0.7.13
- 0.7.12
- 0.7.11
- 0.7.10
- 0.7.9
- 0.7.8
- 0.7.7
- 0.7.6
- 0.7.5
- 0.7.4
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.2
- dev-develop / 0.5.1.x-dev
- 0.5.1
- 0.5.0
- 0.4.0
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- v0.1.9
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1
- dev-feature/add-pickup-create-request
This package is not auto-updated.
Last update: 2024-09-14 13:31:51 UTC
README
此库将所有UPS API封装到一个简单易用的PHP库中。它目前涵盖了Quantum View®、跟踪API、运输API、评级API和运输时间API。请随时贡献。
目录
需求
此库使用PHP 7.1+。
要使用UPS API,您必须从UPS 申请访问密钥。每次请求都必须提供访问密钥、您的UPS用户ID和密码。
安装
建议您通过 Composer 安装PHP UPS API库。为此,运行Composer命令安装PHP UPS API的最新稳定版本
$ composer require gabrielbull/ups-api
如果不使用Composer,您还必须包含以下库: Guzzle、Guzzle Promises、[Guzzle PSR7] (https://github.com/guzzle/psr7)、PHP-Fig PSR Log 和 PHP-Fig HTTP Message。
地址验证类(街道级别)
地址验证类允许您在街道级别验证地址。当地址无效时,将提供建议。
注意:UPS有两个地址验证选项。这是街道级别选项,它包括正常地址验证类的所有选项,并添加了街道级别验证。
目前仅支持美国和波多黎各。
示例
$address = new \Ups\Entity\Address(); $address->setAttentionName('Test Test'); $address->setBuildingName('Test'); $address->setAddressLine1('Address Line 1'); $address->setAddressLine2('Address Line 2'); $address->setAddressLine3('Address Line 3'); $address->setStateProvinceCode('NY'); $address->setCity('New York'); $address->setCountryCode('US'); $address->setPostalCode('10000'); $xav = new \Ups\AddressValidation($accessKey, $userId, $password); $xav->activateReturnObjectOnValidate(); //This is optional try { $response = $xav->validate($address, $requestOption = \Ups\AddressValidation::REQUEST_OPTION_ADDRESS_VALIDATION, $maxSuggestion = 15); } catch (Exception $e) { var_dump($e); }
AddressValidation::validateReturnAVObject()
在上面的代码中 $xav->activateReturnObjectOnValidate()
是完全可选的。调用此方法将导致 AddressValidation::validate()
返回一个 AddressValidationResponse
对象。如果您不调用此方法,validate
将继续像以前一样运行。如果您不调用此方法,将返回一个包含匹配的验证地址或地址模糊不清的第一个候选地址的单个对象。
AddressValidationResponse对象提供了一些方法,使您能够更容易地查询API响应以确定结果。继续上面的示例,返回一个AddressValidationResponse
对象将允许您更具体地处理各种结果
if ($response->noCandidates()) { //Do something clever and helpful to let the use know the address is invalid } if ($response->isAmbiguous()) { $candidateAddresses = $response->getCandidateAddressList(); foreach($candidateAddresses as $address) { //Present user with list of candidate addresses so they can pick the correct one } } if ($response->isValid()) { $validAddress = $response->getValidatedAddress(); //Show user validated address or update their address with the 'official' address //Or do something else helpful... }
参数
地址验证参数有
address
地址对象,如示例中构造的那样requestOption
三个请求选项之一。请参阅文档。默认值 = 地址验证。maxSuggestion
要返回的最大建议数量。最大值 = 50
简单地址验证类
简单的地址验证类允许您验证的范围比之前的类更小。它返回提供的地址的质量评分并提供替代方案。
注意:UPS有两个地址验证选项。这是简单选项。
目前仅支持美国和波多黎各。
示例
$address = new \Ups\Entity\Address(); $address->setStateProvinceCode('NY'); $address->setCity('New York'); $address->setCountryCode('US'); $address->setPostalCode('10000'); $av = new \Ups\SimpleAddressValidation($accessKey, $userId, $password); try { $response = $av->validate($address); var_dump($response); } catch (Exception $e) { var_dump($e); }
参数
简单地址验证参数有
address
地址对象,如示例中构造的那样
QuantumView类
QuantumView类允许您请求Quantum View数据订阅。
示例
$quantumView = new Ups\QuantumView($accessKey, $userId, $password); try { // Get the subscription for all events for the last hour $events = $quantumView->getSubscription(null, (time() - 3600)); foreach($events as $event) { // Your code here echo $event->Type; } } catch (Exception $e) { var_dump($e); }
参数
QuantumView参数有
name
用户请求的订阅名称。如果为空,将返回所有事件。beginDateTime
订阅检索条件的开始日期时间。格式:Y-m-d H:i:s 或 Unix 时间戳。endDateTime
订阅检索条件的结束日期时间。格式:Y-m-d H:i:s 或 Unix 时间戳。fileName
用户请求的特定订阅的文件名。bookmark
将文件标记为下次检索。
如果您提供了beginDateTime
,但没有提供endDateTime
,则默认endDateTime
为当前日期时间。
要使用fileName
参数,请勿提供beginDateTime
。
跟踪类
跟踪类允许您使用UPS跟踪API跟踪运输。
使用跟踪号/邮件创新跟踪号的示例
$tracking = new Ups\Tracking($accessKey, $userId, $password); try { $shipment = $tracking->track('TRACKING NUMBER'); foreach($shipment->Package->Activity as $activity) { var_dump($activity); } } catch (Exception $e) { var_dump($e); }
参数
跟踪参数如下
trackingNumber
包裹的跟踪号。requestOption
可选处理。对于邮件创新,有效的选项只有最后的活动和所有活动。
使用参考号的示例
$tracking = new Ups\Tracking($accessKey, $userId, $password); try { $shipment = $tracking->trackByReference('REFERENCE NUMBER'); foreach($shipment->Package->Activity as $activity) { var_dump($activity); } } catch (Exception $e) { var_dump($e); }
参数
跟踪参数如下
referenceNumber
能够通过参考号跟踪任何UPS包裹或运输。参考号可以是采购订单号、工作号等。参考号在生成运输时提供。requestOption
可选处理。对于邮件创新,有效的选项只有最后的活动和所有活动。
使用带有附加参数的参考号的示例
$tracking = new Ups\Tracking($accessKey, $userId, $password); $tracking->setShipperNumber('SHIPPER NUMBER'); $beginDate = new \DateTime('2016-01-01'); $endDate = new \DateTime('2016-01-31'); $tracking->setBeginDate($beginDate); $tracking->setEndDate($endDate); try { $shipment = $tracking->trackByReference('REFERENCE NUMBER'); foreach($shipment->Package->Activity as $activity) { var_dump($activity); } } catch (Exception $e) { var_dump($e); }
参数shipperNumber、beginDate和endDate是可选的。这些参数可以单独设置。这些参数可以帮助在通过参考号跟踪时缩小搜索范围,因为可能使用的参考号不是唯一的。在通过跟踪号跟踪时,这些参数不是必需的,因为跟踪号是唯一的。
评级类
费率类允许您使用UPS费率API获取运输费率。
示例
$rate = new Ups\Rate( $accessKey, $userId, $password ); try { $shipment = new \Ups\Entity\Shipment(); $shipperAddress = $shipment->getShipper()->getAddress(); $shipperAddress->setPostalCode('99205'); $address = new \Ups\Entity\Address(); $address->setPostalCode('99205'); $shipFrom = new \Ups\Entity\ShipFrom(); $shipFrom->setAddress($address); $shipment->setShipFrom($shipFrom); $shipTo = $shipment->getShipTo(); $shipTo->setCompanyName('Test Ship To'); $shipToAddress = $shipTo->getAddress(); $shipToAddress->setPostalCode('99205'); $package = new \Ups\Entity\Package(); $package->getPackagingType()->setCode(\Ups\Entity\PackagingType::PT_PACKAGE); $package->getPackageWeight()->setWeight(10); // if you need this (depends of the shipper country) $weightUnit = new \Ups\Entity\UnitOfMeasurement; $weightUnit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KGS); $package->getPackageWeight()->setUnitOfMeasurement($weightUnit); $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_IN); $dimensions->setUnitOfMeasurement($unit); $package->setDimensions($dimensions); $shipment->addPackage($package); var_dump($rate->getRate($shipment)); } catch (Exception $e) { var_dump($e); }
参数
rateRequest
必需。包含运输详情的rateRequest对象。
此费率类尚未完成!参数将在完成时添加。
评级运输时间类
费率时间类允许您获取运输费率,如费率类,但响应还将包括时间数据。
示例
$rate = new Ups\RateTimeInTransit( $accessKey, $userId, $password ); try { $shipment = new \Ups\Entity\Shipment(); $shipperAddress = $shipment->getShipper()->getAddress(); $shipperAddress->setPostalCode('99205'); $address = new \Ups\Entity\Address(); $address->setPostalCode('99205'); $shipFrom = new \Ups\Entity\ShipFrom(); $shipFrom->setAddress($address); $shipment->setShipFrom($shipFrom); $shipTo = $shipment->getShipTo(); $shipTo->setCompanyName('Test Ship To'); $shipToAddress = $shipTo->getAddress(); $shipToAddress->setPostalCode('99205'); $package = new \Ups\Entity\Package(); $package->getPackagingType()->setCode(\Ups\Entity\PackagingType::PT_PACKAGE); $package->getPackageWeight()->setWeight(10); // if you need this (depends of the shipper country) $weightUnit = new \Ups\Entity\UnitOfMeasurement; $weightUnit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KGS); $package->getPackageWeight()->setUnitOfMeasurement($weightUnit); $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_IN); $dimensions->setUnitOfMeasurement($unit); $package->setDimensions($dimensions); $shipment->addPackage($package); $deliveryTimeInformation = new \Ups\Entity\DeliveryTimeInformation(); $deliveryTimeInformation->setPackageBillType(\Ups\Entity\DeliveryTimeInformation::PBT_NON_DOCUMENT); $pickup = new \Ups\Entity\Pickup(); $pickup->setDate("20170520"); $pickup->setTime("160000"); $shipment->setDeliveryTimeInformation($deliveryTimeInformation); var_dump($rate->shopRatesTimeInTransit($shipment)); } catch (Exception $e) { var_dump($e); }
参数
rateRequest
必需。包含运输详情的rateRequest对象。
此费率时间类扩展了尚未完成的费率类!参数将在完成时添加。
运输时间类
运输时间类允许您使用UPS运输时间API获取所有运输时间。
示例
$timeInTransit = new Ups\TimeInTransit($access, $userid, $passwd); try { $request = new \Ups\Entity\TimeInTransitRequest; // Addresses $from = new \Ups\Entity\AddressArtifactFormat; $from->setPoliticalDivision3('Amsterdam'); $from->setPostcodePrimaryLow('1000AA'); $from->setCountryCode('NL'); $request->setTransitFrom($from); $to = new \Ups\Entity\AddressArtifactFormat; $to->setPoliticalDivision3('Amsterdam'); $to->setPostcodePrimaryLow('1000AA'); $to->setCountryCode('NL'); $request->setTransitTo($to); // Weight $shipmentWeight = new \Ups\Entity\ShipmentWeight; $shipmentWeight->setWeight($totalWeight); $unit = new \Ups\Entity\UnitOfMeasurement; $unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KGS); $shipmentWeight->setUnitOfMeasurement($unit); $request->setShipmentWeight($shipmentWeight); // Packages $request->setTotalPackagesInShipment(2); // InvoiceLines $invoiceLineTotal = new \Ups\Entity\InvoiceLineTotal; $invoiceLineTotal->setMonetaryValue(100.00); $invoiceLineTotal->setCurrencyCode('EUR'); $request->setInvoiceLineTotal($invoiceLineTotal); // Pickup date $request->setPickupDate(new DateTime); // Get data $times = $timeInTransit->getTimeInTransit($request); foreach($times->ServiceSummary as $serviceSummary) { var_dump($serviceSummary); } } catch (Exception $e) { var_dump($e); }
参数
timeInTransitRequest
必需。包含运输详情的timeInTransitRequest对象,参见示例。
定位器类
定位器类允许您搜索UPS接入点位置。
示例
$locatorRequest = new \Ups\Entity\LocatorRequest; $originAddress = new \Ups\Entity\OriginAddress; $address = new \Ups\Entity\AddressKeyFormat; $address->setCountryCode('NL'); $originAddress->setAddressKeyFormat($address); $geocode = new \Ups\Entity\GeoCode; $geocode->setLatitude(52.0000); $geocode->setLongitude(4.0000); $originAddress->setGeoCode($geocode); $locatorRequest->setOriginAddress($originAddress); $translate = new \Ups\Entity\Translate; $translate->setLanguageCode('ENG'); $locatorRequest->setTranslate($translate); $acccessPointSearch = new \Ups\Entity\AccessPointSearch; $acccessPointSearch->setAccessPointStatus(\Ups\Entity\AccessPointSearch::STATUS_ACTIVE_AVAILABLE); $locationSearch = new \Ups\Entity\LocationSearchCriteria; $locationSearch->setAccessPointSearch($acccessPointSearch); $locationSearch->setMaximumListSize(25); $locatorRequest->setLocationSearchCriteria($locationSearch); $unitOfMeasurement = new \Ups\Entity\UnitOfMeasurement; $unitOfMeasurement->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KM); $unitOfMeasurement->setDescription('Kilometers'); $locatorRequest->setUnitOfMeasurement($unitOfMeasurement); try { // Get the locations $locator = new Ups\Locator($accessKey, $userId, $password); $locations = $locator->getLocations($locatorRequest, \Ups\Locator::OPTION_UPS_ACCESS_POINT_LOCATIONS); foreach($locations->SearchResults->DropLocation as $location) { // Your code here var_dump($location); } } catch (Exception $e) { var_dump($e); }
参数
定位器类参数如下
locatorRequest
必需。包含请求详情的locatorRequest对象,参见示例。requestOption
可选。您要搜索的位置类型。
贸易性类
贸易性类允许您获取国际运输的数据
- 着陆成本(例如,关税)
- 拒绝方筛选器
- 进口合规性
- 出口许可证检测
注意:目前仅实现了着陆成本API。
⚠️ 贸易性仅通过SOAP API提供。因此,您必须在系统上安装SOAP扩展。
示例
// Build request $landedCostRequest = new \Ups\Entity\Tradeability\LandedCostRequest; // Build shipment $shipment = new \Ups\Entity\Tradeability\Shipment; $shipment->setOriginCountryCode('NL'); $shipment->setDestinationCountryCode('US'); $shipment->setDestinationStateProvinceCode('TX'); $shipment->setResultCurrencyCode('EUR'); $shipment->setTariffCodeAlert(1); $shipment->setTransportationMode(\Ups\Entity\Tradeability\Shipment::TRANSPORT_MODE_AIR); $shipment->setTransactionReferenceId('1'); // Build product $product = new \Ups\Entity\Tradeability\Product; $product->setProductName('Test'); $tariffInfo = new \Ups\Entity\Tradeability\TariffInfo; $tariffInfo->setTariffCode('5109.90.80.00'); $product->setTariffInfo($tariffInfo); $product->setProductCountryCodeOfOrigin('BD'); $unitPrice = new \Ups\Entity\Tradeability\UnitPrice; $unitPrice->setMonetaryValue(250); $unitPrice->setCurrencyCode('EUR'); $product->setUnitPrice($unitPrice); $weight = new Ups\Entity\Tradeability\Weight; $weight->setValue(0.83); $unitOfMeasurement = new \Ups\Entity\Tradeability\UnitOfMeasurement; $unitOfMeasurement->setCode('kg'); $weight->setUnitOfMeasurement($unitOfMeasurement); $product->setWeight($weight); $quantity = new \Ups\Entity\Tradeability\Quantity; $quantity->setValue(5); $unitOfMeasurement = new \Ups\Entity\Tradeability\UnitOfMeasurement; $unitOfMeasurement->setCode(\Ups\Entity\Tradeability\UnitOfMeasurement::PROD_PIECES); $quantity->setUnitOfMeasurement($unitOfMeasurement); $product->setQuantity($quantity); $product->setTariffCodeAlert(1); // Add product to shipment $shipment->addProduct($product); // Query request $queryRequest = new \Ups\Entity\Tradeability\QueryRequest; $queryRequest->setShipment($shipment); $queryRequest->setSuppressQuestionIndicator(true); // Build $landedCostRequest->setQueryRequest($queryRequest); try { // Get the data $api = new Ups\Tradeability($accessKey, $userId, $password); $result = $api->getLandedCosts($landedCostRequest); var_dump($result); } catch (Exception $e) { var_dump($e); }
参数
对于着陆成本调用,参数如下
landedCostRequest
必需。包含请求详情的landedCostRequest对象,参见示例。
运输类
运输类允许您注册运输。这也包括退货运输。
运输流程包括2个步骤
- 确认:向UPS发送信息以获取验证并获取您可以使用以接受运输的摘要。
- 接受:最终确定运输,将其标记为即将运输。获取标签和附加信息。
请注意,这只是一个示例。您的用例可能需要向UPS发送更多信息或更少信息。
在示例中,$return
用于展示如何处理返回值。
示例
// Start shipment $shipment = new Ups\Entity\Shipment; // Set shipper $shipper = $shipment->getShipper(); $shipper->setShipperNumber('XX'); $shipper->setName('XX'); $shipper->setAttentionName('XX'); $shipperAddress = $shipper->getAddress(); $shipperAddress->setAddressLine1('XX'); $shipperAddress->setPostalCode('XX'); $shipperAddress->setCity('XX'); $shipperAddress->setStateProvinceCode('XX'); // required in US $shipperAddress->setCountryCode('XX'); $shipper->setAddress($shipperAddress); $shipper->setEmailAddress('XX'); $shipper->setPhoneNumber('XX'); $shipment->setShipper($shipper); // To address $address = new \Ups\Entity\Address(); $address->setAddressLine1('XX'); $address->setPostalCode('XX'); $address->setCity('XX'); $address->setStateProvinceCode('XX'); // Required in US $address->setCountryCode('XX'); $shipTo = new \Ups\Entity\ShipTo(); $shipTo->setAddress($address); $shipTo->setCompanyName('XX'); $shipTo->setAttentionName('XX'); $shipTo->setEmailAddress('XX'); $shipTo->setPhoneNumber('XX'); $shipment->setShipTo($shipTo); // From address $address = new \Ups\Entity\Address(); $address->setAddressLine1('XX'); $address->setPostalCode('XX'); $address->setCity('XX'); $address->setStateProvinceCode('XX'); $address->setCountryCode('XX'); $shipFrom = new \Ups\Entity\ShipFrom(); $shipFrom->setAddress($address); $shipFrom->setName('XX'); $shipFrom->setAttentionName($shipFrom->getName()); $shipFrom->setCompanyName($shipFrom->getName()); $shipFrom->setEmailAddress('XX'); $shipFrom->setPhoneNumber('XX'); $shipment->setShipFrom($shipFrom); // Sold to $address = new \Ups\Entity\Address(); $address->setAddressLine1('XX'); $address->setPostalCode('XX'); $address->setCity('XX'); $address->setCountryCode('XX'); $address->setStateProvinceCode('XX'); $soldTo = new \Ups\Entity\SoldTo; $soldTo->setAddress($address); $soldTo->setAttentionName('XX'); $soldTo->setCompanyName($soldTo->getAttentionName()); $soldTo->setEmailAddress('XX'); $soldTo->setPhoneNumber('XX'); $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('XX'); // 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(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('XX'); // 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($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) ['AccountNumber' => $shipper->getShipperNumber()])); // 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) { var_dump($e); }
如果您想从带有 $accept 的 UPS 运输标签图像数据创建可打印文件,可以使用以下类似方法:
$label_file = $order_id . ".gif"; $base64_string = $accept->PackageResults->LabelImage->GraphicImage; $ifp = fopen($label_file, 'wb'); fwrite($ifp, base64_decode($base64_string)); fclose($ifp);
参数
对于运输 confirm
调用,参数如下:
- $validation UPS_Shipping::REQ_* 常量(或 null)。必需
- $shipment 运输数据容器。必需
- $labelSpec 标签规范数据。可选
- $receiptSpec 运输请求收据规范数据。可选
对于运输 accept
调用,参数如下:
- $shipmentDigest 从 ShipConfirm 请求接收到的 UPS 运输摘要。必需
运输服务选项
Shipment Service Options 类允许您注册额外的运输选项。这包括:
- 添加或修改电子邮件通知:管理此运输的更新。
- 周六商业服务:获取您的运输周末配送。
- 仅向收件人地址交付:不要在 UPS 位置重新路由以供客户取货。
- UPS 碳中和运输感谢您抵消运输的环境影响!:国内和国际运输收取象征性费用。
在示例中,使用 ShipmentServiceOptions 类来展示如何将运输附加选项添加到运输中。
运输服务选项示例
// Start shipment $shipment = new Ups\Entity\Shipment; // Create Shipment Service Options Class $shipmentOptions = new Ups\Entity\ShipmentServiceOptions; // Setting the Carbon Neutral Additional Option, you can set your desired one. $shipmentOptions->setUPScarbonneutralIndicator(); // Set Shipment Service Options Class $shipment->setShipmentServiceOptions($shipmentOptions);
日志记录
所有构造函数都接受一个 PSR-3 兼容的记录器。
除此之外,主要的 UPS 类有一个公开方法 setLogger
,可以在构造函数运行后设置它。
请求和响应(包括 XML,无访问密钥)以 DEBUG 级别记录。在 INFO 级别仅报告事件,不报告 XML 内容。更严重的问题(例如无连接)以更高的严重性记录。
使用 Monolog 的示例
// Create logger $log = new \Monolog\Logger('ups'); $log->pushHandler(new \Monolog\Handler\StreamHandler('logs/ups.log', \Monolog\Logger::DEBUG)); // Create Rate object + insert logger $rate = new Ups\Rate($key, $username, $password, $useIntegration, $log);
许可证
PHP UPS API 根据 MIT 许可证 (MIT) 许可。