使用 Amazon MWS Merchant Fulfillment API PHP SDK 购买运费
Using Amazon MWS Merchant Fulfilment API PHP SDK to buy shipping
我正在尝试使用 Amazon 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 商家履行的镜像 API PHP SDK
https://github.com/AustinMaddox/mws-merchant-fulfillment-php-client-library
多年来,我已经以多种方式使用订单、Feed 和报告 API,但在 Merchant API 上,我感到很困惑,我需要一些帮助。
我如何使用 Amazon MWS Merchant Fulfillment API PHP SDK 购买运费?
感谢 Amazon forums 上的 Bullcom,我弄明白了。
我需要创建对象并使用 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 的示例文件夹中,而不是含糊其词,他们目前有“//对象或参数数组”
我正在尝试使用 Amazon 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 商家履行的镜像 API PHP SDK
https://github.com/AustinMaddox/mws-merchant-fulfillment-php-client-library
多年来,我已经以多种方式使用订单、Feed 和报告 API,但在 Merchant API 上,我感到很困惑,我需要一些帮助。
我如何使用 Amazon MWS Merchant Fulfillment API PHP SDK 购买运费?
感谢 Amazon forums 上的 Bullcom,我弄明白了。
我需要创建对象并使用 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 的示例文件夹中,而不是含糊其词,他们目前有“//对象或参数数组”