Documentation

AmazonOrder extends AmazonOrderCore
in package

Gets the details for a single order from Amazon.

This Amazon Order Core object retrieves (or simply contains) the data for a single order on Amazon. In order to fetch this data, an Amazon Order ID is required.

Table of Contents

$config  : mixed
$env  : mixed
$marketplaceId  : mixed
$mockFiles  : mixed
$mockIndex  : mixed
$mockMode  : mixed
$options  : mixed
$proxyInfo  : mixed
$rawResponses  : mixed
$storeName  : mixed
$throttleCount  : mixed
$throttleGroup  : mixed
$throttleLimit  : mixed
$throttleSafe  : mixed
$throttleStop  : mixed
$throttleTime  : mixed
$urlbase  : mixed
$urlbranch  : mixed
$data  : mixed
__construct()  : mixed
AmazonOrder object gets the details for a single object from Amazon.
fetchItems()  : AmazonOrderItemList
Fetches items for the order from Amazon.
fetchOrder()  : bool
Fetches the specified order from Amazon.
fetchURL()  : array<string|int, mixed>
Get url or send POST data
getAmazonOrderId()  : string|bool
Returns the Amazon Order ID for the Order.
getBuyerEmail()  : string|bool
Returns the Amazon-generated email address of the buyer.
getBuyerName()  : string|bool
Returns the name of the buyer.
getCbaDisplayableShippingLabel()  : string|bool
Returns the customized Checkout by Amazon (CBA) label of the Order.
getData()  : array<string|int, mixed>|bool
Returns the full set of data for the order.
getEarliestDeliveryDate()  : string|bool
Returns the timestamp of the estimated earliest delivery date.
getEarliestShipDate()  : string|bool
Returns the timestamp of the earliest shipping date.
getFulfillmentChannel()  : string|bool
Returns the Fulfillment Channel.
getIsBusinessOrder()  : string|bool
Returns an indication of whether or not the Order is a business number.
getIsPremiumOrder()  : string|bool
Returns an indication of whether or not the Order is a premium order.
getIsPrime()  : string|bool
Returns an indication of whether or not the Order uses the Amazon Prime service.
getLastResponse()  : array<string|int, mixed>|bool
Gives the latest response data received from Amazon.
getLastUpdateDate()  : string|bool
Returns the timestamp of the last modification date.
getLatestDeliveryDate()  : string|bool
Returns the timestamp of the estimated latest delivery date.
getLatestShipDate()  : string|bool
Returns the timestamp of the latest shipping date.
getMarketplaceId()  : string|bool
Returns the ID of the Marketplace in which the Order was placed.
getNumberofItemsShipped()  : int|bool
Returns the number of items in the Order that have been shipped.
getNumberOfItemsUnshipped()  : int|bool
Returns the number of items in the Order that have yet to be shipped.
getOptions()  : array<string|int, mixed>
Returns options array.
getOrderChannel()  : string|bool
Returns the Order Channel of the first item in the Order.
getOrderStatus()  : string|bool
Returns the status of the Order.
getOrderTotal()  : array<string|int, mixed>|bool
Returns an array containing the total cost of the Order along with the currency used.
getOrderTotalAmount()  : string|bool
Returns just the total cost of the Order.
getOrderType()  : string|bool
Returns the type of the order.
getPaymentExecutionDetail()  : array<string|int, mixed>|bool
Returns an array of the complete payment details.
getPaymentMethod()  : string|bool
Returns the payment method of the Order.
getPaymentMethodDetails()  : mixed
getPercentShipped()  : float|bool
Returns the ratio of shipped items to unshipped items.
getPurchaseDate()  : string|bool
Returns the purchase date of the Order.
getPurchaseOrderNumber()  : string|bool
Returns the purchase order number associated with the order.
getRawResponses()  : array<string|int, mixed>|bool
Gives all response code received from Amazon.
getSalesChannel()  : string|bool
Returns the Sales Channel of the Order.
getSellerOrderId()  : string|bool
Returns the seller-defined ID for the Order.
getShipmentServiceLevelCategory()  : string|bool
Returns the shipment service level category of the Order.
getShippedByAmazonTfm()  : string|bool
Returns an indication of whether or not the Order was shipped with the Amazon TFM service.
getShippingAddress()  : array<string|int, mixed>|bool
Returns an array containing all of the address information.
getShipServiceLevel()  : string|bool
Returns the shipment service level of the Order.
getShipServiceLevelCategory()  : string|bool
Use getShipmentServiceLevelCategory instead.
getTaxRegistrationDetails()  : mixed
getTaxRegistrationId()  : false|mixed
This method returns tax registration id (which is usually VAT ID for Europe)
getTfmShipmentStatus()  : string|bool
Returns the status of an Order shipped using Amazon TFM.
getThrottleCountForLastRequest()  : int
Gives the number of times the last call to sendRequest was throttled
isVatRegistered()  : mixed
setConfig()  : mixed
setMock()  : mixed
Enables or disables Mock Mode for the object.
setOrderId()  : bool
Sets the Amazon Order ID. (Required)
setStore()  : mixed
Sets the store values.
setThrottleStop()  : mixed
Enables or disables the throttle stop.
_calculateStringToSignV2()  : string
generates the string to sign, copied from Amazon
_getParametersAsString()  : string
Fuses all of the parameters together into a string, copied from Amazon
_sign()  : string
Runs the hash, copied from Amazon
_signParameters()  : string
validates signature and sets up signing of them, copied from Amazon
_urlencode()  : string
Reformats the provided string using rawurlencode while also replacing ~, copied from Amazon
checkResponse()  : bool
Checks whether or not the response is OK.
checkToken()  : bool
Checks for a token and changes the proper options
fetchMockFile()  : SimpleXMLObject|string|bool
Fetches the given mock file, or attempts to.
fetchMockResponse()  : bool|array<string|int, mixed>
Generates a fake HTTP response using the mock file list.
genQuery()  : string
Handles generation of the signed query string.
genTime()  : string
Generates timestamp in ISO8601 format.
log()  : bool
Writes a message to the log.
parseXML()  : bool
Parses XML response into array.
resetMock()  : mixed
Sets mock index back to 0.
sendRequest()  : array<string|int, mixed>
Sends a request to Amazon via cURL
sleep()  : mixed
Sleeps for the throttle time and records to the log.

Properties

$rawResponses

protected mixed $rawResponses = []

$throttleCount

protected mixed $throttleCount = 0

$throttleStop

protected mixed $throttleStop = false

Methods

__construct()

AmazonOrder object gets the details for a single object from Amazon.

public __construct(string $s[, string $id = null ][, SimpleXMLElement $data = null ][, bool $mock = false ][, array<string|int, mixed>|string $m = null ]) : mixed

The parameters are passed to the parent constructor, which are in turn passed to the AmazonCore constructor. See it for more information on these parameters and common methods. Please note that two extra parameters come before the usual Mock Mode parameters, so be careful when setting up the object.

Parameters
$s : string

Name for the store you want to use.

$id : string = null

[optional]

The Order ID to set for the object.

$data : SimpleXMLElement = null

[optional]

XML data from Amazon to be parsed.

$mock : bool = false

[optional]

This is a flag for enabling Mock Mode. This defaults to FALSE.

$m : array<string|int, mixed>|string = null

[optional]

The files (or file) to use in Mock Mode.

Return values
mixed

fetchItems()

Fetches items for the order from Amazon.

public fetchItems([bool $token = false ]) : AmazonOrderItemList

See the AmazonOrderItemList class for more information on the returned object.

Parameters
$token : bool = false

[optional]

whether or not to automatically use item tokens in the request

Return values
AmazonOrderItemList

container for order's items

fetchOrder()

Fetches the specified order from Amazon.

public fetchOrder() : bool

Submits a GetOrder request to Amazon. In order to do this, an Amazon order ID is required. Amazon will send the data back as a response, which can be retrieved using getData. Other methods are available for fetching specific values from the order.

Return values
bool

FALSE if something goes wrong

fetchURL()

Get url or send POST data

public fetchURL(string $url, array<string|int, mixed> $param) : array<string|int, mixed>
Parameters
$url : string
$param : array<string|int, mixed>

['Header'] $param['Post']

Return values
array<string|int, mixed>

$return['ok'] 1 - success, (0,-1) - fail $return['body'] - response $return['error'] - error, if "ok" is not 1 $return['head'] - http header

getAmazonOrderId()

Returns the Amazon Order ID for the Order.

public getAmazonOrderId() : string|bool

This method will return FALSE if the order ID has not been set yet.

Return values
string|bool

single value, or FALSE if order ID not set yet

getBuyerEmail()

Returns the Amazon-generated email address of the buyer.

public getBuyerEmail() : string|bool

This method will return FALSE if the buyer email has not been set yet.

Return values
string|bool

single value, or FALSE if email not set yet

getBuyerName()

Returns the name of the buyer.

public getBuyerName() : string|bool

This method will return FALSE if the buyer name has not been set yet.

Return values
string|bool

single value, or FALSE if name not set yet

getCbaDisplayableShippingLabel()

Returns the customized Checkout by Amazon (CBA) label of the Order.

public getCbaDisplayableShippingLabel() : string|bool

This method will return FALSE if the CBA label category has not been set yet.

Return values
string|bool

single value, or FALSE if label not set yet

getData()

Returns the full set of data for the order.

public getData() : array<string|int, mixed>|bool

This method will return FALSE if the order data has not yet been filled. The array returned will have the following fields:

  • AmazonOrderId - unique ID for the order, which you sent in the first place
  • SellerOrderId (optional) - your unique ID for the order
  • PurchaseDate - time in ISO8601 date format
  • LastUpdateDate - time in ISO8601 date format
  • OrderStatus - the current status of the order, see getOrderStatus for more details
  • MarketplaceId - the marketplace in which the order was placed
  • FulfillmentChannel (optional) - "AFN" or "MFN"
  • SalesChannel (optional) - sales channel for the first item in the order
  • OrderChannel (optional) - order channel for the first item in the order
  • ShipServiceLevel (optional) - shipment service level of the order
  • ShippingAddress (optional) - array, see getShippingAddress for more details
  • OrderTotal (optional) - array with the fields Amount and CurrencyCode
  • NumberOfItemsShipped (optional) - number of items shipped
  • NumberOfItemsUnshipped (optional) - number of items not shipped
  • PaymentExecutionDetail (optional) - multi-dimensional array, see getPaymentExecutionDetail for more details
  • PaymentMethod (optional) - "COD", "CVS", or "Other"
  • BuyerName (optional) - name of the buyer
  • BuyerEmail (optional) - Amazon-generated email for the buyer
  • ShipmentServiceLevelCategory (optional) - "Expedited", "FreeEconomy", "NextDay", "SameDay", "SecondDay", "Scheduled", or "Standard"
Return values
array<string|int, mixed>|bool

array of data, or FALSE if data not filled yet

getEarliestDeliveryDate()

Returns the timestamp of the estimated earliest delivery date.

public getEarliestDeliveryDate() : string|bool

This method will return FALSE if the timestamp has not been set yet.

Return values
string|bool

timestamp, or FALSE if timestamp not set yet

getEarliestShipDate()

Returns the timestamp of the earliest shipping date.

public getEarliestShipDate() : string|bool

This method will return FALSE if the timestamp has not been set yet.

Return values
string|bool

timestamp, or FALSE if timestamp not set yet

getFulfillmentChannel()

Returns the Fulfillment Channel.

public getFulfillmentChannel() : string|bool

This method will return FALSE if the fulfillment channel has not been set yet.

Return values
string|bool

"AFN" or "MFN", or FALSE if channel not set yet

getIsBusinessOrder()

Returns an indication of whether or not the Order is a business number.

public getIsBusinessOrder() : string|bool

This method will return FALSE if the business order flag has not been set yet.

Return values
string|bool

single value, or FALSE if value not set yet

getIsPremiumOrder()

Returns an indication of whether or not the Order is a premium order.

public getIsPremiumOrder() : string|bool

This method will return FALSE if the premium order flag has not been set yet.

Return values
string|bool

single value, or FALSE if value not set yet

getIsPrime()

Returns an indication of whether or not the Order uses the Amazon Prime service.

public getIsPrime() : string|bool

This method will return FALSE if the Prime flag has not been set yet.

Return values
string|bool

"true" or "false", or FALSE if value not set yet

getLastResponse()

Gives the latest response data received from Amazon.

public getLastResponse([int $i = null ]) : array<string|int, mixed>|bool

Response arrays contain the following keys:

  • head - The raw HTTP head, including the response code and content length
  • body - The raw HTTP body, which will almost always be in XML format
  • code - The HTTP response code extracted from the head for convenience
  • answer - The HTTP response message extracted from the head for convenience
  • ok - Contains a 1 if the response was normal, or 0 if there was a problem
  • headarray - An associative array of the head data, for convenience
Parameters
$i : int = null

[optional]

If set, retrieves the specific response instead of the last one. If the index for the response is not used, FALSE will be returned.

Return values
array<string|int, mixed>|bool

associative array of HTTP response or FALSE if not set yet

getLastUpdateDate()

Returns the timestamp of the last modification date.

public getLastUpdateDate() : string|bool

This method will return FALSE if the timestamp has not been set yet.

Return values
string|bool

timestamp, or FALSE if timestamp not set yet

getLatestDeliveryDate()

Returns the timestamp of the estimated latest delivery date.

public getLatestDeliveryDate() : string|bool

Note that this could be set to midnight of the day after the last date, so the timestamp "2013-09-025T00:00:00Z" indicates the last day is the 24th and not the 25th. This method will return FALSE if the timestamp has not been set yet.

Return values
string|bool

timestamp, or FALSE if timestamp not set yet

getLatestShipDate()

Returns the timestamp of the latest shipping date.

public getLatestShipDate() : string|bool

Note that this could be set to midnight of the day after the last date, so the timestamp "2013-09-025T00:00:00Z" indicates the last day is the 24th and not the 25th. This method will return FALSE if the timestamp has not been set yet.

Return values
string|bool

timestamp, or FALSE if timestamp not set yet

getMarketplaceId()

Returns the ID of the Marketplace in which the Order was placed.

public getMarketplaceId() : string|bool

This method will return FALSE if the marketplace ID has not been set yet.

Return values
string|bool

single value, or FALSE if ID not set yet

getNumberofItemsShipped()

Returns the number of items in the Order that have been shipped.

public getNumberofItemsShipped() : int|bool

This method will return FALSE if the number has not been set yet.

Return values
int|bool

non-negative number, or FALSE if number not set yet

getNumberOfItemsUnshipped()

Returns the number of items in the Order that have yet to be shipped.

public getNumberOfItemsUnshipped() : int|bool

This method will return FALSE if the number has not been set yet.

Return values
int|bool

non-negative number, or FALSE if number not set yet

getOptions()

Returns options array.

public getOptions() : array<string|int, mixed>

Gets the options for the object, for debugging or recording purposes. Note that this also includes key information such as your Amazon Access Key ID.

Return values
array<string|int, mixed>

All of the options for the object.

getOrderChannel()

Returns the Order Channel of the first item in the Order.

public getOrderChannel() : string|bool

This method will return FALSE if the order channel has not been set yet.

Return values
string|bool

single value, or FALSE if channel not set yet

getOrderStatus()

Returns the status of the Order.

public getOrderStatus() : string|bool

This method will return FALSE if the order status has not been set yet. Possible Order Statuses are:

  • Pending
  • Unshipped
  • Partially Shipped
  • Shipped
  • Cancelled
  • Unfulfillable
Return values
string|bool

single value, or FALSE if status not set yet

getOrderTotal()

Returns an array containing the total cost of the Order along with the currency used.

public getOrderTotal() : array<string|int, mixed>|bool

This method will return FALSE if the order total has not been set yet. The returned array has the following fields:

  • Amount
  • CurrencyCode
Return values
array<string|int, mixed>|bool

associative array, or FALSE if total not set yet

getOrderTotalAmount()

Returns just the total cost of the Order.

public getOrderTotalAmount() : string|bool

This method will return FALSE if the order total has not been set yet.

Return values
string|bool

number, or FALSE if total not set yet

getOrderType()

Returns the type of the order.

public getOrderType() : string|bool

This method will return FALSE if the type has not been set yet. Valid values for the type are...

  • StandardOrder
  • Preorder
Return values
string|bool

single value, or FALSE if order type not set yet

getPaymentExecutionDetail()

Returns an array of the complete payment details.

public getPaymentExecutionDetail() : array<string|int, mixed>|bool

This method will return FALSE if the payment details has not been set yet. The array returned contains one or more arrays with the following fields:

  • Amount
  • CurrencyCode
  • SubPaymentMethod
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if details not set yet

getPaymentMethod()

Returns the payment method of the Order.

public getPaymentMethod() : string|bool

This method will return FALSE if the payment method has not been set yet.

Return values
string|bool

"COD", "CVS", "Other", or FALSE if method not set yet

getPaymentMethodDetails()

public getPaymentMethodDetails() : mixed
Return values
mixed

getPercentShipped()

Returns the ratio of shipped items to unshipped items.

public getPercentShipped() : float|bool

This method will return FALSE if the shipment numbers have not been set yet.

Return values
float|bool

Decimal number from 0 to 1, or FALSE if numbers not set yet

getPurchaseDate()

Returns the purchase date of the Order.

public getPurchaseDate() : string|bool

This method will return FALSE if the timestamp has not been set yet.

Return values
string|bool

timestamp, or FALSE if timestamp not set yet

getPurchaseOrderNumber()

Returns the purchase order number associated with the order.

public getPurchaseOrderNumber() : string|bool

This method will return FALSE if the purchase order number has not been set yet.

Return values
string|bool

single value, or FALSE if value not set yet

getRawResponses()

Gives all response code received from Amazon.

public getRawResponses() : array<string|int, mixed>|bool
Tags
see
getLastResponse
Return values
array<string|int, mixed>|bool

list of associative arrays of HTTP response or FALSE if not set yet

getSalesChannel()

Returns the Sales Channel of the Order.

public getSalesChannel() : string|bool

This method will return FALSE if the sales channel has not been set yet.

Return values
string|bool

single value, or FALSE if channel not set yet

getSellerOrderId()

Returns the seller-defined ID for the Order.

public getSellerOrderId() : string|bool

This method will return FALSE if the order ID has not been set yet.

Return values
string|bool

single value, or FALSE if order ID not set yet

getShipmentServiceLevelCategory()

Returns the shipment service level category of the Order.

public getShipmentServiceLevelCategory() : string|bool

This method will return FALSE if the service level category has not been set yet. Valid values for the service level category are...

  • Expedited
  • FreeEconomy
  • NextDay
  • SameDay
  • SecondDay
  • Scheduled
  • Standard
Return values
string|bool

single value, or FALSE if category not set yet

getShippedByAmazonTfm()

Returns an indication of whether or not the Order was shipped with the Amazon TFM service.

public getShippedByAmazonTfm() : string|bool

This method will return FALSE if the Amazon TFM flag has not been set yet.

Return values
string|bool

single value, or FALSE if value not set yet

getShippingAddress()

Returns an array containing all of the address information.

public getShippingAddress() : array<string|int, mixed>|bool

This method will return FALSE if the address has not been set yet. The returned array will have the following fields:

  • Name
  • AddressLine1
  • AddressLine2
  • AddressLine3
  • City
  • County
  • District
  • StateOrRegion
  • PostalCode
  • CountryCode
  • Phone
Return values
array<string|int, mixed>|bool

associative array, or FALSE if address not set yet

getShipServiceLevel()

Returns the shipment service level of the Order.

public getShipServiceLevel() : string|bool

This method will return FALSE if the shipment service level has not been set yet.

Return values
string|bool

single value, or FALSE if level not set yet

getShipServiceLevelCategory()

Use getShipmentServiceLevelCategory instead.

public getShipServiceLevelCategory() : string|bool
Tags
deprecated

since version 1.3.0

Return values
string|bool

single value, or FALSE if category not set yet

getTaxRegistrationDetails()

public getTaxRegistrationDetails() : mixed
Return values
mixed

getTaxRegistrationId()

This method returns tax registration id (which is usually VAT ID for Europe)

public getTaxRegistrationId() : false|mixed
Return values
false|mixed

getTfmShipmentStatus()

Returns the status of an Order shipped using Amazon TFM.

public getTfmShipmentStatus() : string|bool

This method will return FALSE if the status has not been set yet. Valid values for the status are...

  • PendingPickUp
  • LabelCanceled
  • PickedUp
  • AtDestinationFC
  • Delivered
  • RejectedByBuyer
  • Undeliverable
  • ReturnedToSeller
Return values
string|bool

single value, or FALSE if status not set yet

getThrottleCountForLastRequest()

Gives the number of times the last call to sendRequest was throttled

public getThrottleCountForLastRequest() : int
Tags
see
sendRequest
Return values
int

isVatRegistered()

public isVatRegistered() : mixed
Return values
mixed

setConfig()

public setConfig() : mixed
Return values
mixed

setMock()

Enables or disables Mock Mode for the object.

public setMock([bool $b = true ][, array<string|int, mixed>|string|int $files = null ]) : mixed

Use this method when you want to test your object without sending actual requests to Amazon. When Mock Mode is enabled, responses are pulled from files you specify instead of sending the request. Be careful, as this means that the parameters you send will not necessarily match the response you get back. The files are pulled in order of the list, looping back to the first file after the last file is used. The log records every time a file is set or used, or if the file is missing. This method is also used to set response codes used by certain functions. Mock Mode is particularly useful when you need to test functions such as canceling orders or adding new products.

Parameters
$b : bool = true

[optional]

When set to TRUE, Mock Mode is enabled for the object. Defaults to TRUE.

$files : array<string|int, mixed>|string|int = null

[optional]

The list of files (or single file) to be used with Mock Mode. If a single string is given, this method will put it into an array. Integers can also be given, for use in fetchMockResponse. These numbers should only be response codes, such as 200 or 404.

Return values
mixed

setOrderId()

Sets the Amazon Order ID. (Required)

public setOrderId(mixed $id) : bool

This method sets the Amazon Order ID to be sent in the next request. This parameter is required for fetching the order from Amazon.

Parameters
$id : mixed
Return values
bool

FALSE if improper input

setStore()

Sets the store values.

public setStore(string $s) : mixed

This method sets a number of key values from the config file. These values include your Merchant ID, Access Key ID, and Secret Key, and are critical for making requests with Amazon. If the store cannot be found in the config file, or if any of the key values are missing, the incident will be logged.

Parameters
$s : string

The store name to look for.

Tags
throws
Exception

If the file can't be found.

Return values
mixed

setThrottleStop()

Enables or disables the throttle stop.

public setThrottleStop([bool $b = true ]) : mixed

When the throttle stop is enabled, throttled requests will not be repeated. This setting is off by default.

Parameters
$b : bool = true

Defaults to TRUE.

Return values
mixed

_calculateStringToSignV2()

generates the string to sign, copied from Amazon

protected _calculateStringToSignV2(array<string|int, mixed> $parameters) : string
Parameters
$parameters : array<string|int, mixed>
Return values
string

_getParametersAsString()

Fuses all of the parameters together into a string, copied from Amazon

protected _getParametersAsString(array<string|int, mixed> $parameters) : string
Parameters
$parameters : array<string|int, mixed>
Return values
string

_sign()

Runs the hash, copied from Amazon

protected _sign(string $data, string $key, string $algorithm) : string
Parameters
$data : string
$key : string
$algorithm : string

'HmacSHA1' or 'HmacSHA256'

Tags
throws
Exception
Return values
string

_signParameters()

validates signature and sets up signing of them, copied from Amazon

protected _signParameters(array<string|int, mixed> $parameters, string $key) : string
Parameters
$parameters : array<string|int, mixed>
$key : string
Tags
throws
Exception
Return values
string

signed string

_urlencode()

Reformats the provided string using rawurlencode while also replacing ~, copied from Amazon

protected _urlencode(string $value) : string

Almost the same as using rawurlencode

Parameters
$value : string
Return values
string

checkResponse()

Checks whether or not the response is OK.

protected checkResponse(array<string|int, mixed> $r) : bool

Verifies whether or not the HTTP response has the 200 OK code. If the code is not 200, the incident and error message returned are logged.

Parameters
$r : array<string|int, mixed>

The HTTP response array. Expects the array to have the fields code, body, and error.

Return values
bool

TRUE if the status is 200 OK, FALSE otherwise.

checkToken()

Checks for a token and changes the proper options

protected checkToken(SimpleXMLObject $xml) : bool
Parameters
$xml : SimpleXMLObject

response data

Return values
bool

FALSE if no XML data

fetchMockFile()

Fetches the given mock file, or attempts to.

protected fetchMockFile([bool $load = true ]) : SimpleXMLObject|string|bool

This method is only called when Mock Mode is enabled. This is where files from the mock file list are retrieved and passed back to the caller. The success or failure of the operation will be recorded in the log, including the name and path of the file involved. For retrieving response codes, see fetchMockResponse.

Parameters
$load : bool = true

[optional]

Set this to FALSE to prevent the method from loading the file's contents into a SimpleXMLObject. This is for when the contents of the file are not in XML format, or if you simply want to retrieve the raw string of the file.

Return values
SimpleXMLObject|string|bool

A SimpleXMLObject holding the contents of the file, or a string of said contents if $load is set to FALSE. The return will be FALSE if the file cannot be fetched for any reason.

fetchMockResponse()

Generates a fake HTTP response using the mock file list.

protected fetchMockResponse() : bool|array<string|int, mixed>

This method uses the response codes in the mock file list to generate an HTTP response. The success or failure of this operation will be recorded in the log, including the response code returned. This is only used by a few operations. The response array will contain the following fields:

  • head - ignored, but set for the sake of completion
  • body - empty XML, also ignored
  • code - the response code fetched from the list
  • answer - answer message
  • error - error message, same value as answer, not set if status is 200
  • ok - 1 or 0, depending on if the status is 200
Return values
bool|array<string|int, mixed>

An array containing the HTTP response, or simply the value FALSE if the response could not be found or does not match the list of valid responses.

genQuery()

Handles generation of the signed query string.

protected genQuery() : string

This method uses the secret key from the config file to generate the signed query string. It also handles the creation of the timestamp option prior.

Tags
throws
Exception

if config file or secret key is missing

Return values
string

query string to send to cURL

genTime()

Generates timestamp in ISO8601 format.

protected genTime([string $time = false ]) : string

This method creates a timestamp from the provided string in ISO8601 format. The string given is passed through strtotime before being used. The value returned is actually 30 seconds early, to prevent it from tripping up Amazon. If no time is given, the current time is used.

Parameters
$time : string = false

[optional]

The time to use. Since this value is passed through strtotime first, values such as "-1 hour" are fine. Defaults to the current time.

Return values
string

Unix timestamp of the time, minus 30 seconds.

log()

Writes a message to the log.

protected log(string $msg[, string $level = 'Info' ]) : bool

This method adds a message line to the log file defined by the config. This includes the priority level, user IP, and a backtrace of the call.

Parameters
$msg : string

The message to write to the log.

$level : string = 'Info'

[optional]

The priority level of the message. This is merely for the benefit of the user and does not affect how the code runs. The values used in this library are "Info", "Warning", "Urgent", and "Throttle".

Tags
throws
Exception

If the file can't be written to.

Return values
bool

FALSE if the message is empty, NULL if logging is muted

parseXML()

Parses XML response into array.

protected parseXML(SimpleXMLObject $xml) : bool

This is what reads the response XML and converts it into an array.

Parameters
$xml : SimpleXMLObject

The XML response from Amazon.

Return values
bool

FALSE if no XML data is found

resetMock()

Sets mock index back to 0.

protected resetMock([bool $mute = false ]) : mixed

This method is used for returning to the beginning of the mock file list.

Parameters
$mute : bool = false

[optional]

Set to TRUE to prevent logging.

Return values
mixed

sendRequest()

Sends a request to Amazon via cURL

protected sendRequest(string $url[, array<string|int, mixed> $param = [] ]) : array<string|int, mixed>

This method will keep trying if the request was throttled.

Parameters
$url : string

URL to feed to cURL

$param : array<string|int, mixed> = []

parameter array to feed to cURL

Return values
array<string|int, mixed>

cURL response array

sleep()

Sleeps for the throttle time and records to the log.

protected sleep() : mixed
Return values
mixed

Search results