好吧,讓我在一個文件中有以下代碼。這是從EasyPost僅部分碼的簡單的運輸API在EasyPost中定義運送方式或費率
$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']]);
但導致根本沒有被髮送的速率。
順便說一句,會話是像「地面」而不是一個數字的實際詞。不知道我怎麼能做到這一點,但我必須,如果我希望它能夠工作!