Developer notes
Layout
Section titled “Layout”| Part | Role |
|---|---|
Client\BaseClient |
cURL with TLS verification and timeouts, JSON, error mapping, masked logging. The test hook is $config['kv_amazon_mcf_base_url'] in config.local.php (development only). |
Client\Api |
The only Amazon specific HTTP code: Login with Amazon, the Fulfillment Outbound API and the FBA Inventory API. |
Mapper |
Pure mapping between CS-Cart data and the API models (no database, no HTTP). Unit tested with the official model examples. |
Marketplaces |
Amazon stores, their region and the delivery-country routes. |
Fulfilment |
Life of an order: eligibility, send, poll, cancel, resend, lists. One queue job each, under a per-order lock. |
Shipments |
Packages, tracking, CS-Cart shipments. |
Skus, Stock |
SKU map, FBA stock copy. |
RateCalculator, Tygh\Shippings\Services\KvAmazonMcf |
Checkout rates from getFulfillmentPreview. |
Queue, Jobs, Log, Accounts, Secret, Idempotency |
Job queue with retries, log, encrypted accounts, per-order locks. |
Tygh\Api\Entities\KvAmazonMcfOrders |
REST API. |
License\Client, Upgrade\Synchronizer |
Licence check and self-healing in-place upgrades (generated by kv license-client, kv synchronizer). |
Amazon API reference (what is used)
Section titled “Amazon API reference (what is used)”Every call is authenticated with a Login with Amazon access token in x-amz-access-token (the add-on exchanges the merchant’s refresh token: POST https://api.amazon.com/auth/o2/token, grant_type=refresh_token). Requests are not AWS SigV4 signed. The required User-Agent is KavioAmazonMCF/<version> (Language=PHP/<version>; Platform=CS-Cart). Test mode uses sandbox.sellingpartnerapi-<region>.amazon.com, live mode sellingpartnerapi-<region>.amazon.com (na, eu, fe).
Sources: the Selling Partner API models published by Amazon (copies in tests/samples/) and the SP-API documentation pages fulfillment-outbound-api-v2020-07-01-reference and fba-inventory-api-v1-reference.
| Operation | Request | Fields the add-on uses | Default rate / burst |
|---|---|---|---|
| getFulfillmentPreview | POST /fba/outbound/2020-07-01/fulfillmentOrders/preview |
marketplaceId, address (name, addressLine1, city, stateOrRegion, postalCode, countryCode), items[] (sellerSku, quantity, sellerFulfillmentOrderItemId), shippingSpeedCategories[], includeCODFulfillmentPreview (false), includeDeliveryWindows (false), featureConstraints[]. Reads fulfillmentPreviews[]: shippingSpeedCategory, isFulfillable, estimatedFees[] (name, amount.currencyCode, amount.value), fulfillmentPreviewShipments[] (earliestArrivalDate, latestArrivalDate), orderUnfulfillableReasons[] |
2 / 30 |
| createFulfillmentOrder | POST /fba/outbound/2020-07-01/fulfillmentOrders |
marketplaceId, sellerFulfillmentOrderId (max 40), displayableOrderId (max 40), displayableOrderDate, displayableOrderComment (max 750), shippingSpeedCategory, destinationAddress, fulfillmentAction (Ship), fulfillmentPolicy, shipFromCountryCode, notificationEmails[] (max 64 each), featureConstraints[], items[] (sellerSku max 50, sellerFulfillmentOrderItemId max 50, quantity, perUnitDeclaredValue) |
2 / 30 |
| getFulfillmentOrder | GET /fba/outbound/2020-07-01/fulfillmentOrders/{sellerFulfillmentOrderId} |
fulfillmentOrder.fulfillmentOrderStatus, fulfillmentOrderItems[] (unfulfillableQuantity), fulfillmentShipments[] (amazonShipmentId, fulfillmentShipmentStatus, shippingDate, fulfillmentShipmentItem[], fulfillmentShipmentPackage[]: packageNumber, carrierCode, trackingNumber, amazonFulfillmentTrackingNumber, estimatedArrivalDate) |
2 / 30 |
| cancelFulfillmentOrder | PUT /fba/outbound/2020-07-01/fulfillmentOrders/{sellerFulfillmentOrderId}/cancel |
none | 2 / 30 |
| getPackageTrackingDetails | GET /fba/outbound/2020-07-01/tracking?packageNumber= |
trackingNumber, customerTrackingLink, carrierCode, currentStatus, currentStatusDescription |
2 / 30 |
| listAllFulfillmentOrders | GET /fba/outbound/2020-07-01/fulfillmentOrders?queryStartDate= |
fulfillmentOrders[], nextToken (client method Api::listOrders; not called by the add-on in 1.0.0) |
2 / 30 |
| getFeatures | GET /fba/outbound/2020-07-01/features?marketplaceId= |
features[] (featureName, featureDescription, sellerEligible); used by Test connection |
2 / 30 |
| getInventorySummaries | GET /fba/inventory/v1/summaries |
granularityType=Marketplace, granularityId, marketplaceIds, details=true, sellerSkus (up to 50); reads inventorySummaries[].sellerSku and inventoryDetails.fulfillableQuantity, pagination.nextToken (valid 30 seconds: pages are read at once) |
2 / 2 |
Order status mapping (FulfillmentOrderStatus): New, Received, Planning, Processing = open; Complete, CompletePartialled = shipped; Cancelled = cancelled; Unfulfillable, Invalid = failed. The comparison ignores case because the official getFulfillmentOrder example answers PROCESSING while the model enum is Processing.
Not used: updateFulfillmentOrder (an order edited after it was sent is not updated at Amazon), returns (createFulfillmentReturn), delivery offers, scheduled delivery windows, COD settings, the Notifications API (it needs AWS queues). The feature names BLANK_BOX (listed by the official getFeatures example) and BLOCK_AMZL (appears in the official preview example) are sent in featureConstraints; the sellers’ real feature list comes from Test connection.
Where the mock is not the real service
Section titled “Where the mock is not the real service”tests/mock-server/server.js validates every request body against the official models and answers with the model examples. These parts are built from the model schema, field by field, because the model has no example: the answers of getInventorySummaries, a SHIPPED fulfillment shipment with fulfillmentShipmentPackage rows, createFulfillmentOrder and cancelFulfillmentOrder (empty 200 body), the error texts (InvalidRequestParameter, NotFound, QuotaExceeded; the model lists no codes), and the NoInventory reason of an unfulfillable preview. The mock proves the add-on against the published models, not against the live service.
PHP hooks: change_order_status_post (queues the send / cancel at the configured statuses, only queues), delete_order (removes the Amazon rows), init_templater_post (upgrade synchronizer, only while an upgrade is pending). No template hooks on the storefront: the add-on prints nothing on cacheable pages, so the full page cache needs no exception. Admin: orders:tabs_extra (order tab), addons:manage / tabs_content (licence badge).
| Table | Content |
|---|---|
kv_amazon_mcf_accounts |
One row per account (0 = store owner, vendor company id otherwise); secrets sealed with AES-256-GCM; the refresh token is kept in the sealed *_webhook column of the mode. |
kv_amazon_mcf_orders |
One row per Amazon fulfillment order: seller order id, revision, state, Amazon status, error, timestamps. Saved before the request is sent. |
kv_amazon_mcf_shipments |
One row per package: Amazon shipment id, package number, carrier, tracking number and link, status, core shipment id. |
kv_amazon_mcf_skus |
SKU map with the fulfil / copy stock flags and the last FBA quantity. |
kv_amazon_mcf_jobs, kv_amazon_mcf_log, kv_amazon_mcf_cache |
Queue, log, ten-minute cache of previews. |
Idempotency
Section titled “Idempotency”createFulfillmentOrder has no idempotency key. The add-on saves the row (state P) before the request, uses a deterministic sellerFulfillmentOrderId, and on every retry or on an “already exists” answer reads the order with getFulfillmentOrder and adopts it. A second create is never sent for an order Amazon already has. All steps run under GET_LOCK per order.
Why amazon_sp is not required
Section titled “Why amazon_sp is not required”Both products talk to the Selling Partner API with the same login and region scheme, and this add-on copies those patterns (LWA token exchange, region hosts, User-Agent) instead of depending on amazon_sp: either can be sold and installed alone, no install order, no version coupling. The credentials of the two add-ons are independent; a store that uses both pastes the same LWA app into both Connection pages, or uses two apps.
Test hook
Section titled “Test hook”$config['kv_amazon_mcf_base_url'] = 'http://127.0.0.1:11977'; // development onlyThe login endpoint becomes <url>/auth/o2/token and every API path is appended to the same base. Tests refuse to run unless this points at localhost.