Skip to main content

python-getpaid-stripe

License: MIT

Stripe payment processor for the python-getpaid ecosystem, wrapping Stripe Checkout Sessions (payment mode) via the official stripe-python SDK.

Design and rationale live in SPEC.md; research backing in docs/research/.

Key features

  • Hosted checkout — prepare_transaction() creates a payment-mode Checkout Session and returns a redirect URL
  • Webhook handling — signature verification via stripe.Webhook.construct_event over the raw body; semantic mapping where payment_intent.* events are authoritative for money-state
  • Pre-auth / manual capture — charge() (full or partial capture, remainder auto-released) and release_lock(); the first getpaid plugin to exercise core's pre-auth FSM states
  • Refunds — full and multiple partial refunds; status-driven webhook mapping handles late failures and Stripe-generated expiry refunds
  • Radar fraud reviews — review.opened/closed map to core FraudEvents
  • Status polling — fetch_payment_status() PULL flow, doubling as the authorization-expiry backstop
  • Simulator plugin — a local Stripe stand-in for python-getpaid-simulator with a fake hosted checkout, real HMAC webhook signatures, and time-travel ops

Installation

pip install python-getpaid-stripe

With the local simulator plugin:

pip install python-getpaid-stripe[simulator]

Configuration

Setting Type Required Default Notes
api_key str yes — sk_test_… / sk_live_… / rk_…; validated at construction
webhook_secret str yes — whsec_…, per-endpoint, test/live distinct; validated at construction
success_url str template yes — {payment_id} is formatted by the plugin; Stripe's literal {CHECKOUT_SESSION_ID} is passed through
cancel_url str template yes — same semantics
capture_method "automatic" | "manual" no "automatic" per-payment override: prepare_transaction(capture_method="manual")
session_expires_in int minutes (30–1440) no Stripe's 24 h maps to Checkout expires_at
max_network_retries int no 2 safe: the SDK auto-generates idempotency keys

There is no publishable key setting (nothing in a hosted-Checkout flow consumes one) and no sandbox flag: test vs live mode is derived from the API key prefix (processor.is_sandbox). A flag that can contradict the key is a lie waiting to happen.

accepted_currencies is a broad default list of Stripe presentment currencies; availability is per account country — subclass the processor to narrow it.

Webhook endpoint (Stripe Dashboard)

Point a webhook endpoint at your framework adapter's callback URL and enable exactly these events:

checkout.session.completed
checkout.session.expired
payment_intent.amount_capturable_updated
payment_intent.succeeded
payment_intent.payment_failed
payment_intent.canceled
refund.created
refund.updated
refund.failed
review.opened
review.closed

The framework adapter must pass the raw request body to verify_callback(..., raw_body=...) — Stripe signatures are computed over the raw bytes. Only classic v1 snapshot payloads are supported; v2 "thin" events are rejected.

Manual capture (pre-auth)

Opt in per configuration or per payment. The flow:

  1. prepare_transaction(capture_method="manual") — the buyer authorizes; payment_intent.amount_capturable_updated locks the payment (LOCKED).
  2. charge() captures the full locked amount; charge(amount) captures partially and Stripe auto-releases the remainder. Returns async_call=True — the authoritative PAYMENT_CAPTURED arrives via payment_intent.succeeded.
  3. release_lock() cancels the intent and returns the full locked amount; payment_intent.canceled confirms LOCK_RELEASED.

Operator note — authorization expiry: card authorizations are valid for ~7 days (variance: Visa MIT 5 days, some in-person 2, Japan 30). The lock's provider_data["locked_at"] timestamp is stamped when LOCKED is applied, so your application can schedule capture-or-release. There is no reliable expiry webhook; the deterministic detection path is fetch_payment_status() (a canceled manual-capture intent maps to LOCK_RELEASED). Polling cadence belongs to the application — this plugin ships no scheduler. Note that manual capture also narrows the payment methods Stripe offers (cards, Klarna, PayPal yes; ACH, iDEAL no).

Refunds

start_refund() refunds the full captured amount, start_refund(amount) a part of it (multiple partials allowed). The refund id is stored in provider_data["refund_id"] (latest refund only). Failed/canceled refund IDs and their outcomes are retained in separate provider_data["refund_terminal:<refund_id>"] keys. Successful API cancellation also records the canceled ID and sets provider_data["refund_cancel_unconfirmed:<refund_id>"] on the bound payment; core's cancellation flow saves it. Direct processor callers must save that payment themselves. The first failed/canceled webhook for that still-current refund emits REFUND_CANCELLED and clears the flag through its update, so direct callers can complete cancellation. Apply and save the update, including provider data. The original refund_terminal_statuses dictionary remains readable and is not removed. Other late events for recorded terminal IDs are ignored, even with a new event ID or after a retry has started. Independent keys avoid replacing another refund's history when core shallow-merges updates mapped from stale snapshots.

Persist provider data with each payment update; do not clear this history when starting another refund. Adapters must serialize the complete load/map/apply/save and cancellation/retry lifecycle per payment, or provide equivalent conflict detection and revalidation. Independent keys do not prevent lost updates from concurrent saves of entire payment snapshots, or make a stale mapping safe to apply after a newer lifecycle change.

Existing-payment rollout boundary: records without retained terminal IDs are not retrospectively protected. Replaying an already-deduplicated event does not backfill them. Before use (including beta), the operator must establish the applicable existing-user, integration and payment obligations and reconcile the needed terminal identities from retained provider/payment records under serialized writes. This repair does not provide a historical backfill or establish deployment applicability; do not treat a version label as evidence that no obligations exist. Preserve both legacy dictionaries and new keys; older plugin versions do not read the new keys, so a code rollback alone does not preserve the new ordering protection.

A successful status is not treated as permanent: a bank can return funds later (see Stripe refund handling). Refund reason is deliberately not exposed — Stripe's fraudulent value has card-block side effects.

cancel_refund() effectively always returns False for card payments: only refunds in requires_action (bank-transfer-style methods) are API-cancelable; card refunds can only be canceled from the Stripe Dashboard.

Simulator plugin

With the simulator extra installed, python-getpaid-simulator auto-discovers the stripe plugin. Configuration via environment:

SIMULATOR_STRIPE_API_KEY        (default sk_test_sim_stripe_key)
SIMULATOR_STRIPE_WEBHOOK_SECRET (default whsec_sim_stripe_secret)
SIMULATOR_STRIPE_NOTIFY_URL     (webhook delivery target)

Point the processor at the simulator with the internal api_base config key. The fake hosted checkout offers pay / pay-delayed / decline / abandon; POST /sim/stripe/ops/{order_id} forces transitions with no natural actor (expire_session, expire_auth time-travel, settle_delayed / fail_delayed, fail_refund, set_refund_mode, open_review / close_review). Webhooks carry genuine HMAC Stripe-Signature headers plus deliberate ignore-list traffic (charge.*, checkout.session.async_payment_*) so the processor's ignore behavior is exercised under realistic fire.

Development

uv sync --all-extras
uv run pytest
uv run ruff check .
uv run ty check

License

MIT

Metadata

Release files for python-getpaid-stripe 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-getpaid-stripe 0.2.2
File Size Uploaded Provenance Actions
python_getpaid_stripe-0.2.2.tar.gz 168.4 kB Without provenance Details for python_getpaid_stripe-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-getpaid-stripe 0.2.2
File Interpreter ABI Platform Actions
python_getpaid_stripe-0.2.2-py3-none-any.whl Python 3 none any Details for python_getpaid_stripe-0.2.2-py3-none-any.whl

Total release size: 194.3 kB

Release files / python_getpaid_stripe-0.2.2.tar.gz

Download URL python_getpaid_stripe-0.2.2.tar.gz
Size 168.4 kB
Tags Source
SHA-256 checksum
How to use checksums
eb2d7d721ebf7e7730a493f190887cb8b84ee2b03070cd0da9c35d1c71cf9199
BLAKE2b-256 checksum
How to use checksums
c765d5249d9089c08b832cae84bb2025d56a15bdaeef013a25d510e7037a1882
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / python_getpaid_stripe-0.2.2-py3-none-any.whl

Download URL python_getpaid_stripe-0.2.2-py3-none-any.whl
Size 25.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5eda9d4ccd9a01da1a28c121717be6321bf3660695308cbd6dc6f14c3bf8362f
BLAKE2b-256 checksum
How to use checksums
7dc4ec1f7f98c5013a9be7ba45710ecb6cb45762e13d2cdedbdf33ef534d8c17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for python-getpaid-stripe 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page