feat: add Stripe payment method (SPT charge intent)#97
Open
brendanjryan wants to merge 8 commits intomainfrom
Open
feat: add Stripe payment method (SPT charge intent)#97brendanjryan wants to merge 8 commits intomainfrom
brendanjryan wants to merge 8 commits intomainfrom
Conversation
Adds Stripe payment method support to pympp, mirroring the TypeScript
mppx implementation:
- StripeMethod client with create_token callback for SPT creation
- ChargeIntent server with Stripe SDK client or raw secret_key paths
- Pydantic schemas for ChargeRequest and StripeCredentialPayload
- transform_request hook for injecting networkId/paymentMethodTypes
- MPP analytics metadata on every PaymentIntent (mpp_version, etc.)
- Idempotency key format matching mppx: mppx_{challengeId}_{spt}
- 29 tests covering schemas, client, server, and factory
- Fix Stripe SDK client shape: support both client.v1.payment_intents (stripe-python v8+) and client.payment_intents (legacy/custom) - Add metadata.externalId rejection in create_credential (mppx parity) - Require networkId in challenge.methodDetails (mppx parity) - Use VerificationFailedError instead of VerificationError for proper RFC 9457 Problem Details support - Surface Stripe error details in raw HTTP path instead of generic msg - Remove unused secret_key param from stripe() factory - Fix docstring examples: clients don't need secret keys - Convert OnChallengeParameters to frozen dataclass for consistency - Remove fragile hasattr(__await__) sync/async detection - Pass request body as first positional arg (Stripe SDK convention) - Add tests: raw HTTP path, modern v1 client, async lifecycle, networkId guard, metadata.externalId rejection, factory param removal (44 tests, up from 29)
The StripeClient protocol was too strict for pyright's invariance checking on mutable attributes. Since _resolve_payment_intents() handles duck-type dispatch at runtime, the type annotation can safely be Any.
Consolidates the 3 duplicate DEFAULT_TIMEOUT = 30.0 constants from tempo/intents.py, tempo/_rpc.py, and stripe/intents.py into a single shared mpp._defaults module.
Pay-per-fortune example demonstrating the full SPT flow: - FastAPI server with /api/create-spt proxy and /api/fortune gated endpoint - Headless CLI client using pm_card_visa test card - Mirrors the mppx examples/stripe/ structure
seller_details[network_id] is only for Stripe Business Network accounts. Skip it for standard accounts so the SPT endpoint works universally.
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
Adds Stripe payment method support to pympp, mirroring the mppx TypeScript implementation.
Key design decisions
client.v1.payment_intents(stripe-python v8+) andclient.payment_intents(legacy) via_resolve_payment_intents()httpxPOST toapi.stripe.commppx_{challenge_id}_{spt}— matches TypeScript SDK for cross-SDK consistencympp_version,mpp_is_mpp,mpp_intent, etc. on every PaymentIntenttransform_requesthook: InjectsnetworkIdandpaymentMethodTypesinto challengemethodDetailsVerificationFailedError(RFC 9457 Problem Details) instead of plainVerificationErrorDEFAULT_TIMEOUT: Extracted tompp._defaults— used by both Stripe and Tempo methodsUsage
Files
src/mpp/_defaults.pyDEFAULT_TIMEOUTconstantsrc/mpp/methods/stripe/__init__.pysrc/mpp/methods/stripe/_defaults.pysrc/mpp/methods/stripe/client.pysrc/mpp/methods/stripe/intents.pysrc/mpp/methods/stripe/schemas.pytests/test_stripe.pyexamples/stripe/mppx parity guards
metadata.externalIdin challenge (reserved for credential payload)networkIdinchallenge.methodDetailsTest coverage (44 tests)
Example (verified working)
examples/stripe/contains a pay-per-fortune server + headless client usingpm_card_visa. Tested end-to-end against Stripe test mode: