feat(rest/python): implement cart capability and discount extension - #159
Open
damaz91 wants to merge 11 commits into
Open
feat(rest/python): implement cart capability and discount extension#159damaz91 wants to merge 11 commits into
damaz91 wants to merge 11 commits into
Conversation
…o payment handlers)
…pability extends cart
…h default handlers
# Conflicts: # rest/python/server/services/checkout_service.py
carolinerg1
approved these changes
Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implement the Cart capability (
dev.ucp.shopping.cart) and the Cart Discount extension (dev.ucp.shopping.discount) in the Python REST sample server.Key changes:
CartServicefor managing cart lifecycle (create, get, update, cancel) and calculating estimated totals.models.pywithUnifiedCart,UnifiedCartCreateRequest, andUnifiedCartUpdateRequestto support the discount extension fields on cart.cart_test.pycovering cart CRUD operations and discount application.CheckoutService: inherits all cart data (line items, buyer, context, signals, attribution, and discounts) and deletes the cart session upon successful checkout completion.cart_id.UnifiedCheckoutCreateRequest(models.py) to makeline_itemsoptional, and added a model validator enforcing that eithercart_idorline_itemsis provided. This allows clients to convert by sending only thecart_idas per the UCP specification.CheckoutService.create_checkoutto handle missing optional fields safely.simple_happy_path_client.pyto execute the full Cart-to-Checkout flow, verifying the conversion with a minimal payload.idfield for new line items during updates, ensuring it only sends known IDs or leaves them unset, conforming to UCP specifications.discovery_profile.jsonto expose the cart capability and advertise that thedev.ucp.shopping.discountcapability extends bothcheckoutandcart.ucp.payment_handlersin the checkout response (services/checkout_service.py) with default supported handlers loaded from the discovery profile via a new cached helper inconfig.py. This ensures full compliance with the required fields in the response schema._recalculate_totalsto_enrich_and_recalculatein bothcart_service.pyandcheckout_service.pyto clarify that the method performs product details enrichment from the database (like updating titles and prices) before computing totals.db.pyby using.as_string()on the JSON index to avoid quote mismatch during cart lookup.Category (Required)
ucp-schematool (resolver, linter, validator). (Requires Maintainer approval)Related Issues
Fixes #134
Checklist
!for breaking changes).