duanguzhong5776 2017-04-03 17:04
浏览 16

获得特定服务的速率 - EasyPost

I currently have EasyPost creating a shipment. When I create the shipment it provides me with all the available services and rates.

I would like to dynamically select service and only return that rate.

I originally would read through the array using the index number (I guess that how to describe it).

The problem with this is every time I create a new shipment the order of the rates array changes so what would have been $shipment->rates[0]['rate'] would be express and then the next time first class.

I want to create a shipment with "Express" and only return that rate.

Any advice would be appreciated.

Here is my code:

$name = $this->thiscustomer->cust_first . ' ' . $this->thiscustomer->cust_first;
$street_1 = $this->thiscustomer->street_1;
$street_2 = $this->thiscustomer->street_2;
$city = $this->thiscustomer->city;
$state = $this->thiscustomer->state;
$zip = $this->thiscustomer->zip;


$weight = $this->weight;
    $packaging = $this->packaging;
    $service = $this->service;
    $caddress = $this->consultant->address;
    $cstreet_1 = $this->consultant->street_1;
    $cstreet_2 = $this->consultant->street_2;
    $ccity = $this->consultant->city;
    $cstate = $this->consultant->state;
    $czip = $this->consultant->zip;
    $cname = $this->consultant->first_name . ' ' . $this->consultant->last_name;
    $cuser_id = $this->consultant->user_id;




require_once(dirname(__FILE__) . '/lib/easypost.php');
\EasyPost\EasyPost::setApiKey('KUk4fZUI6YaYc1h0FiIXFw');


$shipment = \EasyPost\Shipment::create(array(
 'to_address' => array(
"name"    => $name,
"street1" => $street_1,
"street2" => $street_2,
"city"    => $city,
"state"   => $state,
"zip"     => $zip
 ),
 'from_address' => array(
"company" => $cname,
"street1" => $cstreet_1,
"street2" => $cstreet_2,
"city"    => $ccity,
"state"   => $cstate,
"zip"     => $czip
 ),
 'parcel' => array(
'weight' => $weight,
'predefined_package'=> $packaging
),
'rates' => array(
  'service' => $service
)

));

echo $shipment->rates[0]['rate']. '<br>';
  • 写回答

1条回答 默认 最新

  • douren6035 2017-04-03 19:49
    关注

    In EasyPost's Getting Started Guide there is an example of buying a specific carrier+rate:

    $shipment->buy($shipment->lowest_rate(array('USPS'), array('Express')));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数