Skip to content

fix(insurance): read insurance limits from the flat capabilities format - #511

Open
FreekVR wants to merge 3 commits into
mainfrom
fix/INT-1697-insurance-flat-capabilities
Open

fix(insurance): read insurance limits from the flat capabilities format#511
FreekVR wants to merge 3 commits into
mainfrom
fix/INT-1697-insurance-flat-capabilities

Conversation

@FreekVR

@FreekVR FreekVR commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

reads insurance limits from the flat capabilities format instead of the nested wrapper the API is removing.

The MyParcel API is dropping the old nested wrapper around insurance limits from the capabilities and contract definitions responses (Core API story SB-2770). The PDK read the limits through that wrapper, so insurance would have broken in the webshops the moment it disappeared.

Insurance limits now come from the flat min, max and default fields. Each limit stands on its own: no minimum means there is no floor, no maximum means the carrier sets no ceiling so a requested amount is kept as-is, and no default falls back to the minimum. For the carrier settings the "insure up to" dropdown needs a maximum to list amounts against, so without one it stays empty and logs a warning instead. Previously any missing limit was a fatal error, so this is also a crash fix for stored carrier data that predates the flat fields.

The API still sends both formats until after this ships. So that nothing starts depending on the old one again, the PDK now drops it as capabilities come in, which means stored carrier data and the admin only ever see the flat fields. That part is temporary and can go once the SDK is regenerated without the wrapper (INT-1696).

Note on ordering: this must be released before SB-2770 deploys, and the SDK must not be regenerated until the plugin releases are out. Plugin installs resolve ^11.0.0-beta.28, so an SDK without the wrapper would hand an older PDK a model with no getInsuredAmount() and fatal before shops can update. The existing SDK floor already has the flat fields, so nothing needed bumping here.

Follow-ups in the same story: the admin still reads the nested shape in JS-PDK, and both plugins need a migration that refreshes stored carrier data.

Resolves INT-1697
Part of INT-1695

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 29, 2026 08:39
@FreekVR
FreekVR requested a review from a team as a code owner July 29, 2026 08:39
@github-project-automation github-project-automation Bot moved this to Todo in PDK Jul 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the PDK’s insurance handling to consume the newer “flat” insurance bounds (min/max/default) from Core API capabilities/contract definitions and to actively strip the deprecated nested insuredAmount wrapper so downstream storage/admin payloads don’t rely on it.

Changes:

  • Strip deprecated nested insurance wrapper (insured_amount) from capabilities and contract definitions responses on ingest.
  • Update insurance tier/validation logic to use flat bounds and handle missing bounds (notably missing max) without fatal errors.
  • Update/extend unit tests and snapshots to reflect the flattened insurance shape.

Reviewed changes

Copilot reviewed 38 out of 38 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/SdkApi/Service/CoreApi/Shipment/CapabilitiesService.php Drops deprecated nested insurance wrapper from incoming SDK models before filtering/serialization.
src/Carrier/Service/CarrierValidationService.php Builds insurance tier ladders from flat bounds and returns empty results (with warning) when no maximum is available.
src/App/Order/Calculator/General/InsuranceCalculator.php Resolves insurance amounts against flat bounds, supporting absent min/max/default and keeping requested amount when no max is advertised.
tests/Unit/SdkApi/Service/CoreApi/Shipment/CapabilitiesServiceTest.php Adds coverage ensuring nested wrapper is removed and flat bounds remain for capabilities and contract definitions.
tests/Unit/Carrier/Service/CarrierValidationServiceTest.php Adds coverage for carriers advertising insurance without bounds (empty ladder).
tests/Unit/Base/Model/SdkBackedModelTest.php Updates hydration expectations to use flat insurance bounds instead of nested wrapper.
tests/Unit/App/Order/Calculator/General/InsuranceCalculatorTest.php Adds regression coverage for missing insurance bounds (no max) keeping requested amount.
tests/Unit/App/Action/Backend/Account/UpdateAccountActionTest.php Updates assertions to expect insuredAmount to be absent/null and flat bounds present.
tests/SdkApi/Response/ExampleContractDefinitionsResponse.php Adjusts example response fixture to include flat bounds (while still showing API’s current dual-format payload).
tests/factories/Carrier/Model/CarrierFactory.php Updates carrier factory helpers to populate flat insurance bounds.
tests/Bootstrap/MockCarrierCapabilitiesRepository.php Updates mocked capability generation to merge flat insurance bounds.
tests/__snapshots__/ShipmentTest__it_returns_empty_fulfilment_shipment_when_no_pdk_shipment_is_passed__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/ShipmentTest__it_creates_fulfilment_shipment_from_pdk_shipment_with_data_set_shipment_with_all_options__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/ShipmentTest__it_creates_fulfilment_shipment_from_pdk_shipment_with_data_set_empty_shipment__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/SaveOrderTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_order_with_pickup__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/SaveOrderTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_order_containing_many_attributes__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/QueryTest__it_creates_shipment_collection_from_queried_data_with_data_set_shipment_with_pickup__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/QueryTest__it_creates_shipment_collection_from_queried_data_with_data_set_shipment_with_drop-off_point__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/QueryTest__it_creates_shipment_collection_from_queried_data_with_data_set_shipment_with_contract__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/QueryTest__it_creates_shipment_collection_from_queried_data_with_data_set_normal_shipment__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/QueryTest__it_creates_order_collection_from_queried_data__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/PostOrdersTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_one_order_with_pickup__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/PostOrdersTest__it_creates_a_valid_order_collection_from_api_data_with_data_set_one_order_containing_many_attributes__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/PdkOrderTest__it_creates_pdk_order_from_fulfilment_order_with_data_set_one_order_with_pickup__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/PdkOrderTest__it_creates_pdk_order_from_fulfilment_order_with_data_set_one_order_containing_many_attributes__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_without_shipments__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_order_with_shipments__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/OrderTest__it_creates_fulfilment_order_from_pdk_order_with_data_set_empty_order__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/FrontendRenderServiceTest__it_renders_component_with_data_set_order_list_column__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/FrontendRenderServiceTest__it_renders_component_with_data_set_order_box__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/FrontendRenderServiceTest__it_renders_component_with_data_set_init_script__1.json Snapshot updated for flattened insurance bounds (and endpoint ordering in rendered payload).
tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_simple_orders__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_no_return_capabilities__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/ExportReturnActionTest__it_exports_return_with_data_set_insurance__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/CreateReturnShipmentsTest__it_creates_return_shipment_with_data_set_simple_domestic_shipment__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/ContextServiceTest__it_gets_context_data_with_data_set_single_order__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/ContextServiceTest__it_gets_context_data_with_data_set_multiple_orders__1.json Snapshot updated to reflect flattened insurance bounds.
tests/__snapshots__/AccountTest__it_creates_storable_array__1.json Snapshot updated to reflect flattened insurance bounds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Carrier/Service/CarrierValidationService.php
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.31%. Comparing base (393ad70) to head (dc03ad2).

Files with missing lines Patch % Lines
...p/Order/Calculator/General/InsuranceCalculator.php 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main     #511   +/-   ##
=========================================
  Coverage     94.31%   94.31%           
- Complexity     2419     2433   +14     
=========================================
  Files           352      352           
  Lines          7738     7757   +19     
=========================================
+ Hits           7298     7316   +18     
- Misses          440      441    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/App/Order/Calculator/General/InsuranceCalculator.php Outdated
@github-project-automation github-project-automation Bot moved this from Todo to Needs work in PDK Aug 4, 2026
@myparcel-bot myparcel-bot Bot added the changes requested (Auto) label Aug 4, 2026
@myparcel-bot
myparcel-bot Bot force-pushed the fix/INT-1697-insurance-flat-capabilities branch 5 times, most recently from e754b3a to 5f2cf7e Compare August 6, 2026 11:18
FreekVR added a commit to myparcelnl/prestashop that referenced this pull request Aug 6, 2026
4.7.0 is the first release carrying markFailed(), which the carrier refresh
migration calls. The flat insurance format is not in it yet, so the nested
wrapper test stays red until myparcelnl/pdk#511 ships.

Part of INT-1695

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
FreekVR added a commit to myparcelnl/woocommerce that referenced this pull request Aug 6, 2026
4.7.0 is the first release carrying markFailed(), which the carrier refresh
migration calls. The flat insurance format is not in it yet, so the nested
wrapper test stays red until myparcelnl/pdk#511 ships.

Part of INT-1695

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-project-automation github-project-automation Bot moved this from Needs work to Testing in PDK Aug 6, 2026
@myparcel-bot myparcel-bot Bot added approved (Auto) and removed changes requested (Auto) labels Aug 6, 2026
NabDevs and others added 2 commits August 6, 2026 16:08
* Guard carrier settings

* test: clean carrier guard

* fix: validate carrier entries

* fix: ignore malformed carrier settings

* refactor: simplify carrier settings guard
The MyParcel API is dropping the old nested wrapper around insurance limits from the capabilities and contract definitions responses. The PDK read the limits through that wrapper, so insurance would have broken in the webshops the moment it disappeared.

Insurance limits now come from the flat min, max and default fields. Each limit stands on its own: no minimum means there is no floor, no maximum means the carrier sets no ceiling so a requested amount is kept as-is, and no default falls back to the minimum. For the carrier settings the "insure up to" dropdown needs a maximum to list amounts against, so without one it stays empty and logs a warning instead.

The API still sends both formats until after this ships. So that nothing starts depending on the old one again, the PDK now drops it as capabilities come in, which means stored carrier data and the admin only ever see the flat fields. That part is temporary and can go once the SDK is regenerated without the wrapper.

Resolves INT-1697

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The old note said the "insure up to" setting bounds a carrier without a maximum.
It does cap the amount, but it defaults to 0 when unset, so the result lands on
the carrier minimum instead.

Also records why the insurance fields are dropped when there is no tier ladder:
the fields are tier dropdowns, so a carrier without a maximum has nothing to
render, and that case does not occur in practice.

Resolves INT-1697

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@myparcel-bot
myparcel-bot Bot force-pushed the fix/INT-1697-insurance-flat-capabilities branch from 80f1cba to dc03ad2 Compare August 6, 2026 14:18
myparcel-bot Bot pushed a commit to myparcelnl/woocommerce that referenced this pull request Aug 7, 2026
4.7.0 is the first release carrying markFailed(), which the carrier refresh
migration calls. The flat insurance format is not in it yet, so the nested
wrapper test stays red until myparcelnl/pdk#511 ships.

Part of INT-1695

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
myparcel-bot Bot pushed a commit to myparcelnl/woocommerce that referenced this pull request Aug 7, 2026
4.7.0 is the first release carrying markFailed(), which the carrier refresh
migration calls. The flat insurance format is not in it yet, so the nested
wrapper test stays red until myparcelnl/pdk#511 ships.

Part of INT-1695

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
myparcel-bot Bot pushed a commit to myparcelnl/woocommerce that referenced this pull request Aug 7, 2026
4.7.0 is the first release carrying markFailed(), which the carrier refresh
migration calls. The flat insurance format is not in it yet, so the nested
wrapper test stays red until myparcelnl/pdk#511 ships.

Part of INT-1695

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved (Auto)

Development

Successfully merging this pull request may close these issues.

5 participants