diff --git a/Networking/Networking.xcodeproj/project.pbxproj b/Networking/Networking.xcodeproj/project.pbxproj index 8372f28ca85..b0c6f51895f 100644 --- a/Networking/Networking.xcodeproj/project.pbxproj +++ b/Networking/Networking.xcodeproj/project.pbxproj @@ -717,10 +717,17 @@ DE50296328C609DE00551736 /* jetpack-user-not-connected.json in Resources */ = {isa = PBXBuildFile; fileRef = DE50296228C609DE00551736 /* jetpack-user-not-connected.json */; }; DE50296528C60A8000551736 /* JetpackUserMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE50296428C60A8000551736 /* JetpackUserMapperTests.swift */; }; DE5CA111288A3E080077BEF9 /* product-malformed-variations-and-image-alt.json in Resources */ = {isa = PBXBuildFile; fileRef = DE5CA110288A3E080077BEF9 /* product-malformed-variations-and-image-alt.json */; }; + DE66C5532976508300DAA978 /* CookieNonceAuthenticator.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE66C5522976508300DAA978 /* CookieNonceAuthenticator.swift */; }; DE66C5552976662700DAA978 /* just-in-time-message-list-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5542976662700DAA978 /* just-in-time-message-list-without-data.json */; }; DE66C5572976913C00DAA978 /* wcpay-charge-card-present-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5562976913C00DAA978 /* wcpay-charge-card-present-without-data.json */; }; DE66C559297799D000DAA978 /* add-on-groups-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C558297799CF00DAA978 /* add-on-groups-without-data.json */; }; - DE66C5532976508300DAA978 /* CookieNonceAuthenticator.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE66C5522976508300DAA978 /* CookieNonceAuthenticator.swift */; }; + DE66C55B2977C1A000DAA978 /* order-shipping-labels-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C55A2977C1A000DAA978 /* order-shipping-labels-without-data.json */; }; + DE66C55D2977C35A00DAA978 /* shipping-label-packages-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C55C2977C35A00DAA978 /* shipping-label-packages-success-without-data.json */; }; + DE66C55F2977C67D00DAA978 /* shipping-label-account-settings-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C55E2977C67D00DAA978 /* shipping-label-account-settings-without-data.json */; }; + DE66C5612977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5602977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json */; }; + DE66C5632977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */; }; + DE66C5652977CC4300DAA978 /* shipping-label-purchase-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */; }; + DE66C5672977CEB800DAA978 /* shipping-label-status-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */; }; DE6F308727966FEF004E1C9A /* CouponReportListMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */; }; DE74F29A27E08F5A0002FE59 /* SiteSettingMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */; }; DE74F29C27E0A1D00002FE59 /* setting-coupon.json in Resources */ = {isa = PBXBuildFile; fileRef = DE74F29B27E0A1D00002FE59 /* setting-coupon.json */; }; @@ -1558,10 +1565,17 @@ DE50296228C609DE00551736 /* jetpack-user-not-connected.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "jetpack-user-not-connected.json"; sourceTree = ""; }; DE50296428C60A8000551736 /* JetpackUserMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackUserMapperTests.swift; sourceTree = ""; }; DE5CA110288A3E080077BEF9 /* product-malformed-variations-and-image-alt.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "product-malformed-variations-and-image-alt.json"; sourceTree = ""; }; + DE66C5522976508300DAA978 /* CookieNonceAuthenticator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CookieNonceAuthenticator.swift; sourceTree = ""; }; DE66C5542976662700DAA978 /* just-in-time-message-list-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "just-in-time-message-list-without-data.json"; sourceTree = ""; }; DE66C5562976913C00DAA978 /* wcpay-charge-card-present-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "wcpay-charge-card-present-without-data.json"; sourceTree = ""; }; DE66C558297799CF00DAA978 /* add-on-groups-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "add-on-groups-without-data.json"; sourceTree = ""; }; - DE66C5522976508300DAA978 /* CookieNonceAuthenticator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CookieNonceAuthenticator.swift; sourceTree = ""; }; + DE66C55A2977C1A000DAA978 /* order-shipping-labels-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "order-shipping-labels-without-data.json"; sourceTree = ""; }; + DE66C55C2977C35A00DAA978 /* shipping-label-packages-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-packages-success-without-data.json"; sourceTree = ""; }; + DE66C55E2977C67D00DAA978 /* shipping-label-account-settings-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-account-settings-without-data.json"; sourceTree = ""; }; + DE66C5602977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-eligibility-success-without-data.json"; sourceTree = ""; }; + DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-eligibility-failure-without-data.json"; sourceTree = ""; }; + DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-purchase-success-without-data.json"; sourceTree = ""; }; + DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-status-success-without-data.json"; sourceTree = ""; }; DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponReportListMapperTests.swift; sourceTree = ""; }; DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteSettingMapper.swift; sourceTree = ""; }; DE74F29B27E0A1D00002FE59 /* setting-coupon.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "setting-coupon.json"; sourceTree = ""; }; @@ -2191,6 +2205,13 @@ B559EBA820A0B5B100836CD4 /* Responses */ = { isa = PBXGroup; children = ( + DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */, + DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */, + DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */, + DE66C5602977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json */, + DE66C55E2977C67D00DAA978 /* shipping-label-account-settings-without-data.json */, + DE66C55C2977C35A00DAA978 /* shipping-label-packages-success-without-data.json */, + DE66C55A2977C1A000DAA978 /* order-shipping-labels-without-data.json */, DE66C558297799CF00DAA978 /* add-on-groups-without-data.json */, DE66C5542976662700DAA978 /* just-in-time-message-list-without-data.json */, DE66C5562976913C00DAA978 /* wcpay-charge-card-present-without-data.json */, @@ -3047,6 +3068,7 @@ DEA6B1C9296D0E8B005AA5E9 /* systemStatusWithPluginsOnly-without-data.json in Resources */, 314EDF2927C02CC100A56B6F /* stripe-account-complete-empty-descriptor.json in Resources */, 028CB71F2902589E00331C09 /* create-account-error-invalid-email.json in Resources */, + DE66C55F2977C67D00DAA978 /* shipping-label-account-settings-without-data.json in Resources */, E137619929151C7400FD098F /* error-wp-rest-forbidden.json in Resources */, 31A451CE27863A2E00FE81AA /* stripe-account-wrong-json.json in Resources */, 26BD9FCD2965EC3C004E0D15 /* product-variations-bulk-create.json in Resources */, @@ -3066,6 +3088,7 @@ DEC51A9B274E3206009F3DF4 /* plugin-inactive.json in Resources */, CCF48B382628AEAE0034EA83 /* shipping-label-account-settings-no-payment-methods.json in Resources */, 31A451D327863A2E00FE81AA /* stripe-account-complete.json in Resources */, + DE66C5632977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json in Resources */, DE42F96F296BC9A700D514C2 /* countries-without-data.json in Resources */, EECB7EE8286555180028C888 /* media-update-product-id.json in Resources */, D88D5A43230BC668007B6E01 /* reviews-single.json in Resources */, @@ -3073,6 +3096,7 @@ 02DD6492248A3EC00082523E /* product-external.json in Resources */, 03DCB7522624B3BE00C8953D /* coupons-all.json in Resources */, 02B41A94296C04BC00FE3311 /* load-site-plans-no-current-plan.json in Resources */, + DE66C5612977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json in Resources */, 028CB716290223CB00331C09 /* create-account-success.json in Resources */, 036563E129069D3500D84BFD /* just-in-time-message-list.json in Resources */, 45A4B85C25D2FAB500776FB4 /* shipping-label-address-validation-error.json in Resources */, @@ -3123,6 +3147,7 @@ DEF13C5A296571150024A02B /* leaderboards-year-without-data.json in Resources */, 2683D70E24456DB8002A1589 /* categories-empty.json in Resources */, D865CE67278CA225002C8520 /* stripe-payment-intent-succeeded.json in Resources */, + DE66C5652977CC4300DAA978 /* shipping-label-purchase-success-without-data.json in Resources */, DE74F2A027E3137F0002FE59 /* setting-analytics.json in Resources */, 0272E3F5254AA48F00436277 /* order-with-line-item-attributes.json in Resources */, 3105471C262E2F8000C5C02B /* wcpay-payment-intent-requires-action.json in Resources */, @@ -3153,6 +3178,7 @@ 453305ED2459E1AA00264E50 /* site-post.json in Resources */, 74749B99224135C4005C4CF2 /* product.json in Resources */, 4515281F257A89B90076B03C /* product-attribute-create.json in Resources */, + DE66C55B2977C1A000DAA978 /* order-shipping-labels-without-data.json in Resources */, CEF88DAF233E9F7E00BED485 /* order-details-partially-refunded.json in Resources */, D823D9032237450A00C90817 /* shipment_tracking_new.json in Resources */, DE4F2A442975684900B0701C /* site-api-without-data.json in Resources */, @@ -3199,6 +3225,7 @@ 74A1D264211898F000931DFA /* site-visits-week.json in Resources */, B53EF53621813681003E146F /* generic_success.json in Resources */, 31054718262E2F5E00C5C02B /* wcpay-payment-intent-requires-confirmation.json in Resources */, + DE66C5672977CEB800DAA978 /* shipping-label-status-success-without-data.json in Resources */, D8FBFF2922D52AFB006E3336 /* order-stats-v4-year.json in Resources */, D865CE65278CA202002C8520 /* stripe-payment-intent-canceled.json in Resources */, DE42F9672967F61D00D514C2 /* refunds-all-without-data.json in Resources */, @@ -3265,6 +3292,7 @@ 451A97DE260B59870059D135 /* shipping-label-packages-success.json in Resources */, 2676F4D0290B0EC800C7A15B /* product-id-only.json in Resources */, 31D27C8F2602B553002EDB1D /* plugins.json in Resources */, + DE66C55D2977C35A00DAA978 /* shipping-label-packages-success-without-data.json in Resources */, 261CF1B4255AD6B30090D8D3 /* payment-gateway-list.json in Resources */, 268B68FB24C87384007EBF1D /* leaderboards-products.json in Resources */, 0359EA2527AAF7D60048DE2D /* wcpay-charge-card.json in Resources */, diff --git a/Networking/Networking/Mapper/OrderShippingLabelListMapper.swift b/Networking/Networking/Mapper/OrderShippingLabelListMapper.swift index 7ed178745c3..7e39a515722 100644 --- a/Networking/Networking/Mapper/OrderShippingLabelListMapper.swift +++ b/Networking/Networking/Mapper/OrderShippingLabelListMapper.swift @@ -32,9 +32,14 @@ struct OrderShippingLabelListMapper: Mapper { .orderID: orderID ] - let envelope = try decoder.decode(OrderShippingLabelListEnvelope.self, from: response) - let data = OrderShippingLabelListResponse(shippingLabels: envelope.data.shippingLabels, settings: envelope.data.settings) - return data + let data: OrderShippingLabelListData = try { + do { + return try decoder.decode(OrderShippingLabelListEnvelope.self, from: response).data + } catch { + return try decoder.decode(OrderShippingLabelListData.self, from: response) + } + }() + return OrderShippingLabelListResponse(shippingLabels: data.shippingLabels, settings: data.settings) } } diff --git a/Networking/Networking/Mapper/ShippingLabelAccountSettingsMapper.swift b/Networking/Networking/Mapper/ShippingLabelAccountSettingsMapper.swift index 8f5a6ec2813..fba378438f8 100644 --- a/Networking/Networking/Mapper/ShippingLabelAccountSettingsMapper.swift +++ b/Networking/Networking/Mapper/ShippingLabelAccountSettingsMapper.swift @@ -17,7 +17,11 @@ struct ShippingLabelAccountSettingsMapper: Mapper { .siteID: siteID ] - return try decoder.decode(ShippingLabelAccountSettingsMapperEnvelope.self, from: response).data + do { + return try decoder.decode(ShippingLabelAccountSettingsMapperEnvelope.self, from: response).data + } catch { + return try decoder.decode(ShippingLabelAccountSettings.self, from: response) + } } } diff --git a/Networking/Networking/Mapper/ShippingLabelAddressValidationSuccessMapper.swift b/Networking/Networking/Mapper/ShippingLabelAddressValidationSuccessMapper.swift index 7b6ee10ea84..7c5e307a536 100644 --- a/Networking/Networking/Mapper/ShippingLabelAddressValidationSuccessMapper.swift +++ b/Networking/Networking/Mapper/ShippingLabelAddressValidationSuccessMapper.swift @@ -8,10 +8,14 @@ struct ShippingLabelAddressValidationSuccessMapper: Mapper { /// func map(response: Data) throws -> ShippingLabelAddressValidationSuccess { let decoder = JSONDecoder() - return try decoder.decode(ShippingLabelAddressValidationResponseEnvelope.self, from: response) - .data - .result - .get() + let data: ShippingLabelAddressValidationResponse = try { + do { + return try decoder.decode(ShippingLabelAddressValidationResponseEnvelope.self, from: response).data + } catch { + return try decoder.decode(ShippingLabelAddressValidationResponse.self, from: response) + } + }() + return try data.result.get() } } diff --git a/Networking/Networking/Mapper/ShippingLabelCarriersAndRatesMapper.swift b/Networking/Networking/Mapper/ShippingLabelCarriersAndRatesMapper.swift index 3fd456261c5..baeaab8a021 100644 --- a/Networking/Networking/Mapper/ShippingLabelCarriersAndRatesMapper.swift +++ b/Networking/Networking/Mapper/ShippingLabelCarriersAndRatesMapper.swift @@ -8,7 +8,11 @@ struct ShippingLabelCarriersAndRatesMapper: Mapper { /// func map(response: Data) throws -> [ShippingLabelCarriersAndRates] { let decoder = JSONDecoder() - return try decoder.decode(ShippingLabelDataEnvelope.self, from: response).data.rates.boxes + do { + return try decoder.decode(ShippingLabelDataEnvelope.self, from: response).data.rates.boxes + } catch { + return try decoder.decode(ShippingLabelRatesEnvelope.self, from: response).rates.boxes + } } } diff --git a/Networking/Networking/Mapper/ShippingLabelCreationEligibilityMapper.swift b/Networking/Networking/Mapper/ShippingLabelCreationEligibilityMapper.swift index 8a8a76e950d..2e5d2a293f4 100644 --- a/Networking/Networking/Mapper/ShippingLabelCreationEligibilityMapper.swift +++ b/Networking/Networking/Mapper/ShippingLabelCreationEligibilityMapper.swift @@ -7,7 +7,11 @@ struct ShippingLabelCreationEligibilityMapper: Mapper { /// func map(response: Data) throws -> ShippingLabelCreationEligibilityResponse { let decoder = JSONDecoder() - return try decoder.decode(ShippingLabelCreationEligibilityMapperEnvelope.self, from: response).eligibility + do { + return try decoder.decode(ShippingLabelCreationEligibilityMapperEnvelope.self, from: response).eligibility + } catch { + return try decoder.decode(ShippingLabelCreationEligibilityResponse.self, from: response) + } } } diff --git a/Networking/Networking/Mapper/ShippingLabelPackagesMapper.swift b/Networking/Networking/Mapper/ShippingLabelPackagesMapper.swift index 7dcd7634d37..8e69b19d8f0 100644 --- a/Networking/Networking/Mapper/ShippingLabelPackagesMapper.swift +++ b/Networking/Networking/Mapper/ShippingLabelPackagesMapper.swift @@ -8,7 +8,11 @@ struct ShippingLabelPackagesMapper: Mapper { /// func map(response: Data) throws -> ShippingLabelPackagesResponse { let decoder = JSONDecoder() - return try decoder.decode(ShippingLabelPackagesMapperEnvelope.self, from: response).data + do { + return try decoder.decode(ShippingLabelPackagesMapperEnvelope.self, from: response).data + } catch { + return try decoder.decode(ShippingLabelPackagesResponse.self, from: response) + } } } diff --git a/Networking/Networking/Mapper/ShippingLabelPrintDataMapper.swift b/Networking/Networking/Mapper/ShippingLabelPrintDataMapper.swift index 82c9fa7e2d4..87806c0f598 100644 --- a/Networking/Networking/Mapper/ShippingLabelPrintDataMapper.swift +++ b/Networking/Networking/Mapper/ShippingLabelPrintDataMapper.swift @@ -8,7 +8,11 @@ struct ShippingLabelPrintDataMapper: Mapper { /// func map(response: Data) throws -> ShippingLabelPrintData { let decoder = JSONDecoder() - return try decoder.decode(ShippingLabelPrintDataEnvelope.self, from: response).printData + do { + return try decoder.decode(ShippingLabelPrintDataEnvelope.self, from: response).printData + } catch { + return try decoder.decode(ShippingLabelPrintData.self, from: response) + } } } diff --git a/Networking/Networking/Mapper/ShippingLabelPurchaseMapper.swift b/Networking/Networking/Mapper/ShippingLabelPurchaseMapper.swift index 4e9cad2fb1d..b938fa33fa5 100644 --- a/Networking/Networking/Mapper/ShippingLabelPurchaseMapper.swift +++ b/Networking/Networking/Mapper/ShippingLabelPurchaseMapper.swift @@ -25,7 +25,11 @@ struct ShippingLabelPurchaseMapper: Mapper { .orderID: orderID ] - return try decoder.decode(ShippingLabelPurchaseResponse.self, from: response).data.labels + do { + return try decoder.decode(ShippingLabelPurchaseResponse.self, from: response).data.labels + } catch { + return try decoder.decode(ShippingLabelPurchaseEnvelope.self, from: response).labels + } } } diff --git a/Networking/Networking/Mapper/ShippingLabelRefundMapper.swift b/Networking/Networking/Mapper/ShippingLabelRefundMapper.swift index bc5088d7486..3fd3c11dbe1 100644 --- a/Networking/Networking/Mapper/ShippingLabelRefundMapper.swift +++ b/Networking/Networking/Mapper/ShippingLabelRefundMapper.swift @@ -9,7 +9,11 @@ struct ShippingLabelRefundMapper: Mapper { func map(response: Data) throws -> ShippingLabelRefund { let decoder = JSONDecoder() decoder.dateDecodingStrategy = .millisecondsSince1970 - return try decoder.decode(ShippingLabelRefundResponse.self, from: response).data.refund + do { + return try decoder.decode(ShippingLabelRefundResponse.self, from: response).data.refund + } catch { + return try decoder.decode(ShippingLabelRefundEnvelope.self, from: response).refund + } } } diff --git a/Networking/Networking/Mapper/ShippingLabelStatusMapper.swift b/Networking/Networking/Mapper/ShippingLabelStatusMapper.swift index 03e45939ffd..4560e45ce06 100644 --- a/Networking/Networking/Mapper/ShippingLabelStatusMapper.swift +++ b/Networking/Networking/Mapper/ShippingLabelStatusMapper.swift @@ -25,7 +25,11 @@ struct ShippingLabelStatusMapper: Mapper { .orderID: orderID ] - return try decoder.decode(ShippingLabelStatusResponse.self, from: response).data.labels + do { + return try decoder.decode(ShippingLabelStatusResponse.self, from: response).data.labels + } catch { + return try decoder.decode(ShippingLabelStatusEnvelope.self, from: response).labels + } } } diff --git a/Networking/Networking/Mapper/SuccessDataResultMapper.swift b/Networking/Networking/Mapper/SuccessDataResultMapper.swift index bba28a04595..ce97453369f 100644 --- a/Networking/Networking/Mapper/SuccessDataResultMapper.swift +++ b/Networking/Networking/Mapper/SuccessDataResultMapper.swift @@ -8,7 +8,14 @@ struct SuccessDataResultMapper: Mapper { /// (Attempts) to extract the `success` flag from a given JSON Encoded response. /// func map(response: Data) throws -> Bool { - let rawData = try JSONDecoder().decode(SuccessDataResultEnvelope.self, from: response).rawData + let decoder = JSONDecoder() + let rawData: [String: Bool] = try { + do { + return try decoder.decode(SuccessDataResultEnvelope.self, from: response).rawData + } catch { + return try decoder.decode([String: Bool].self, from: response) + } + }() return rawData["success"] ?? false } } diff --git a/Networking/Networking/Remote/ShippingLabelRemote.swift b/Networking/Networking/Remote/ShippingLabelRemote.swift index 25f8b1ee565..47a3e24a04f 100644 --- a/Networking/Networking/Remote/ShippingLabelRemote.swift +++ b/Networking/Networking/Remote/ShippingLabelRemote.swift @@ -56,7 +56,11 @@ public final class ShippingLabelRemote: Remote, ShippingLabelRemoteProtocol { /// - completion: Closure to be executed upon completion. public func loadShippingLabels(siteID: Int64, orderID: Int64, completion: @escaping (Result) -> Void) { let path = "\(Path.shippingLabels)/\(orderID)" - let request = JetpackRequest(wooApiVersion: .wcConnectV1, method: .get, siteID: siteID, path: path) + let request = JetpackRequest(wooApiVersion: .wcConnectV1, + method: .get, + siteID: siteID, + path: path, + availableAsRESTRequest: true) let mapper = OrderShippingLabelListMapper(siteID: siteID, orderID: orderID) enqueue(request, mapper: mapper, completion: completion) } @@ -78,7 +82,12 @@ public final class ShippingLabelRemote: Remote, ShippingLabelRemoteProtocol { ParameterKey.json: "true" // `json=true` is necessary, otherwise it results in 500 error "no_response_body". ] let path = "\(Path.shippingLabels)/print" - let request = JetpackRequest(wooApiVersion: .wcConnectV1, method: .get, siteID: siteID, path: path, parameters: parameters) + let request = JetpackRequest(wooApiVersion: .wcConnectV1, + method: .get, + siteID: siteID, + path: path, + parameters: parameters, + availableAsRESTRequest: true) let mapper = ShippingLabelPrintDataMapper() enqueue(request, mapper: mapper, completion: completion) @@ -92,7 +101,11 @@ public final class ShippingLabelRemote: Remote, ShippingLabelRemoteProtocol { /// - completion: Closure to be executed upon completion. public func refundShippingLabel(siteID: Int64, orderID: Int64, shippingLabelID: Int64, completion: @escaping (Result) -> Void) { let path = "\(Path.shippingLabels)/\(orderID)/\(shippingLabelID)/refund" - let request = JetpackRequest(wooApiVersion: .wcConnectV1, method: .post, siteID: siteID, path: path) + let request = JetpackRequest(wooApiVersion: .wcConnectV1, + method: .post, + siteID: siteID, + path: path, + availableAsRESTRequest: true) let mapper = ShippingLabelRefundMapper() enqueue(request, mapper: mapper, completion: completion) } @@ -108,7 +121,12 @@ public final class ShippingLabelRemote: Remote, ShippingLabelRemoteProtocol { do { let parameters = try address.toDictionary() let path = "\(Path.normalizeAddress)" - let request = JetpackRequest(wooApiVersion: .wcConnectV1, method: .post, siteID: siteID, path: path, parameters: parameters) + let request = JetpackRequest(wooApiVersion: .wcConnectV1, + method: .post, + siteID: siteID, + path: path, + parameters: parameters, + availableAsRESTRequest: true) let mapper = ShippingLabelAddressValidationSuccessMapper() enqueue(request, mapper: mapper, completion: completion) } catch { @@ -123,7 +141,12 @@ public final class ShippingLabelRemote: Remote, ShippingLabelRemoteProtocol { public func packagesDetails(siteID: Int64, completion: @escaping (Result) -> Void) { let path = Path.packages - let request = JetpackRequest(wooApiVersion: .wcConnectV1, method: .get, siteID: siteID, path: path, parameters: nil) + let request = JetpackRequest(wooApiVersion: .wcConnectV1, + method: .get, + siteID: siteID, + path: path, + parameters: nil, + availableAsRESTRequest: true) let mapper = ShippingLabelPackagesMapper() enqueue(request, mapper: mapper, completion: completion) } @@ -157,7 +180,12 @@ public final class ShippingLabelRemote: Remote, ShippingLabelRemoteProtocol { ParameterKey.predefined: predefinedOptionDictionary ] let path = Path.packages - let request = JetpackRequest(wooApiVersion: .wcConnectV1, method: .post, siteID: siteID, path: path, parameters: parameters) + let request = JetpackRequest(wooApiVersion: .wcConnectV1, + method: .post, + siteID: siteID, + path: path, + parameters: parameters, + availableAsRESTRequest: true) let mapper = SuccessDataResultMapper() enqueue(request, mapper: mapper, completion: completion) } catch { @@ -186,7 +214,12 @@ public final class ShippingLabelRemote: Remote, ShippingLabelRemoteProtocol { ParameterKey.packages: try packages.map { try $0.toDictionary() } ] let path = "\(Path.shippingLabels)/\(orderID)/rates" - let request = JetpackRequest(wooApiVersion: .wcConnectV1, method: .post, siteID: siteID, path: path, parameters: parameters) + let request = JetpackRequest(wooApiVersion: .wcConnectV1, + method: .post, + siteID: siteID, + path: path, + parameters: parameters, + availableAsRESTRequest: true) let mapper = ShippingLabelCarriersAndRatesMapper() enqueue(request, mapper: mapper, completion: completion) } @@ -201,7 +234,11 @@ public final class ShippingLabelRemote: Remote, ShippingLabelRemoteProtocol { /// - completion: Closure to be executed upon completion. public func loadShippingLabelAccountSettings(siteID: Int64, completion: @escaping (Result) -> Void) { let path = Path.accountSettings - let request = JetpackRequest(wooApiVersion: .wcConnectV1, method: .get, siteID: siteID, path: path) + let request = JetpackRequest(wooApiVersion: .wcConnectV1, + method: .get, + siteID: siteID, + path: path, + availableAsRESTRequest: true) let mapper = ShippingLabelAccountSettingsMapper(siteID: siteID) enqueue(request, mapper: mapper, completion: completion) } @@ -218,7 +255,12 @@ public final class ShippingLabelRemote: Remote, ShippingLabelRemoteProtocol { ParameterKey.paperSize: settings.paperSize.rawValue ] let path = Path.accountSettings - let request = JetpackRequest(wooApiVersion: .wcConnectV1, method: .post, siteID: siteID, path: path, parameters: parameters) + let request = JetpackRequest(wooApiVersion: .wcConnectV1, + method: .post, + siteID: siteID, + path: path, + parameters: parameters, + availableAsRESTRequest: true) let mapper = SuccessDataResultMapper() enqueue(request, mapper: mapper, completion: completion) } @@ -232,7 +274,12 @@ public final class ShippingLabelRemote: Remote, ShippingLabelRemoteProtocol { orderID: Int64, completion: @escaping (Result) -> Void) { let path = "\(Path.shippingLabels)/\(orderID)/creation_eligibility" - let request = JetpackRequest(wooApiVersion: .wcConnectV1, method: .get, siteID: siteID, path: path, parameters: nil) + let request = JetpackRequest(wooApiVersion: .wcConnectV1, + method: .get, + siteID: siteID, + path: path, + parameters: nil, + availableAsRESTRequest: true) let mapper = ShippingLabelCreationEligibilityMapper() enqueue(request, mapper: mapper, completion: completion) } @@ -265,7 +312,12 @@ public final class ShippingLabelRemote: Remote, ShippingLabelRemoteProtocol { ParameterKey.emailReceipt: emailCustomerReceipt ] let path = "\(Path.shippingLabels)/\(orderID)" - let request = JetpackRequest(wooApiVersion: .wcConnectV1, method: .post, siteID: siteID, path: path, parameters: parameters) + let request = JetpackRequest(wooApiVersion: .wcConnectV1, + method: .post, + siteID: siteID, + path: path, + parameters: parameters, + availableAsRESTRequest: true) let mapper = ShippingLabelPurchaseMapper(siteID: siteID, orderID: orderID) enqueue(request, mapper: mapper, completion: completion) } @@ -289,7 +341,11 @@ public final class ShippingLabelRemote: Remote, ShippingLabelRemoteProtocol { completion: @escaping (Result<[ShippingLabelStatusPollingResponse], Error>) -> Void) { let labelIDs = labelIDs.map(String.init).joined(separator: ",") let path = "\(Path.shippingLabels)/\(orderID)/\(labelIDs)" - let request = JetpackRequest(wooApiVersion: .wcConnectV1, method: .get, siteID: siteID, path: path) + let request = JetpackRequest(wooApiVersion: .wcConnectV1, + method: .get, + siteID: siteID, + path: path, + availableAsRESTRequest: true) let mapper = ShippingLabelStatusMapper(siteID: siteID, orderID: orderID) enqueue(request, mapper: mapper, completion: completion) } diff --git a/Networking/NetworkingTests/Mapper/OrderShippingLabelListMapperTests.swift b/Networking/NetworkingTests/Mapper/OrderShippingLabelListMapperTests.swift index 799b73af5cc..8d38775da54 100644 --- a/Networking/NetworkingTests/Mapper/OrderShippingLabelListMapperTests.swift +++ b/Networking/NetworkingTests/Mapper/OrderShippingLabelListMapperTests.swift @@ -76,4 +76,16 @@ final class OrderShippingLabelListMapperTests: XCTestCase { commercialInvoiceURL: nil) XCTAssertEqual(response.shippingLabels, [shippingLabelWithoutRefund, shippingLabelWithRefund]) } + + func test_order_shipping_labels_and_settings_are_properly_parsed_when_response_has_no_data_envelope() throws { + // Given + let jsonData = try XCTUnwrap(Loader.contentsOf("order-shipping-labels-without-data")) + + // When + let response = try OrderShippingLabelListMapper(siteID: sampleSiteID, orderID: sampleOrderID).map(response: jsonData) + + // Then + XCTAssertEqual(response.settings, .init(siteID: sampleSiteID, orderID: sampleOrderID, paperSize: .label)) + XCTAssertEqual(response.shippingLabels.count, 1) + } } diff --git a/Networking/NetworkingTests/Mapper/ShippingLabelAccountSettingsMapperTests.swift b/Networking/NetworkingTests/Mapper/ShippingLabelAccountSettingsMapperTests.swift index baca7225cc8..cf91df79680 100644 --- a/Networking/NetworkingTests/Mapper/ShippingLabelAccountSettingsMapperTests.swift +++ b/Networking/NetworkingTests/Mapper/ShippingLabelAccountSettingsMapperTests.swift @@ -31,6 +31,28 @@ class ShippingLabelAccountSettingsMapperTests: XCTestCase { XCTAssertEqual(settings.storeOwnerWpcomUsername, "apiexamples") } + /// Verifies that the Shipping Label Account Settings are parsed correctly. + /// + func test_Account_Settings_are_properly_parsed_when_response_has_no_data_envelope() { + guard let settings = mapLoadShippingLabelAccountSettingsWithoutDataEnvelope() else { + XCTFail() + return + } + + XCTAssertEqual(settings.siteID, sampleSiteID) + XCTAssertEqual(settings.canEditSettings, true) + XCTAssertEqual(settings.canManagePayments, true) + XCTAssertEqual(settings.isEmailReceiptsEnabled, true) + XCTAssertEqual(settings.lastSelectedPackageID, "small_flat_box") + XCTAssertEqual(settings.paperSize, .label) + XCTAssertEqual(settings.paymentMethods, [sampleShippingLabelPaymentMethod()]) + XCTAssertEqual(settings.selectedPaymentMethodID, 11743265) + XCTAssertEqual(settings.storeOwnerDisplayName, "Example User") + XCTAssertEqual(settings.storeOwnerUsername, "admin") + XCTAssertEqual(settings.storeOwnerWpcomEmail, "example@example.com") + XCTAssertEqual(settings.storeOwnerWpcomUsername, "apiexamples") + } + /// Verifies that the Shipping Label Account Settings without any payment methods are parsed correctly. /// func test_Account_Settings_without_payment_methods_are_properly_parsed() { @@ -75,6 +97,12 @@ private extension ShippingLabelAccountSettingsMapperTests { return mapAccountSettings(from: "shipping-label-account-settings") } + /// Returns the ShippingLabelAccountSettingsMapper output upon receiving `shipping-label-account-settings-without-data` + /// + func mapLoadShippingLabelAccountSettingsWithoutDataEnvelope() -> ShippingLabelAccountSettings? { + return mapAccountSettings(from: "shipping-label-account-settings-without-data") + } + /// Returns the ShippingLabelAccountSettingsMapper output upon receiving `shipping-label-account-settings-no-payment-methods` /// func mapLoadIncompleteShippingLabelAccountSettings() -> ShippingLabelAccountSettings? { diff --git a/Networking/NetworkingTests/Mapper/ShippingLabelCreationEligibilityMapperTests.swift b/Networking/NetworkingTests/Mapper/ShippingLabelCreationEligibilityMapperTests.swift index f4ae514ad28..77b18785e1a 100644 --- a/Networking/NetworkingTests/Mapper/ShippingLabelCreationEligibilityMapperTests.swift +++ b/Networking/NetworkingTests/Mapper/ShippingLabelCreationEligibilityMapperTests.swift @@ -19,6 +19,15 @@ class ShippingLabelCreationEligibilityMapperTests: XCTestCase { XCTAssertEqual(response.reason, nil) } + func test_shipping_label_creation_eligibility_success_is_properly_parsed_when_response_has_no_data_envelope() throws { + // Given + let response = try XCTUnwrap(mapEligibilityResponse(from: "shipping-label-eligibility-success-without-data")) + + // Then + XCTAssertEqual(response.isEligible, true) + XCTAssertEqual(response.reason, nil) + } + func test_shipping_label_creation_eligibility_failure_is_properly_parsed() throws { // Given let response = try XCTUnwrap(mapEligibilityResponse(from: "shipping-label-eligibility-failure")) @@ -27,6 +36,15 @@ class ShippingLabelCreationEligibilityMapperTests: XCTestCase { XCTAssertEqual(response.isEligible, false) XCTAssertEqual(response.reason, "no_selected_payment_method_and_user_cannot_manage_payment_methods") } + + func test_shipping_label_creation_eligibility_failure_is_properly_parsed_when_response_has_no_data_envelope() throws { + // Given + let response = try XCTUnwrap(mapEligibilityResponse(from: "shipping-label-eligibility-failure-without-data")) + + // Then + XCTAssertEqual(response.isEligible, false) + XCTAssertEqual(response.reason, "no_selected_payment_method_and_user_cannot_manage_payment_methods") + } } /// Private Helpers diff --git a/Networking/NetworkingTests/Mapper/ShippingLabelPackagesMapperTests.swift b/Networking/NetworkingTests/Mapper/ShippingLabelPackagesMapperTests.swift index 8ee849e606f..0b2375b795b 100644 --- a/Networking/NetworkingTests/Mapper/ShippingLabelPackagesMapperTests.swift +++ b/Networking/NetworkingTests/Mapper/ShippingLabelPackagesMapperTests.swift @@ -18,6 +18,15 @@ final class ShippingLabelPackagesMapperTests: XCTestCase { XCTAssertTrue(shippingLabelPackages.unactivatedPredefinedOptions.contains(sampleShippingLabelUnactivatedPredefinedOption())) XCTAssertFalse(shippingLabelPackages.unactivatedPredefinedOptions.contains(sampleShippingLabelPredefinedOptions()[1])) } + + /// Verifies that all of the ShippingLabelPackagesResponse Fields are parsed correctly. + /// + func test_ShippingLabelPackages_fields_are_properly_parsed_when_response_has_no_data_envelope() throws { + let shippingLabelPackages = try XCTUnwrap(mapLoadShippingLabelPackagesResponseWithoutDataEnvelope()) + + XCTAssertEqual(shippingLabelPackages.storeOptions, sampleShippingLabelStoreOptions()) + XCTAssertEqual(shippingLabelPackages.customPackages.first?.title, "Small box") + } } /// Private Helpers @@ -33,11 +42,18 @@ private extension ShippingLabelPackagesMapperTests { return try? ShippingLabelPackagesMapper().map(response: response) } - /// Returns the ShippingLabelPackagesMapper output upon receiving `filename` + /// Returns the ShippingLabelPackagesMapper output upon receiving `shipping-label-packages-success` /// func mapLoadShippingLabelPackagesResponse() -> ShippingLabelPackagesResponse? { return mapShippingLabelPackages(from: "shipping-label-packages-success") } + + /// Returns the ShippingLabelPackagesMapper output upon receiving + /// `shipping-label-packages-success-without-data` + /// + func mapLoadShippingLabelPackagesResponseWithoutDataEnvelope() -> ShippingLabelPackagesResponse? { + return mapShippingLabelPackages(from: "shipping-label-packages-success-without-data") + } } private extension ShippingLabelPackagesMapperTests { diff --git a/Networking/NetworkingTests/Mapper/ShippingLabelPurchaseMapperTests.swift b/Networking/NetworkingTests/Mapper/ShippingLabelPurchaseMapperTests.swift index a58c6aa08df..80efc71819d 100644 --- a/Networking/NetworkingTests/Mapper/ShippingLabelPurchaseMapperTests.swift +++ b/Networking/NetworkingTests/Mapper/ShippingLabelPurchaseMapperTests.swift @@ -33,6 +33,29 @@ class ShippingLabelPurchaseMapperTests: XCTestCase { XCTAssertEqual(shippingLabel.productIDs, []) XCTAssertEqual(shippingLabel.productNames, ["Beanie"]) } + + /// Verifies that the Shipping Label Purchase is parsed correctly. + /// + func test_ShippingLabelPurchase_is_properly_parsed_when_response_has_no_data_envelope() { + guard let shippingLabelList = mapLoadShippingLabelPurchaseWithoutDataEnvelope(), + let shippingLabel = shippingLabelList.first else { + XCTFail() + return + } + + XCTAssertEqual(shippingLabel.siteID, sampleSiteID) + XCTAssertEqual(shippingLabel.orderID, sampleOrderID) + XCTAssertEqual(shippingLabel.shippingLabelID, 733) + XCTAssertNil(shippingLabel.carrierID) + XCTAssertEqual(shippingLabel.dateCreated, Date(timeIntervalSince1970: 1584549793.938)) + XCTAssertEqual(shippingLabel.packageName, "Test") + XCTAssertNil(shippingLabel.trackingNumber) + XCTAssertEqual(shippingLabel.serviceName, "USPS - First Class Mail") + XCTAssertEqual(shippingLabel.refundableAmount, 0) + XCTAssertEqual(shippingLabel.status, ShippingLabelStatus.purchaseInProgress) + XCTAssertEqual(shippingLabel.productIDs, []) + XCTAssertEqual(shippingLabel.productNames, ["Beanie"]) + } } /// Private Helpers @@ -54,4 +77,10 @@ private extension ShippingLabelPurchaseMapperTests { func mapLoadShippingLabelPurchase() -> [ShippingLabelPurchase]? { return mapShippingLabelPurchase(from: "shipping-label-purchase-success") } + + /// Returns the ShippingLabelPurchaseMapper output upon receiving `shipping-label-purchase-success-without-data` + /// + func mapLoadShippingLabelPurchaseWithoutDataEnvelope() -> [ShippingLabelPurchase]? { + return mapShippingLabelPurchase(from: "shipping-label-purchase-success-without-data") + } } diff --git a/Networking/NetworkingTests/Mapper/ShippingLabelStatusMapperTests.swift b/Networking/NetworkingTests/Mapper/ShippingLabelStatusMapperTests.swift index 8ac8332ed54..f75503ad501 100644 --- a/Networking/NetworkingTests/Mapper/ShippingLabelStatusMapperTests.swift +++ b/Networking/NetworkingTests/Mapper/ShippingLabelStatusMapperTests.swift @@ -47,6 +47,40 @@ class ShippingLabelStatusMapperTests: XCTestCase { XCTAssertEqual(shippingLabel?.productNames, ["WordPress Pennant"]) } + func test_ShippingLabelStatusPollingResponse_is_properly_parsed_for_purchased_label_when_response_has_no_data_envelope() { + // Given + guard let shippingLabelList = mapLoadShippingLabelStatusWithoutDataEnvelope(), + let shippingLabelResponse = shippingLabelList.first else { + XCTFail() + return + } + + // Assert + XCTAssertEqual(shippingLabelResponse.status, .purchased) + + // Then + let shippingLabel = shippingLabelResponse.getPurchasedLabel() + + // Assert + XCTAssertEqual(shippingLabel?.siteID, sampleSiteID) + XCTAssertEqual(shippingLabel?.orderID, sampleOrderID) + XCTAssertEqual(shippingLabel?.shippingLabelID, 1825) + XCTAssertEqual(shippingLabel?.carrierID, "usps") + XCTAssertEqual(shippingLabel?.dateCreated, Date(timeIntervalSince1970: 1623764362.682)) + XCTAssertEqual(shippingLabel?.packageName, "Small Flat Rate Box") + XCTAssertEqual(shippingLabel?.rate, 7.9) + XCTAssertEqual(shippingLabel?.currency, "USD") + XCTAssertEqual(shippingLabel?.trackingNumber, "9405500205309072644962") + XCTAssertEqual(shippingLabel?.serviceName, "USPS - Priority Mail") + XCTAssertEqual(shippingLabel?.refundableAmount, 7.9) + XCTAssertEqual(shippingLabel?.status, ShippingLabelStatus.purchased) + XCTAssertNil(shippingLabel?.refund) + XCTAssertEqual(shippingLabel?.originAddress, ShippingLabelAddress.fake()) + XCTAssertEqual(shippingLabel?.destinationAddress, ShippingLabelAddress.fake()) + XCTAssertEqual(shippingLabel?.productIDs, [89]) + XCTAssertEqual(shippingLabel?.productNames, ["WordPress Pennant"]) + } + /// Verifies that the Shipping Label Status Polling Response is parsed correctly when it receives a pending shipping label purchase. /// func test_ShippingLabelStatusPollingResponse_is_properly_parsed_for_pending_label_purchase() { @@ -81,6 +115,12 @@ private extension ShippingLabelStatusMapperTests { return mapShippingLabelStatus(from: "shipping-label-status-success") } + /// Returns the ShippingLabelStatusMapper output upon receiving `shipping-label-status-success-without-data` + /// + func mapLoadShippingLabelStatusWithoutDataEnvelope() -> [ShippingLabelStatusPollingResponse]? { + return mapShippingLabelStatus(from: "shipping-label-status-success-without-data") + } + /// Returns the ShippingLabelStatusMapper output upon receiving `shipping-label-purchase-success` /// func mapLoadShippingLabelPurchaseStatus() -> [ShippingLabelStatusPollingResponse]? { diff --git a/Networking/NetworkingTests/Responses/order-shipping-labels-without-data.json b/Networking/NetworkingTests/Responses/order-shipping-labels-without-data.json new file mode 100644 index 00000000000..f300fca357a --- /dev/null +++ b/Networking/NetworkingTests/Responses/order-shipping-labels-without-data.json @@ -0,0 +1,95 @@ +{ + "orderId": 3188, + "paperSize": "label", + "formData": { + "is_packed": true, + "selected_packages": { + "default_box": { + "id": "default_box", + "box_id": "not_selected", + "height": 0, + "length": 0, + "weight": 0, + "width": 0, + "items": [ + { + "height": 0, + "product_id": 3013, + "length": 0, + "quantity": 1, + "weight": 0, + "width": 0, + "name": "#3013 - Password protected!", + "url": "https://funtestingusa.wpcomstaging.com/wp-admin/post.php?post=3013&action=edit", + "description": "Password protected secret", + "hs_tariff_number": "", + "origin_country": "US", + "value": 200 + } + ] + } + }, + "origin": { + "company": "fun testing", + "name": "Woo seller", + "phone": "6501234567", + "country": "US", + "state": "CA", + "address": "9999 19TH AVE", + "address_2": "", + "city": "SAN FRANCISCO", + "postcode": "94121-2303" + }, + "destination": { + "company": "", + "address_2": "", + "city": "Taipei", + "state": "Taiwan", + "postcode": "100", + "country": "TW", + "phone": "1650345689", + "name": "Woo buyer", + "address": "No 70 RA St" + }, + "origin_normalized": true, + "destination_normalized": true, + "rates": { + "selected": {} + }, + "order_id": 3188 + }, + "labelsData": [ + { + "label_id": 1149, + "tracking": "CM199912222US", + "refundable_amount": 58.81, + "created": 1603716274809, + "carrier_id": "usps", + "service_name": "USPS - Priority Mail International", + "status": "PURCHASED", + "commercial_invoice_url": "https://woocommerce.com", + "package_name": "box", + "product_names": [ + "Password protected!" + ], + "product_ids": [ + 3013 + ], + "receipt_item_id": 24448314, + "created_date": 1603716279000, + "main_receipt_id": 19879722, + "rate": 58.81, + "currency": "USD", + "expiry_date": 1619268278000, + "label_cached": 1603716284000, + } + ], + "storeOptions": { + "currency_symbol": "$", + "dimension_unit": "in", + "weight_unit": "kg", + "origin_country": "US" + }, + "canChangeCountries": true, + "success": true +} diff --git a/Networking/NetworkingTests/Responses/shipping-label-account-settings-without-data.json b/Networking/NetworkingTests/Responses/shipping-label-account-settings-without-data.json new file mode 100644 index 00000000000..befa83bd6c4 --- /dev/null +++ b/Networking/NetworkingTests/Responses/shipping-label-account-settings-without-data.json @@ -0,0 +1,38 @@ +{ + "success": true, + "storeOptions": { + "currency_symbol": "$", + "dimension_unit": "in", + "weight_unit": "lbs", + "origin_country": "US" + }, + "formData": { + "selected_payment_method_id": 11743265, + "enabled": true, + "email_receipts": true, + "paper_size": "label" + }, + "formMeta": { + "can_manage_payments": true, + "can_edit_settings": true, + "master_user_name": "Example User", + "master_user_login": "admin", + "master_user_wpcom_login": "apiexamples", + "master_user_email": "example@example.com", + "payment_methods": [ + { + "payment_method_id": 11743265, + "name": "Example User", + "card_type": "visa", + "card_digits": "4242", + "expiry": "2030-12-31" + } + ], + "warnings": { + "payment_methods": false + } + }, + "userMeta": { + "last_box_id": "small_flat_box" + } +} diff --git a/Networking/NetworkingTests/Responses/shipping-label-eligibility-failure-without-data.json b/Networking/NetworkingTests/Responses/shipping-label-eligibility-failure-without-data.json new file mode 100644 index 00000000000..2a50d3253ea --- /dev/null +++ b/Networking/NetworkingTests/Responses/shipping-label-eligibility-failure-without-data.json @@ -0,0 +1,4 @@ +{ + "is_eligible": false, + "reason": "no_selected_payment_method_and_user_cannot_manage_payment_methods" +} diff --git a/Networking/NetworkingTests/Responses/shipping-label-eligibility-success-without-data.json b/Networking/NetworkingTests/Responses/shipping-label-eligibility-success-without-data.json new file mode 100644 index 00000000000..bdb2ae08c38 --- /dev/null +++ b/Networking/NetworkingTests/Responses/shipping-label-eligibility-success-without-data.json @@ -0,0 +1,3 @@ +{ + "is_eligible": true +} diff --git a/Networking/NetworkingTests/Responses/shipping-label-packages-success-without-data.json b/Networking/NetworkingTests/Responses/shipping-label-packages-success-without-data.json new file mode 100644 index 00000000000..c8dc4623e7c --- /dev/null +++ b/Networking/NetworkingTests/Responses/shipping-label-packages-success-without-data.json @@ -0,0 +1,217 @@ +{ + "success": true, + "storeOptions": { + "currency_symbol": "$", + "dimension_unit": "cm", + "weight_unit": "kg", + "origin_country": "US" + }, + "formSchema": { + "custom": { + "type": "array", + "title": "Box Sizes", + "description": "Items will be packed into these boxes based on item dimensions and volume. Outer dimensions will be passed to the delivery service, whereas inner dimensions will be used for packing. Items not fitting into boxes will be packed individually.", + "default": [], + "items": { + "type": "object", + "title": "Box", + "required": [ + "name", + "inner_dimensions", + "box_weight", + "max_weight" + ], + "properties": { + "name": { + "type": "string", + "title": "Name" + }, + "is_user_defined": { + "type": "boolean" + }, + "inner_dimensions": { + "type": "string", + "title": "Inner Dimensions (L x W x H)", + "pattern": "^(\\d+|(?:\\d*\\.\\d+)) x (\\d+|(?:\\d*\\.\\d+)) x (\\d+|(?:\\d*\\.\\d+))$" + }, + "outer_dimensions": { + "type": "string", + "title": "Outer Dimensions (L x W x H)", + "pattern": "^(\\d+|(?:\\d*\\.\\d+)) x (\\d+|(?:\\d*\\.\\d+)) x (\\d+|(?:\\d*\\.\\d+))$" + }, + "box_weight": { + "type": "number", + "title": "Weight of Box (lbs)" + }, + "max_weight": { + "type": "number", + "title": "Max Weight (lbs)" + }, + "is_letter": { + "type": "boolean", + "title": "Letter" + } + } + } + }, + "predefined": { + "usps": { + "pri_flat_boxes": { + "title": "USPS Priority Mail Flat Rate Boxes", + "definitions": [ + { + "inner_dimensions": "21.91 x 13.65 x 4.13", + "outer_dimensions": "21.91 x 13.65 x 4.13", + "box_weight": 0, + "is_flat_rate": true, + "id": "small_flat_box", + "name": "Small Flat Rate Box", + "dimensions": "21.91 x 13.65 x 4.13", + "max_weight": 31.75, + "is_letter": false, + "group_id": "pri_flat_boxes", + "can_ship_international": true + } + ] + }, + "pri_envelopes": { + "title": "USPS Priority Mail Flat Rate Envelopes", + "definitions": [ + { + "inner_dimensions": "31.75 x 24.13 x 1.27", + "outer_dimensions": "31.75 x 24.13 x 1.27", + "box_weight": 0, + "is_flat_rate": true, + "id": "flat_envelope", + "name": "Flat Rate Envelope", + "dimensions": [ + "31.75 x 24.13 x 1.27" + ], + "max_weight": 31.75, + "is_letter": true, + "group_id": "pri_envelopes", + "can_ship_international": true + } + ] + }, + "pri_boxes": { + "title": "USPS Priority Mail Boxes", + "definitions": [ + { + "inner_dimensions": "95.72 x 15.56 x 12.86", + "outer_dimensions": "95.72 x 15.56 x 12.86", + "box_weight": 0, + "is_flat_rate": false, + "id": "medium_tube", + "name": "Priority Mail Medium Tube", + "dimensions": "95.72 x 15.56 x 12.86", + "max_weight": 31.75, + "is_letter": false, + "service_group_ids": [ + "priority", + "priority_international" + ], + "group_id": "pri_boxes", + "can_ship_international": true + } + ] + }, + "pri_express_envelopes": { + "title": "USPS Priority Mail Express Flat Rate Envelopes", + "definitions": [ + { + "inner_dimensions": "31.75 x 24.13 x 1.27", + "outer_dimensions": "31.75 x 24.13 x 1.27", + "box_weight": 0, + "is_flat_rate": true, + "id": "express_flat_envelope", + "name": "Flat Rate Envelope", + "dimensions": [ + "31.75 x 24.13 x 1.27" + ], + "max_weight": 31.75, + "is_letter": true, + "group_id": "pri_express_envelopes", + "can_ship_international": true + } + ] + }, + "pri_express_boxes": { + "title": "USPS Priority Mail Express Boxes", + "definitions": [ + { + "inner_dimensions": "38.73 x 31.43 x 7.62", + "outer_dimensions": "39.69 x 31.59 x 7.94", + "box_weight": 0, + "is_flat_rate": false, + "id": "express_box", + "name": "Priority Mail Express Box", + "dimensions": { + "inner": "38.73 x 31.43 x 7.62", + "outer": "39.69 x 31.59 x 7.94" + }, + "max_weight": 31.75, + "is_letter": false, + "service_group_ids": [ + "priority_exp", + "priority_express_international" + ], + "group_id": "pri_express_boxes", + "can_ship_international": true + } + ] + }, + "pri_regional_boxes": { + "title": "USPS Priority Mail Regional Rate Boxes", + "definitions": [ + { + "inner_dimensions": "25.72 x 18.1 x 12.7", + "outer_dimensions": "25.72 x 18.1 x 12.7", + "box_weight": 0, + "is_flat_rate": true, + "id": "regional_a1", + "name": "Regional Rate Box A1", + "dimensions": "25.72 x 18.1 x 12.7", + "max_weight": 6.8, + "is_letter": false, + "group_id": "pri_regional_boxes", + "can_ship_international": false + } + ] + } + }, + "dhlexpress": { + "domestic_and_international": { + "title": "DHL Express", + "definitions": [ + { + "inner_dimensions": "24.89 x 30.48 x 2.54", + "outer_dimensions": "24.89 x 30.48 x 2.54", + "box_weight": 0, + "is_flat_rate": false, + "id": "SmallPaddedPouch", + "name": "Small Padded Pouch", + "dimensions": "24.89 x 30.48 x 2.54", + "max_weight": 45.36, + "is_letter": true, + "group_id": "domestic_and_international", + "can_ship_international": true + } + ] + } + } + } + }, + "formData": { + "custom": [ + { + "inner_dimensions": "12 x 12 x 4", + "is_user_defined": true, + "max_weight": 0, + "name": "Small box", + "box_weight": 1.4 + } + ], + "predefined": [] + } +} diff --git a/Networking/NetworkingTests/Responses/shipping-label-purchase-success-without-data.json b/Networking/NetworkingTests/Responses/shipping-label-purchase-success-without-data.json new file mode 100644 index 00000000000..0d2762452ba --- /dev/null +++ b/Networking/NetworkingTests/Responses/shipping-label-purchase-success-without-data.json @@ -0,0 +1,14 @@ +{ + "labels": [{ + "label_id": 733, + "tracking": null, + "refundable_amount": 0, + "created": 1584549793938, + "carrier_id": null, + "service_name": "USPS - First Class Mail", + "status": "PURCHASE_IN_PROGRESS", + "package_name": "Test", + "product_names": ["Beanie"] + }], + "success": true +} diff --git a/Networking/NetworkingTests/Responses/shipping-label-status-success-without-data.json b/Networking/NetworkingTests/Responses/shipping-label-status-success-without-data.json new file mode 100644 index 00000000000..69aa9a1bd0d --- /dev/null +++ b/Networking/NetworkingTests/Responses/shipping-label-status-success-without-data.json @@ -0,0 +1,23 @@ +{ + "success":true, + "labels":[{ + "label_id": 1825, + "tracking": "9405500205309072644962", + "refundable_amount": 7.9, + "created": 1623764362682, + "carrier_id": "usps", + "service_name": "USPS - Priority Mail", + "status": "PURCHASED", + "commercial_invoice_url": null, + "package_name": "Small Flat Rate Box", + "is_letter": false, + "product_names": ["WordPress Pennant"], + "product_ids": [89], + "receipt_item_id": 24601924, + "created_date": 1623764367000, + "expiry_date": 1639316366000, + "main_receipt_id": 19991879, + "rate": 7.9, + "currency": "USD" + }] +}