Documentation

AmazonFinancialEventList extends AmazonFinanceCore
in package

Pulls a list of financial events from Amazon.

This Amazon Finance Core object retrieves a list of financial events from Amazon. Because the object has separate lists for each event type, the object cannot be iterated over.

Table of Contents

$config  : mixed
$env  : mixed
$list  : 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
$tokenFlag  : mixed
$tokenUseFlag  : mixed
$urlbase  : mixed
$urlbranch  : mixed
fetchEventList()  : bool
Fetches the inventory supply list from Amazon.
fetchURL()  : array<string|int, mixed>
Get url or send POST data
getAdjustmentEvents()  : array<string|int, mixed>|bool
Returns all adjustment events.
getChargebackEvents()  : array<string|int, mixed>|bool
Returns all chargeback events.
getDebtRecoveryEvents()  : array<string|int, mixed>|bool
Returns all debt recovery events.
getEvents()  : array<string|int, mixed>|bool
Returns all financial events.
getGuaranteeClaimEvents()  : array<string|int, mixed>|bool
Returns all guarantee claim events.
getLastResponse()  : array<string|int, mixed>|bool
Gives the latest response data received from Amazon.
getLoanServicingEvents()  : array<string|int, mixed>|bool
Returns all loan servicing events.
getOptions()  : array<string|int, mixed>
Returns options array.
getPayWithAmazonEvents()  : array<string|int, mixed>|bool
Returns all pay with Amazon events.
getPerformanceBondRefundEvents()  : array<string|int, mixed>|bool
Returns all performance bond refund events.
getRawResponses()  : array<string|int, mixed>|bool
Gives all response code received from Amazon.
getRefundEvents()  : array<string|int, mixed>|bool
Returns all refund events.
getRentalTransactionEvents()  : array<string|int, mixed>|bool
Returns all rental transaction events.
getRetrochargeEvents()  : array<string|int, mixed>|bool
Returns all retrocharge events.
getServiceFeeEvents()  : array<string|int, mixed>|bool
Returns all service fee events.
getServiceProviderCreditEvents()  : array<string|int, mixed>|bool
Returns all service provider credit events.
getShipmentEvents()  : array<string|int, mixed>|bool
Returns all shipment events.
getThrottleCountForLastRequest()  : int
Gives the number of times the last call to sendRequest was throttled
hasToken()  : bool
Returns whether or not a token is available.
resetFilters()  : mixed
Removes all filter options.
resetTimeLimits()  : mixed
Removes time limit options.
setConfig()  : mixed
setGroupFilter()  : bool
Sets the financial event group ID filter. (Required*)
setMaxResultsPerPage()  : bool
Sets the maximum number of responses per page. (Optional)
setMock()  : mixed
Enables or disables Mock Mode for the object.
setOrderFilter()  : bool
Sets the order ID filter. (Required*)
setStore()  : mixed
Sets the store values.
setThrottleStop()  : mixed
Enables or disables the throttle stop.
setTimeLimits()  : bool
Sets the time frame options. (Required*)
setUseToken()  : bool
Sets whether or not the object should automatically use tokens if it receives one.
__construct()  : mixed
AmazonCore constructor sets up key information used in all Amazon requests.
_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.
parseCharge()  : array<string|int, mixed>
Parses XML for a single charge into an array.
parseFee()  : array<string|int, mixed>
Parses XML for a single charge into an array.
parseShipmentEvent()  : array<string|int, mixed>
Parses XML for a single shipment event into an array.
parseXml()  : bool
Parses XML response into array.
prepareToken()  : mixed
Sets up options for using tokens.
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

fetchEventList()

Fetches the inventory supply list from Amazon.

public fetchEventList([bool $r = true ]) : bool

Submits a ListFinancialEvents request to Amazon. Amazon will send the list back as a response, which can be retrieved using getEvents. Other methods are available for fetching specific values from the list. This operation can potentially involve tokens.

Parameters
$r : bool = true

[optional]

When set to FALSE, the function will not recurse, defaults to TRUE

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

getAdjustmentEvents()

Returns all adjustment events.

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

Each event array will have the following keys:

  • AdjustmentType "FBAInventoryReimbursement", "ReserveEvent", "PostageBilling", or "PostageRefund"
  • Amount - number
  • CurrencyCode - ISO 4217 currency code
  • AdjustmentItemList - multi-dimensional array, each array has the following keys:
    • Quantity
    • PerUnitAmount - array with Amount and CurrencyCode
    • TotalAmount - array with Amount and CurrencyCode
    • SellerSKU
    • FnSKU
    • ProductDescription
    • ASIN
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled yet

getChargebackEvents()

Returns all chargeback events.

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

The structure for each event array is the same as in getRefundEvents.

Tags
see
getRefundEvents
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled yet

getDebtRecoveryEvents()

Returns all debt recovery events.

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

Each event array will have the following keys:

  • DebtRecoveryType - "DebtPayment", "DebtPaymentFailure", or "DebtAdjustment"
  • RecoveryAmount - array
    • Amount - number
    • CurrencyCode - ISO 4217 currency code
  • OverPaymentCredit (optional) - array with Amount and CurrencyCode
  • DebtRecoveryItemList - multi-dimensional array, each array has the following keys:
    • RecoveryAmount - array with Amount and CurrencyCode
    • OriginalAmount - array with Amount and CurrencyCode
    • GroupBeginDate - ISO 8601 date format
    • GroupEndDate - ISO 8601 date format
  • ChargeInstrumentList - multi-dimensional array, each array has the following keys:
    • Description
    • Tail
    • Amount - number
    • CurrencyCode - ISO 4217 currency code
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled yet

getEvents()

Returns all financial events.

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

The array will have the following keys:

  • Shipment - see getShipmentEvents
  • Refund - see getRefundEvents
  • GuaranteeClaim - see getGuaranteeClaimEvents
  • Chargeback - see getChargebackEvents
  • PayWithAmazon - see getPayWithAmazonEvents
  • ServiceProviderCredit - see getServiceProviderCreditEvents
  • Retrocharge - see getRetrochargeEvents
  • RentalTransaction - see getRentalTransactionEvents
  • PerformanceBondRefund - see getPerformanceBondRefundEvents
  • ServiceFee - see getServiceFeeEvents
  • DebtRecovery - see getDebtRecoveryEvents
  • LoanServicing - see getLoanServicingEvents
  • Adjustment - see getAdjustmentEvents
Tags
see
getShipmentEvents
see
getRefundEvents
see
getGuaranteeClaimEvents
see
getChargebackEvents
see
getPayWithAmazonEvents
see
getServiceProviderCreditEvents
see
getRetrochargeEvents
see
getRentalTransactionEvents
see
getPerformanceBondRefundEvents
see
getServiceFeeEvents
see
getDebtRecoveryEvents
see
getLoanServicingEvents
see
getAdjustmentEvents
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled yet

getGuaranteeClaimEvents()

Returns all guarantee claim events.

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

The structure for each event array is the same as in getRefundEvents.

Tags
see
getRefundEvents
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled 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

getLoanServicingEvents()

Returns all loan servicing events.

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

Each event array will have the following keys:

  • Amount - number
  • CurrencyCode - ISO 4217 currency code
  • SourceBusinessEventType - "LoanAdvance", "LoanPayment", or "LoanRefund"
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled 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.

getPayWithAmazonEvents()

Returns all pay with Amazon events.

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

Each event array will have the following keys:

  • SellerOrderId
  • TransactionPostedDate - ISO 8601 date format
  • BusinessObjectType - "PaymentContract"
  • SalesChannel
  • Charge - array
    • ChargeType
    • Amount - number
    • CurrencyCode - ISO 4217 currency code
  • FeeList - multi-dimensional array, each array has the following keys:
    • FeeType
    • Amount - number
    • CurrencyCode - ISO 4217 currency code
  • PaymentAmountType - "Sales"
  • AmountDescription
  • FulfillmentChannel - "MFN" or "AFN"
  • StoreName
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled yet

getPerformanceBondRefundEvents()

Returns all performance bond refund events.

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

Each event array will have the following keys:

  • MarketplaceCountryCode - two-letter country code in ISO 3166-1 alpha-2 format
  • Amount - number
  • CurrencyCode - ISO 4217 currency code
  • ProductGroupList - simple array of category names
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled 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

getRefundEvents()

Returns all refund events.

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

The structure for each event array is the same as in getShipmentEvents, but with the following additional keys in each "item" array:

  • OrderChargeAdjustmentList (optional) - list of charges, only for MCF COD orders
  • ShipmentFeeAdjustmentList - list of fees
  • OrderFeeAdjustmentList (optional) - list of fees, only for MCF orders
Each "item" array will have the following additional keys:
  • OrderAdjustmentItemId
  • ItemChargeAdjustmentList - list of charges
  • ItemFeeAdjustmentList - list of fees
  • PromotionAdjustmentList - list of promotions
  • CostOfPointsReturned (optional) - array
    • Amount - number
    • CurrencyCode - ISO 4217 currency code
Tags
see
getShipmentEvents
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled yet

getRentalTransactionEvents()

Returns all rental transaction events.

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

Each event array will have the following keys:

  • AmazonOrderId
  • RentalEventType
  • ExtensionLength (optional)
  • PostedDate - ISO 8601 date format
  • RentalChargeList - multi-dimensional array, each with the following keys:
    • ChargeType
    • Amount - number
    • CurrencyCode - ISO 4217 currency code
  • RentalFeeList - multi-dimensional array, each array has the following keys:
    • FeeType
    • Amount - number
    • CurrencyCode - ISO 4217 currency code
  • MarketplaceName
  • RentalInitialValue (optional) - array with Amount and CurrencyCode
  • RentalReimbursement (optional) - array with Amount and CurrencyCode
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled yet

getRetrochargeEvents()

Returns all retrocharge events.

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

Each event array will have the following keys:

  • RetrochargeEventType -"Retrocharge" or "RetrochargeReversal"
  • AmazonOrderId
  • PostedDate - ISO 8601 date format
  • BaseTax - array
    • Amount - number
    • CurrencyCode - ISO 4217 currency code
  • ShippingTax - array with Amount and CurrencyCode
  • MarketplaceName
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled yet

getServiceFeeEvents()

Returns all service fee events.

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

Each event array will have the following keys:

  • AmazonOrderId
  • FeeReason
  • FeeList - multi-dimensional array, each array has the following keys:
    • FeeType
    • Amount - number
    • CurrencyCode - ISO 4217 currency code
  • SellerSKU
  • FnSKU
  • FeeDescription
  • ASIN
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled yet

getServiceProviderCreditEvents()

Returns all service provider credit events.

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

Each event array will have the following keys:

  • ProviderTransactionType - "ProviderCredit" or "ProviderCreditReversal"
  • SellerOrderId
  • MarketplaceId
  • MarketplaceCountryCode - two-letter country code in ISO 3166-1 alpha-2 format
  • SellerId
  • SellerStoreName
  • ProviderId
  • ProviderStoreName
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled yet

getShipmentEvents()

Returns all shipment events.

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

Each event array will have the following keys:

  • AmazonOrderId
  • SellerOrderId
  • MarketplaceName
  • OrderChargeList (optional) - list of charges, only for MCF COD orders
  • ShipmentFeeList - list of fees
  • OrderFeeList (optional) - list of fees, only for MCF orders
  • DirectPaymentList (optional) - multi-dimensional array, only for COD orders. Each array in the list has the following keys:
    • DirectPaymentType
    • Amount - number
    • CurrencyCode - ISO 4217 currency code
  • PostedDate - ISO 8601 date format

Each "charge" array has the following keys:

  • ChargeType
  • Amount - number
  • CurrencyCode - ISO 4217 currency code
Each "fee" array has the following keys:
  • FeeType
  • Amount - number
  • CurrencyCode - ISO 4217 currency code
Each "item" array has the following keys:
  • SellerSKU
  • OrderItemId
  • QuantityShipped
  • ItemChargeList - list of charges
  • ItemFeeList - list of fees
  • CurrencyCode - ISO 4217 currency code
  • PromotionList - list of promotions
  • CostOfPointsGranted (optional) - array
    • Amount - number
    • CurrencyCode - ISO 4217 currency code
Each "promotion" array has the following keys:
  • PromotionType
  • PromotionId
  • Amount - number
  • CurrencyCode - ISO 4217 currency code
Return values
array<string|int, mixed>|bool

multi-dimensional array, or FALSE if list not filled yet

getThrottleCountForLastRequest()

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

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

resetFilters()

Removes all filter options.

public resetFilters() : mixed

Use this in case you change your mind and want to remove all filter parameters you previously set.

Return values
mixed

resetTimeLimits()

Removes time limit options.

public resetTimeLimits() : mixed

Use this in case you change your mind and want to remove the time limit parameters you previously set.

Return values
mixed

setConfig()

public setConfig() : mixed
Return values
mixed

setGroupFilter()

Sets the financial event group ID filter. (Required*)

public setGroupFilter(string $s) : bool

If this parameter is set, Amazon will only return Financial Events that belong to the given financial event group. This parameter is required if none of the other filter options are set. If this parameter is set, the order ID and time range options will be removed.

Parameters
$s : string

Financial Event Group ID

Return values
bool

FALSE if improper input

setMaxResultsPerPage()

Sets the maximum number of responses per page. (Optional)

public setMaxResultsPerPage(int $num) : bool

This method sets the maximum number of Financial Events for Amazon to return per page. If this parameter is not set, Amazon will send 100 at a time.

Parameters
$num : int

Positive integer from 1 to 100.

Return values
bool

FALSE if improper input

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

setOrderFilter()

Sets the order ID filter. (Required*)

public setOrderFilter(string $s) : bool

If this parameter is set, Amazon will only return Financial Events that relate to the given order. This parameter is required if none of the other filter options are set. If this parameter is set, the group ID and time range options will be removed.

Parameters
$s : string

Amazon Order ID in 3-7-7 format

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

setTimeLimits()

Sets the time frame options. (Required*)

public setTimeLimits(string $s[, string $e = null ]) : bool

This method sets the start and end times for the next request. If this parameter is set, Amazon will only return Financial Events posted between the two times given. This parameter is required if none of the other filter options are set. The parameters are passed through strtotime, so values such as "-1 hour" are fine. If this parameter is set, the order ID and group ID options will be removed.

Parameters
$s : string

A time string for the earliest time.

$e : string = null

[optional]

A time string for the latest time.

Return values
bool

FALSE if improper input

setUseToken()

Sets whether or not the object should automatically use tokens if it receives one.

public setUseToken([bool $b = true ]) : bool

If this option is set to TRUE, the object will automatically perform the necessary operations to retrieve the rest of the list using tokens. If this option is off, the object will only ever retrieve the first section of the list.

Parameters
$b : bool = true

[optional]

Defaults to TRUE

Return values
bool

FALSE if improper input

__construct()

AmazonCore constructor sets up key information used in all Amazon requests.

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

This constructor is called when initializing all objects in this library. The parameters are passed by the child objects' constructors.

Parameters
$s : string

Name for the store you want to use as seen in the config file. If this is not set to a valid name, none of these objects will work.

$mock : bool = false

[optional]

This is a flag for enabling Mock Mode. When this is set to TRUE, the object will fetch responses from files you specify instead of sending the requests to Amazon. The log will indicate whether mock mode is on or off each time an object is initialized. This defaults to FALSE.

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

[optional]

The files (or file) to use in Mock Mode. When Mock Mode is enabled, the object will retrieve one of these files from the list to use as a response. See setMock for more information.

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

parseCharge()

Parses XML for a single charge into an array.

protected parseCharge(SimpleXMLElement $xml) : array<string|int, mixed>

This structure is used many times throughout shipment events.

Parameters
$xml : SimpleXMLElement

The XML response from Amazon.

Return values
array<string|int, mixed>

parsed structure from XML

parseFee()

Parses XML for a single charge into an array.

protected parseFee(SimpleXMLElement $xml) : array<string|int, mixed>

This structure is used many times throughout shipment events.

Parameters
$xml : SimpleXMLElement

The XML response from Amazon.

Return values
array<string|int, mixed>

parsed structure from XML

parseShipmentEvent()

Parses XML for a single shipment event into an array.

protected parseShipmentEvent(SimpleXMLElement $xml) : array<string|int, mixed>
Parameters
$xml : SimpleXMLElement

The XML response from Amazon.

Return values
array<string|int, mixed>

parsed structure from XML

parseXml()

Parses XML response into array.

protected parseXml(SimpleXMLElement $xml) : bool

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

Parameters
$xml : SimpleXMLElement

The XML response from Amazon.

Return values
bool

FALSE if no XML data is found

prepareToken()

Sets up options for using tokens.

protected prepareToken() : mixed

This changes key options for switching between simply fetching a list and fetching the rest of a list using a token. Please note: because the operation for using tokens does not use any other parameters, all other parameters will be removed.

Return values
mixed

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