我正在使用 EasyPost API,但一路上遇到了一些阻碍。我想创建一个货件并同时购买保险,但 API 似乎希望您首先购买货件(邮资),然后购买保险,按照此文档:https://www. easypost.com/docs/api/java#shipping-insurance
但是 Create Shipment 的文档说的不同,它需要
insurance
金额:https://www.easypost.com/docs/api/java#shipment-object
我得出的结论是API不能一起处理它们,尽管Create Shipment说的不同,你必须先购买标签,然后再购买保险。但这对于我的工作流程来说是违反直觉的,我想使用一种表单来允许用户设置地址、包裹,选择货物是否投保,并在一笔交易中购买标签+保险,而不是做两笔交易交易(邮费和保险)。
<?php
$client = new \EasyPost\EasyPostClient('EASYPOST_API_KEY');
$shipment = $client->shipment->retrieve('shp_...');
$boughtShipment = $client->shipment->buy(
$shipmentId,
[
'rate' => array('id' => $rateId),
'insurance' => $insuranceAmount
]
);
echo $boughtShipment;