php-在EasyPost中定义送货方式或费率

好的,所以我在一个文件中包含以下代码.这只是EasyPost易运输api的部分代码

$created_rates = \EasyPost\Rate::create($shipment);

$availableRates = array();

foreach($created_rates as $rate){

    $fedexR = str_replace("FEDEX_", " ", $rate->service);

    $displayS = str_replace("_", " ", $fedexR);

    $displayP = $rate->rate;

    $availableRates[] = $displayS;

}

$_SESSION['displayRates'] = $availableRates;

然后,这会将用户带到选择运输方式的下一步,如下所示:

<?php foreach($_SESSION['displayRates'] as $rate): ?>
     <option value="<?php echo $rate; ?>"><?php echo $rate; ?></option>
<?php endforeach; ?>

这将提交到以下页面:

$_SESSION['shipping_method'] = $_POST['shippingRate'];

$shipment = \EasyPost\Shipment::retrieve(array('id' => $_SESSION['shipment_id']));

$shipment->buy($shipment->rates[1]);

$_SESSION['shipment_label_url'] = $shipment->postage_label->label_url;

echo $_SESSION['shipment_label_url'];

如何使用EasyPost API发送选定的运费,以告知其购买该运费方法的邮费?我懂了

$shipment-> buy($shipment-> rates [1]);

我尝试这样做:

$shipment-> buy($shipment-> rates [$_ SESSION [‘shipping_method’]]);;但是结果是速率根本没有发送.

顺便说一句,会话是实际的单词,例如“ GROUND”,而不是数字.不知道如何实现此目标,但是如果我想使其完全正常运行,则必须这样做!

解决方法:

货件上有一个名为lowest_rate的费率过滤器.您可以将args传递给它,例如操作符名称和服务名称.就像是:

$shipment->buy($shipment->lowest_rate(array('Fedex'), array($_SESSION['shipping_method'])));
上一篇:PHP:在取消存档期间应用Chmod


下一篇:linux-如何仅将路径中的最后一个目录打包到tar文件中?