我正在尝试使用亚马逊MWS Merchant Fulfillment API PHP SDK购买送货服务。
我的代码看起来像这样,为隐私更改了一些个人详细信息:
// Configure
require_once('sdks/Amazon/.config.inc.php');
$serviceUrl = "https://mws.amazonservices.com/MerchantFulfillment/2015-06-01";
$config = array(
'ServiceURL' => $serviceUrl,
'ProxyHost' => null,
'ProxyPort' => -1,
'ProxyUsername' => null,
'ProxyPassword' => null,
'MaxErrorRetry' => 3
);
// Create service
$merchant_service = new Amazon_Merchant_Client(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, APPLICATION_NAME, APPLICATION_VERSION, $config);
// Create request object
$request = new Amazon_Merchant_Model_CreateShipmentRequest();
// Set SellerId
$request->setSellerId(MERCHANT_ID);
// Define shipping info
$package_dimensions = array(
'Length' => 5,
'Width' => 5,
'Height' => 5,
'Unit' => 'inches',
);
$weight = array(
'Value' => 5,
'Unit' => 'ounces',
);
$ship_from_address = array(
'Name' => '904Custom',
'AddressLine1' => 'foobar',
'AddressLine2' => 'foobar',
'Email' => 'foobar@foobar.com',
'City' => 'foobar',
'StateOrProvinceCode' => 'FL',
'PostalCode' => '12345',
'CountryCode' => 'US',
'Phone' => '(888) 555-5555',
);
$shipping_service_options = array(
'DeliveryExperience' => 'DeliveryConfirmationWithoutSignature',
'CarrierWillPickUp' => true,
);
$shipping_details_array = array(
'AmazonOrderId' => '114-1234567-1234567',
'SellerOrderId' => '114-1234567-1234567',
'ShipFromAddress' => $ship_from_address,
'PackageDimensions' => $package_dimensions,
'Weight' => $weight,
'ShippingServiceOptions' => $shipping_service_options,
);
$request->setShipmentRequestDetails($shipping_details_array);
// Set shipping service id
$request->setShippingServiceId('1234');
// Invoke request
// invokeCreateShipment is a wrapper for $service->CreateShipment($request);
$result = $this->invokeCreatehipment($merchant_service, $request);
这给了我
致命错误:在第276行的/var/www/hydra/sdks/Amazon/Merchant/Model.php中的非对象上调用成员函数_toQueryParameterArray()
详细信息可能不正确,但是现在我只是尝试向API发送请求,SDK不允许我这样做,因为它遇到了致命的PHP错误。为了它的价值,我删除了$ request-> setShipmentRequestDetails()以查看我会得到什么结果。我确实从API获得了响应,但它是一个InternalFailure XML:
<ErrorResponse xmlns="https://mws.amazonservices.com/MerchantFulfillment/2015-06-01">
<Error>
<Type>Receiver</Type>
<Code>InternalFailure</Code>
</Error>
<RequestId>b1f5a04c-54ac-442c-ab88-f2f1c9374377</RequestId>
</ErrorResponse>
我已阅读以下所有文档
我查看了SDK中包含的示例文件,但它们不是完整的示例。
我已经完成了详尽的谷歌搜索,但无法在野外找到任何此SDK的使用。
http://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_Overview.html http://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_HowToUseForPrime.html http://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_CreateShipment.html http://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_Datatypes.html#ShipmentRequestDetails http://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_Datatypes.html#ShippingServiceOptions
我在源代码中尝试使用var_dump()来试图找出正在发生的事情,但它非常抽象且难以使用。例如,toQueryParameterArray()
调用_toQueryParameterArray()
,调用__toQueryParameterArray()
,同时调用_toQueryParameterArray()
和__toQueryParameterArray()
。代码很难理解,并且尝试编写变通方法的工作也没有结束。
供参考,以下是官方亚马逊MWS Merchant Fulfillment API PHP SDK的镜像
https://github.com/AustinMaddox/mws-merchant-fulfillment-php-client-library
我多年来一直使用Orders,Feed和Reports API,但是在Merchant API上,我很难过,我需要一些帮助。
如何使用亚马逊MWS Merchant Fulfillment API PHP SDK购买送货服务?
答案 0 :(得分:1)
感谢Bullcom对Amazon forums的反应,我明白了。
我需要创建对象并使用setter和getter,而不仅仅是传递数据数组
所以我的新代码看起来更像是
$shipping_details = new Amazon_Merchant_Model_ShipmentRequestDetails();
$weight = new Amazon_Merchant_Model_Weight();
$weight->setValue(5);
$weight->setUnit('ounces');
$shipping_details->setWeight($weight);
这绝对应该在SDK的示例文件夹中,而不是模糊它们当前具有“//对象或参数数组”的注释