如何将已创建的标签添加到联邦快递取件
Posted
技术标签:
【中文标题】如何将已创建的标签添加到联邦快递取件【英文标题】:How to add already created label to fedex pickup 【发布时间】:2019-09-17 15:44:37 【问题描述】:我正在创建标签,一切正常。 但是如何将已创建的标签连接到 FEDEX 取货。
try
/*
* Per explicit request fromthe FROM
* address should always be the address of their headquarters
*/
/** @var Address $fromAddress */
$fromAddress = Address::create([
"street1" => $params['street'],
"street2" => "",
"city" => $params['city'],
"state" => $params['state'],
"zip" => $params['zipCode'],
"country" => $params['country'],
"company" => $from['name'],
"phone" => $from['phone']
]);
if (!$fromAddress->valid()) return self::jsonError('There was an error configuring your shipment. Please try again.');
/** @var Address $toAddress */
$toAddress = Address::create([
"street1" => $params['toStreet'],
"street2" => "",
"city" => $params['toCity'],
"state" => $params['toState'],
"zip" => $params['toZipCode'],
"country" => $params['toCountry'],
"company" => $params['toName'],
"phone" => $params['toPhone']
]);
if (!$toAddress->valid()) return self::jsonError('Address of the requested destination is invalid. Please choose another');
/** @var Parcel $parcel */
$parcel = Parcel::create(array(
"length" => 13,
"width" => 11,
"height" => 2,
"weight" => 1,
"predefined_package" => "FedExPak"
));
if (!$parcel->valid()) return self::jsonError('There was a problem validating parcel dimensions.');
/** @var Shipment $shipment */
$shipment = Shipment::create([
"to_address" => $toAddress,
"from_address" => $fromAddress,
"parcel" => $parcel,
"options" => [
"print_custom_1" => 'Case ' . $project->caseId->get()
]
]);
if (!$shipment->valid()) return self::jsonError('There was a problem creating a valid shipment. Please try again.');
catch (\Exception $e)
return self::jsonError('There was a problem contacting the shipping service.' . $e->getMessage());
try
// determine rate(s)
$shipment->get_rates();
$shippingService = 'FEDEX_2_DAY';
$defaultService = 'FEDEX_2_DAY';
if (in_array($params['provide_option'], ['FedEx Dropoff', 'Dropoff']))
$shippingCarrier = 'FedEx';
$defaultCarrier = 'FedEx';
foreach ($shipment->rates as $rate)
/** @var Rate $rate */
if ($rate->carrier == $shippingCarrier && $rate->service == $shippingService) $shippingRate = $rate;
else if ($rate->carrier == $defaultCarrier && $rate->service == $defaultService) $defaultRate = $rate;
catch (\Exception $e)
return self::jsonError('There was a problem determining shipping rates for the given shipping options. Please contact your customer representative.' . $e->getMessage());
// buy label
try
if ($shippingRate == null)
// go with default rate if available or try to buy the lowest rate for available carriers
$shippingRate = ($defaultRate != null) ?
$defaultRate : $shipment->lowest_rate($carriers);
$shipment->buy(['rate' => $shippingRate]);
catch (\Exception $e)
return self::jsonError('There was a problem creating the shipment. Please review your shipping information.' . $e->getMessage());
$_SESSION['createdShipment'] = $shipment;
我在这里尝试添加一个已经创建的标签来取货
$_SESSION['createdShipment']
它在条件下工作。在代码中看到
但我收到错误Unable to create pickup, the carrier associated with the batch shipments is inconsistent.
try
$mindate = $params['pickup-date-from'] . " " . $params['pickup-time-from'];
$maxdate = $params['pickup-date-to'] . " " . $params['pickup-time-to'];
if(!empty($params['addressPickup']) AND count($params['addressPickup']) == 4)
$address = Address::create([
"street1" => $params['addressPickup']['pickup_street'],
"street2" => $params['street2'],
"city" => $params['addressPickup']['pickup_city'],
"state" => $params['addressPickup']['pickup_state'],
"zip" => $params['addressPickup']['pickup_zipCode'],
"country" => $params['country'],
"company" => $from['name'],
"phone" => $from['phone']
]);
$shipment = $_SESSION['createdShipment'];
else
$address = Address::create([
"street1" => $params['street'],
"street2" => $params['street2'],
"city" => $params['city'],
"state" => $params['state'],
"zip" => $params['zipCode'],
"country" => $params['country'],
"company" => $from['name'],
"phone" => $from['phone']
]);
// Cancel FedEx Pickup if has been bought
$this->requestCancelFedExPickup($params, $user, $project, $db, $api, $accountConfig, $oldsession);
$pickup = \EasyPost\Pickup::create(array(
"address" => $address,
"shipment" => $shipment,
"reference" => "fedex_pickup_refr",
"min_datetime" => date("Y-m-d H:i:s", strtotime($mindate)),
"max_datetime" => date("Y-m-d H:i:s", strtotime($maxdate)),
"is_account_address" => false,
"instructions" => ""
));
if (!$pickup->valid())
$this->updateProjectCrmByShipmentAndPickup($project, $params, $api, $fromAddress, $toAddress, $shipment);
return self::jsonError('There was a problem creating a valid pickup. Please try again.');
catch (\Exception $e)
$this->updateProjectCrmByShipmentAndPickup($project, $params, $api, $fromAddress, $toAddress, $shipment);
return self::jsonError(
'There was a problem of the Pickup creation. Please contact your customer representative.',
['easy-post' => $e->getMessage()]
);
【问题讨论】:
【参考方案1】:您经常看到的错误意味着货件尚未购买,或者取件和货件标签与不同的承运人相关联(例如:标签用于 UPS,但您正在尝试安排 FedEx 取件。)
如果您继续看到此错误,您可以在此处参考 API 文档:https://www.easypost.com/docs/api#pickups 或发送电子邮件至 support@easypost.com - 支持团队非常擅长找出导致此类错误的原因。
【讨论】:
以上是关于如何将已创建的标签添加到联邦快递取件的主要内容,如果未能解决你的问题,请参考以下文章
快递驿站取件管理系统|基于SpringBoot的快递栈系统设计与实现