diff --git a/CHANGELOG.md b/CHANGELOG.md index 5378881..e046fdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.6.0 [#108](https://github.com/patterninc/muffin_man/pull/108) + +- Orders v2026-01-01 + # 2.5.1 [#107](https://github.com/patterninc/muffin_man/pull/107) - Added ORDER_CHANGE to PROCESSING_DIRECTIVE_SUPPORTED_NOTIFICATIONS in Notifications API v1 diff --git a/README.md b/README.md index be33b7d..ba6b04b 100644 --- a/README.md +++ b/README.md @@ -4,43 +4,6 @@ MuffinMan is a ruby interface to the Amazon Selling Partner API. For more information on registering to use the Selling Partner API, see [Amazon's documentation](https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/developer-guide/SellingPartnerApiDeveloperGuide.md) -As of now, this gem only supports portions of the following APIs with more to come: - -- `Customer Feedback Insights API v2024-06-01 (BETA)` -- `Amazon Warehousing and Distribution API v2024-05-09` -- `Catalog Items API v2022-04-01` -- `Data Kiosk API v2023-11-15` -- `FBA Inventory API v1` -- `Feeds API v2021-06-30` -- `Finances API v0` -- `Fulfillment Inbound API v2024-03-20` -- `Fulfillment Outbound API v2020-07-01` -- `Listings API v2021-08-01` -- `Listings API v2020-09-01` -- `Listings Restrictions API v2021-08-01` -- `Merchant Fulfillment API v0` -- `Notifications API v1` -- `Orders API v0` -- `Product Fees API v0` -- `Product Pricing API v0` -- `Reports API v2021-06-30` -- `Solicitations API v1` -- `Sellers API v1` -- `Tokens API v2021-03-01` -- `Vendor Direct Fulfillment Transactions API v1` -- `Vendor Direct Fulfillment Orders API v2021-12-28` -- `Vendor Direct Fulfillment Payments API v1` -- `Vendor Direct Fulfillment Shipping API v2021-12-28` -- `Vendor Direct Fulfillment Transactions API v2021-12-28` -- `Vendor Invoices API v1` -- `Vendor Orders API v1` -- `Vendor Shipments API v1` -- `Vendor Transaction Status API v1` -- `Uploads API v2020-11-01` -- `A+ API v2020-11-01` -- `Application Management API v2023-11-30` -- `Finances API v2024-06-19` - ## Installation Add this line to your application's Gemfile: diff --git a/lib/muffin_man.rb b/lib/muffin_man.rb index 38b2d84..50a1a5f 100644 --- a/lib/muffin_man.rb +++ b/lib/muffin_man.rb @@ -3,6 +3,7 @@ require "muffin_man/lwa/auth_helper" require "muffin_man/solicitations/v1" require "muffin_man/orders/v0" +require "muffin_man/orders/v20260101" require "muffin_man/reports/v20210630" require "muffin_man/catalog_items/v20201201" require "muffin_man/catalog_items/v20220401" diff --git a/lib/muffin_man/orders/v20260101.rb b/lib/muffin_man/orders/v20260101.rb new file mode 100644 index 0000000..6177787 --- /dev/null +++ b/lib/muffin_man/orders/v20260101.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module MuffinMan + module Orders + class V20260101 < SpApiClient + SEARCH_ORDERS_QUERY_PARAMS = %w[ + createdAfter + createdBefore + lastUpdatedAfter + lastUpdatedBefore + fulfillmentStatuses + marketplaceIds + fulfilledBy + maxResultsPerPage + paginationToken + includedData + ].freeze + + def search_orders(query_params: {}) + @local_var_path = "/orders/2026-01-01/orders" + @query_params = query_params.slice(*SEARCH_ORDERS_QUERY_PARAMS) + @request_type = "GET" + call_api + end + + def get_order(order_id, included_data: []) + @local_var_path = "/orders/2026-01-01/orders/#{order_id}" + @query_params = {} + @query_params["includedData"] = included_data.join(",") if included_data.any? + @request_type = "GET" + call_api + end + end + end +end diff --git a/lib/muffin_man/version.rb b/lib/muffin_man/version.rb index aedd6be..fc3d35c 100644 --- a/lib/muffin_man/version.rb +++ b/lib/muffin_man/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module MuffinMan - VERSION = "2.5.1" + VERSION = "2.6.0" end diff --git a/spec/muffin_man/orders/v20260101_spec.rb b/spec/muffin_man/orders/v20260101_spec.rb new file mode 100644 index 0000000..bf9f2d7 --- /dev/null +++ b/spec/muffin_man/orders/v20260101_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +RSpec.describe MuffinMan::Orders::V20260101 do + subject(:orders_client) { described_class.new(credentials) } + + before { stub_request_access_token } + + describe "#search_orders" do + it "returns orders" do + query_params = { "lastUpdatedBefore" => "2024-12-25T15:00:00Z" } + + stub_request(:get, "https://#{hostname}/orders/2026-01-01/orders") + .with(query: query_params) + .to_return(status: 200, body: File.read("./spec/support/orders/v20260101_search_orders.json")) + + response = orders_client.search_orders(query_params: query_params) + + expect(response).to be_success + expect(JSON.parse(response.body)["orders"]).to be_an(Array) + end + end + + describe "#get_order" do + it "returns the order" do + order_id = "202-1234567-8901234" + included_data = ["BUYER", "RECIPIENT"] + + stub_request(:get, "https://#{hostname}/orders/2026-01-01/orders/#{order_id}") + .with(query: { "includedData" => included_data.join(",") }) + .to_return(status: 200, body: File.read("./spec/support/orders/v20260101_get_order.json")) + + response = orders_client.get_order(order_id, included_data: included_data) + + expect(response).to be_success + expect(JSON.parse(response.body).dig("order", "orderId")).to eq(order_id) + end + end +end diff --git a/spec/support/orders/v20260101_get_order.json b/spec/support/orders/v20260101_get_order.json new file mode 100644 index 0000000..1936556 --- /dev/null +++ b/spec/support/orders/v20260101_get_order.json @@ -0,0 +1,207 @@ +{ + "order": { + "orderId": "202-1234567-8901234", + "orderAliases": [ + { + "aliasId": "UK-MERCHANT-ORDER-2024-001", + "aliasType": "SELLER_ORDER_ID" + } + ], + "createdTime": "2024-12-25T09:15:00Z", + "lastUpdatedTime": "2024-12-25T16:30:00Z", + "programs": [ + "PRIME" + ], + "salesChannel": { + "channelName": "AMAZON", + "marketplaceId": "A1F83G8C2ARO7P", + "marketplaceName": "Amazon.co.uk" + }, + "buyer": { + "buyerName": "James Wilson", + "buyerEmail": "buyer-email@marketplace.amazon.co.uk" + }, + "recipient": { + "deliveryAddress": { + "name": "James Wilson", + "companyName": "Wilson Electronics Ltd", + "addressLine1": "123 High Street", + "addressLine2": "Unit 4B", + "addressLine3": "", + "city": "Manchester", + "districtOrCounty": "Greater Manchester", + "stateOrRegion": "England", + "municipality": "", + "postalCode": "M1 2AB", + "countryCode": "GB", + "phone": "+44 161 123 4567", + "addressType": "COMMERCIAL" + } + }, + "proceeds": { + "grandTotal": { + "amount": "103.97", + "currencyCode": "GBP" + } + }, + "fulfillment": { + "fulfillmentStatus": "SHIPPED", + "fulfilledBy": "MERCHANT", + "fulfillmentServiceLevel": "STANDARD", + "shipByWindow": { + "earliestDateTime": "2024-12-25T00:00:00Z", + "latestDateTime": "2024-12-26T23:59:59Z" + }, + "deliverByWindow": { + "earliestDateTime": "2024-12-27T00:00:00Z", + "latestDateTime": "2024-12-30T23:59:59Z" + } + }, + "orderItems": [ + { + "orderItemId": "20212345678901", + "quantityOrdered": 3, + "programs": [ + "TRANSPARENCY" + ], + "product": { + "asin": "B08DFPV54V", + "title": "Echo Dot (4th Gen) | Smart speaker with Alexa | Charcoal", + "sellerSku": "ECHO-DOT-4-UK-CHARCOAL-3PACK", + "condition": { + "conditionType": "NEW", + "conditionSubtype": "NEW", + "conditionNote": "Brand new, sealed in original packaging" + }, + "price": { + "unitPrice": { + "amount": "29.99", + "currencyCode": "GBP" + }, + "priceDesignation": "BUSINESS_PRICE" + }, + "serialNumbers": [ + "ED4UK-2024-ABC123456789", + "ED4UK-2024-DEF987654321", + "ED4UK-2024-GHI456789123" + ], + "customization": { + "customizedUrl": "" + } + }, + "proceeds": { + "proceedsTotal": { + "amount": "103.97", + "currencyCode": "GBP" + }, + "breakdowns": [ + { + "type": "ITEM", + "subtotal": { + "amount": "89.97", + "currencyCode": "GBP" + } + }, + { + "type": "SHIPPING", + "subtotal": { + "amount": "10.00", + "currencyCode": "GBP" + } + }, + { + "type": "TAX", + "subtotal": { + "amount": "4.00", + "currencyCode": "GBP" + }, + "detailedBreakdowns": [ + { + "subtype": "ITEM", + "value": { + "amount": "3.00", + "currencyCode": "GBP" + } + }, + { + "subtype": "SHIPPING", + "value": { + "amount": "1.00", + "currencyCode": "GBP" + } + } + ] + } + ] + }, + "promotion": { + "breakdowns": [ + { + "promotionId": "UK-BOXING-DAY-2024" + } + ] + }, + "fulfillment": { + "quantityFulfilled": 3, + "quantityUnfulfilled": 0, + "packing": { + "giftOption": { + "giftMessage": "Happy Christmas! Hope you enjoy your new smart speakers.", + "giftWrapLevel": "PREMIUM" + } + }, + "shipping": { + "scheduledDeliveryWindow": { + "earliestDateTime": "2024-12-27T09:00:00Z", + "latestDateTime": "2024-12-27T17:00:00Z" + }, + "shippingConstraints": { + "signatureConfirmation": "MANDATORY", + "recipientIdentityVerification": "MANDATORY" + }, + "internationalShipping": { + "iossNumber": "IM1234567890" + } + } + } + } + ], + "packages": [ + { + "packageReferenceId": "UK-PKG-2024-001", + "createdTime": "2024-12-25T16:45:00Z", + "packageStatus": { + "status": "IN_TRANSIT", + "detailedStatus": "OUT_FOR_DELIVERY" + }, + "carrier": "Royal Mail", + "shipTime": "2024-12-26T14:00:00Z", + "shippingService": "Royal Mail Tracked 48", + "trackingNumber": "RR123456789GB", + "shipFromAddress": { + "name": "TechGear UK Warehouse", + "addressLine1": "Industrial Estate Unit 15", + "addressLine2": "Riverside Business Park", + "addressLine3": "", + "city": "Birmingham", + "districtOrCounty": "West Midlands", + "stateOrRegion": "England", + "municipality": "", + "postalCode": "B12 0XY", + "countryCode": "GB" + }, + "packageItems": [ + { + "orderItemId": "20212345678901", + "quantity": 3, + "transparencyCodes": [ + "T12345ABCDE67890UK", + "T12346ABCDF67891UK", + "T12347ABCDG67892UK" + ] + } + ] + } + ] + } +} diff --git a/spec/support/orders/v20260101_search_orders.json b/spec/support/orders/v20260101_search_orders.json new file mode 100644 index 0000000..7c889f2 --- /dev/null +++ b/spec/support/orders/v20260101_search_orders.json @@ -0,0 +1,357 @@ +{ + "orders": [ + { + "orderId": "123-4567890-1234567", + "orderAliases": [ + { + "aliasId": "SELLER-ORDER-2024-001", + "aliasType": "SELLER_ORDER_ID" + } + ], + "createdTime": "2024-12-25T10:30:00Z", + "lastUpdatedTime": "2024-12-25T14:45:00Z", + "programs": [ + "PRIME", + "AMAZON_BUSINESS" + ], + "associatedOrders": [ + { + "orderId": "123-4567890-1234566", + "associationType": "REPLACEMENT_ORIGINAL_ID" + } + ], + "salesChannel": { + "channelName": "AMAZON", + "marketplaceId": "ATVPDKIKX0DER", + "marketplaceName": "Amazon.com" + }, + "buyer": { + "buyerName": "John Smith", + "buyerEmail": "buyer-email@marketplace.amazon.com", + "buyerCompanyName": "Smith Industries LLC", + "buyerPurchaseOrderNumber": "PO-2024-12345" + }, + "recipient": { + "deliveryAddress": { + "name": "John Smith", + "companyName": "Smith Industries LLC", + "addressLine1": "123 Main Street", + "addressLine2": "Suite 456", + "addressLine3": "", + "city": "Seattle", + "districtOrCounty": "King County", + "stateOrRegion": "WA", + "municipality": "", + "postalCode": "98101", + "countryCode": "US", + "phone": "555-123-4567", + "addressType": "COMMERCIAL" + }, + "deliveryPreference": { + "dropOffLocation": "Front desk reception", + "addressInstruction": "Enter through main lobby, ask for John Smith at reception", + "deliveryTime": { + "businessHours": [ + { + "dayOfWeek": "MON", + "timeWindows": [ + { + "startTime": { + "hour": 9, + "minute": 0 + }, + "endTime": { + "hour": 17, + "minute": 0 + } + } + ] + }, + { + "dayOfWeek": "TUE", + "timeWindows": [ + { + "startTime": { + "hour": 9, + "minute": 0 + }, + "endTime": { + "hour": 17, + "minute": 0 + } + } + ] + }, + { + "dayOfWeek": "WED", + "timeWindows": [ + { + "startTime": { + "hour": 9, + "minute": 0 + }, + "endTime": { + "hour": 17, + "minute": 0 + } + } + ] + }, + { + "dayOfWeek": "THU", + "timeWindows": [ + { + "startTime": { + "hour": 9, + "minute": 0 + }, + "endTime": { + "hour": 17, + "minute": 0 + } + } + ] + }, + { + "dayOfWeek": "FRI", + "timeWindows": [ + { + "startTime": { + "hour": 9, + "minute": 0 + }, + "endTime": { + "hour": 17, + "minute": 0 + } + } + ] + } + ], + "exceptionDates": [ + { + "exceptionDate": "2024-12-31", + "exceptionDateType": "CLOSED", + "timeWindows": [] + } + ] + }, + "deliveryCapabilities": [ + "HAS_ACCESS_POINT", + "PALLET_ENABLED" + ] + } + }, + "proceeds": { + "grandTotal": { + "amount": "149.99", + "currencyCode": "USD" + } + }, + "fulfillment": { + "fulfillmentStatus": "SHIPPED", + "fulfilledBy": "MERCHANT", + "fulfillmentServiceLevel": "STANDARD", + "shipByWindow": { + "earliestDateTime": "2024-12-26T00:00:00Z", + "latestDateTime": "2024-12-27T23:59:59Z" + }, + "deliverByWindow": { + "earliestDateTime": "2024-12-28T00:00:00Z", + "latestDateTime": "2024-12-30T23:59:59Z" + } + }, + "orderItems": [ + { + "orderItemId": "12345678901234", + "quantityOrdered": 2, + "programs": [ + "TRANSPARENCY", + "SUBSCRIBE_AND_SAVE" + ], + "product": { + "asin": "B08N5WRWNW", + "title": "Echo Dot (4th Gen) | Smart speaker with Alexa | Charcoal", + "sellerSku": "ECHO-DOT-4-CHARCOAL", + "condition": { + "conditionType": "NEW", + "conditionSubtype": "NEW", + "conditionNote": "Brand new in original packaging" + }, + "price": { + "unitPrice": { + "amount": "49.99", + "currencyCode": "USD" + }, + "priceDesignation": "BUSINESS_PRICE" + }, + "customization": { + "customizedUrl": "https://amazon.com/custom/view/12345" + } + }, + "proceeds": { + "proceedsTotal": { + "amount": "99.98", + "currencyCode": "USD" + }, + "breakdowns": [ + { + "type": "ITEM", + "subtotal": { + "amount": "99.98", + "currencyCode": "USD" + } + }, + { + "type": "TAX", + "subtotal": { + "amount": "0.02", + "currencyCode": "USD" + }, + "detailedBreakdowns": [ + { + "subtype": "ITEM", + "value": { + "amount": "0.02", + "currencyCode": "USD" + } + } + ] + } + ] + }, + "promotion": { + "breakdowns": [ + { + "promotionId": "PROMO-HOLIDAY-2024" + } + ] + }, + "cancellation": { + "cancellationRequest": { + "requester": "BUYER", + "cancelReason": "Changed mind about purchase" + } + }, + "fulfillment": { + "quantityFulfilled": 2, + "quantityUnfulfilled": 0, + "packing": { + "giftOption": { + "giftMessage": "Happy Holidays! Enjoy your new smart speakers.", + "giftWrapLevel": "PREMIUM" + } + }, + "shipping": { + "scheduledDeliveryWindow": { + "earliestDateTime": "2024-12-28T09:00:00Z", + "latestDateTime": "2024-12-28T17:00:00Z" + }, + "shippingConstraints": { + "palletDelivery": "MANDATORY", + "cashOnDelivery": "MANDATORY", + "signatureConfirmation": "MANDATORY", + "recipientIdentityVerification": "MANDATORY", + "recipientAgeVerification": "MANDATORY" + } + } + } + }, + { + "orderItemId": "12345678901235", + "quantityOrdered": 1, + "programs": [], + "product": { + "asin": "B07XJ8C8F5", + "title": "Fire TV Stick 4K with Alexa Voice Remote", + "sellerSku": "FIRE-TV-4K-2021", + "condition": { + "conditionType": "NEW", + "conditionSubtype": "NEW", + "conditionNote": "" + }, + "price": { + "unitPrice": { + "amount": "49.99", + "currencyCode": "USD" + } + } + }, + "proceeds": { + "proceedsTotal": { + "amount": "49.99", + "currencyCode": "USD" + }, + "breakdowns": [ + { + "type": "ITEM", + "subtotal": { + "amount": "49.99", + "currencyCode": "USD" + } + } + ] + }, + "fulfillment": { + "quantityFulfilled": 1, + "quantityUnfulfilled": 0, + "shipping": { + "scheduledDeliveryWindow": { + "earliestDateTime": "2024-12-28T09:00:00Z", + "latestDateTime": "2024-12-28T17:00:00Z" + }, + "shippingConstraints": { + "signatureConfirmation": "MANDATORY" + } + } + } + } + ], + "packages": [ + { + "packageReferenceId": "PKG-2024-001", + "createdTime": "2024-12-25T15:00:00Z", + "packageStatus": { + "status": "DELIVERED", + "detailedStatus": "DELIVERED" + }, + "carrier": "UPS", + "shipTime": "2024-12-25T14:00:00Z", + "shippingService": "UPS Ground", + "trackingNumber": "1Z999AA1234567890", + "shipFromAddress": { + "name": "Smith Electronics Warehouse", + "addressLine1": "456 Industrial Blvd", + "addressLine2": "Building A", + "city": "Bellevue", + "districtOrCounty": "King County", + "stateOrRegion": "WA", + "postalCode": "98004", + "countryCode": "US" + }, + "packageItems": [ + { + "orderItemId": "12345678901234", + "quantity": 2, + "transparencyCodes": [ + "T12345ABCDE67890", + "T12346ABCDF67891" + ] + }, + { + "orderItemId": "12345678901235", + "quantity": 1, + "transparencyCodes": [ + "T67890GHIJK12345" + ] + } + ] + } + ] + } + ], + "pagination": { + "nextToken": "2YgYW55IGNhcm5hbCBwbGVhc3VyZS4" + }, + "lastUpdatedBefore": "2024-12-25T15:00:00Z" +}