docs(examples): migrate 6 examples to Checkout + canonical 2.0 surface - #48
Merged
Conversation
- api_provider — Checkout per-call billing on 3 rails; discovery probe stays inline (sample rails != real rails). Fail-fast on missing recipient env. - multi_rail_merchant — Checkout + CheckoutGateConfig + mint_recipients hook for Stripe-anchored deposit addresses. simulate_deposit_if_test_mode now gates on tx_hash (skips $0 zero-settle carve-outs which have no PI). - compliance_merchant — CheckoutGateConfig.on_denied composes the canonical denial helpers. Signer-match enforcement is now automatic in the gate. - per_product_policy_merchant — CheckoutGateConfig.per_request_policy returns the matching PolicyBlock from ctx.state; SDK handles hard/soft enforcement. - signed_ucp_merchant — build_signed_ucp_response + build_signed_jwks_response + bootstrap_ucp_signing_key + well_known_preflight_response. payment_handlers compose from the Checkout's rails automatically. - variable_cost_merchant — kept custom 402 emit (variable-cost flows don't fit Checkout); added missing PAYMENT-REQUIRED header + payment-signature alt. Imports tightened across all 6 to use the top-level agentscore_commerce re-exports (CheckoutValidationError, DenialReason, PolicyBlock, AgentScoreGatePolicy, denial helpers). identity_only + stripe_multichain_merchant unchanged (already canonical / Stripe-specific). Verification: ruff check, ty check, pytest all green (1156 passed, 95 percent coverage). Each migrated example imports cleanly under mock env. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Migrates the bulk of the example set from hand-rolled gate + 402 envelope + header parsing to
Checkout(...)orchestration. Each example uses the canonical 2.0 SDK helpers end-to-end.Migrated (6):
api_provider— Checkout per-call billing on 3 rails; discovery probe stays inline (sample rails != real rails). Fail-fast on missing recipient env.multi_rail_merchant— Checkout + CheckoutGateConfig + mint_recipients hook for Stripe-anchored deposit addresses.simulate_deposit_if_test_modegates ontx_hash(skips $0 zero-settle carve-outs which have no PI).compliance_merchant— CheckoutGateConfig.on_denied composes the canonical denial helpers. Signer-match enforcement is automatic in the gate (no handler-side recheck).per_product_policy_merchant— CheckoutGateConfig.per_request_policy returns the matching PolicyBlock fromctx.state; SDK handles hard/soft enforcement.signed_ucp_merchant—build_signed_ucp_response+build_signed_jwks_response+bootstrap_ucp_signing_key+well_known_preflight_response. payment_handlers compose from the Checkout's rails automatically.variable_cost_merchant— kept custom 402 emit (variable-cost flows don't fit Checkout); added missingPAYMENT-REQUIREDheader +payment-signaturealt-header check.Untouched (2):
identity_only— already on canonical surface (AgentScoreGate+get_agentscore_data)stripe_multichain_merchant— Stripe-specific demo, doesn't fit CheckoutImports tightened across all 6 to use the top-level
agentscore_commercere-exports (CheckoutValidationError, DenialReason, PolicyBlock, AgentScoreGatePolicy, denial helpers).Review
Each migrated example was hand-reviewed twice for bugs / gaps / edge cases. Findings + fixes:
Pass 1 (file-by-file functional review):
.get(..., \"\")silently produces empty-recipient rails. Switched toos.environ[...](fail-fast at import).stripe_secret_keywas read inside_on_settledhot path → lifted to module constant.rails={}would break the 402 emit. Added a minimal tempo rail;_on_deniedreturn type widened todict | None._per_request_policysimplified.PAYMENT-REQUIREDheader;_build_402_body(_url)param unused → wired through.Pass 2 (fresh-eye edge-case review):
simulate_deposit_if_test_modewas firing on $0 zero-settle carve-outs (which have signer but no tx). Re-gated ontx_hash.x-paymentORpayment-signature(purl uses the latter); added both checks.SDK-lift candidates surfaced during the review
Not fixed in this PR; flagged for follow-up:
if is_discovery_probe_request: build_discovery_probe_responsebranch beforehandle_fastapi. Could beCheckout(discovery_probe=DiscoveryProbeConfig(...)).pre_validatewrapper that callsshipping_country_allowed+shipping_state_allowedis pure boilerplate. Could auto-fire whenpolicy.allowed_shipping_*is set.simulate_deposit_if_test_modefromon_settled. Checkout could detect a Stripe-PI-derived recipient + auto-fire.build_pricing_block+ stuffs intobody_extras. Could bePricingResult(subtotal_cents=..., tax_cents=..., tax_rate=..., tax_state=...).Checkout.mount_ucp(app, path=...)— every UCP-publishing merchant wires GET ucp + GET jwks + OPTIONS preflight identically.Verification
uv run ruff checkcleanuv run ty check agentscore_commerce examplescleanuv run pytest1156 passed, 4 skipped, coverage 95%🤖 Generated with Claude Code