Skip to main content

Reflex custom component wrapping @stripe/react-stripe-js for Express Checkout and Embedded Checkout

Project description

reflex-stripe

Stripe payment components for Reflex applications

CI PyPI Version Python Versions License Publish


A Reflex custom component library wrapping @stripe/react-stripe-js for seamless Stripe payment integration in Python.

Features

  • Express Checkout — Apple Pay, Google Pay, and Link via ExpressCheckoutElement
  • Embedded Checkout — Full Stripe-hosted checkout form in an iframe
  • Backend State ManagementStripeState handles PaymentIntents and Checkout Sessions
  • API Routes — Auto-registered FastAPI endpoints for client-server communication
  • Type-Safe Config — Pydantic-style Appearance, ExpressCheckoutOptions, and more

Installation

pip install reflex-stripe
uv add reflex-stripe

Quick Start

Express Checkout

Drop in a complete Express Checkout (Apple Pay / Google Pay) with a single provider:

import os
import reflex as rx
import reflex_stripe as stripe

def checkout_page() -> rx.Component:
    return stripe.stripe_provider(
        stripe.ExpressCheckoutBridge.create(
            return_url="/checkout/complete",
        ),
        publishable_key=os.environ["STRIPE_PUBLISHABLE_KEY"],
        secret_key=os.environ["STRIPE_SECRET_KEY"],
        mode="payment",
        amount=1099,
        currency="usd",
    )

Embedded Checkout

Render a full Stripe Checkout form as an embedded iframe:

import os
import reflex as rx
import reflex_stripe as stripe

def checkout_page() -> rx.Component:
    return stripe.embedded_checkout_session(
        publishable_key=os.environ["STRIPE_PUBLISHABLE_KEY"],
        secret_key=os.environ["STRIPE_SECRET_KEY"],
        line_items=[{
            "price_data": {
                "currency": "usd",
                "product_data": {"name": "Pro Plan"},
                "unit_amount": 2000,
            },
            "quantity": 1,
        }],
        return_url="/checkout/complete",
    )

Register API Routes

Register the Stripe backend endpoints on your Reflex app:

app = rx.App()
stripe.register_stripe_api(app)

Architecture

reflex_stripe/
├── base.py              # StripeBase — shared component base class
├── models.py            # Appearance, ExpressCheckoutOptions, ButtonType, etc.
├── stripe_provider.py   # StripeProvider wrapping <Elements> + loadStripe
├── stripe_state.py      # StripeState — PaymentIntent & Checkout Session management
├── express_checkout.py  # ExpressCheckoutElement + JS bridge
└── embedded_checkout.py # EmbeddedCheckoutProvider + EmbeddedCheckout + bridge
Layer Component Purpose
Provider StripeProvider Wraps <Elements> with loadStripe()
Elements ExpressCheckoutElement, EmbeddedCheckout Stripe UI components
Bridges ExpressCheckoutBridge, EmbeddedCheckoutBridge JS glue for event handling
State StripeState Backend payment logic (PaymentIntents, Sessions)
API register_stripe_api() Auto-registers /api/stripe/* endpoints

Environment Variables

Variable Required Description
STRIPE_PUBLISHABLE_KEY Yes Stripe publishable key (pk_test_... or pk_live_...)
STRIPE_SECRET_KEY Yes Stripe secret key (sk_test_... or sk_live_...)

Development

task install    # Install dev deps + pre-commit hooks
task lint       # Run ruff linter
task typecheck  # Run pyright type checker
task test       # Run full test suite
task run        # Run demo app
task run-docs   # Run docs locally

Requirements

  • Python 3.11+
  • Reflex >= 0.8.0
  • Stripe Python SDK >= 12.0.0

Contributing

Contributions welcome. Please run task lint and task test before submitting a PR.

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reflex_stripe-0.1.0.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reflex_stripe-0.1.0-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file reflex_stripe-0.1.0.tar.gz.

File metadata

  • Download URL: reflex_stripe-0.1.0.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for reflex_stripe-0.1.0.tar.gz
Algorithm Hash digest
SHA256 445c0974518b6dd36fbbf6c07953087544b6d7b4a2f347a03c6e05060dfb1d6e
MD5 e190cc36ba285e7d7f68a5b72158899e
BLAKE2b-256 4f77e43a20b2e88c485663c3000dcf10a779bf69dbccf6ede8248737356462cb

See more details on using hashes here.

File details

Details for the file reflex_stripe-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for reflex_stripe-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c2784c47e52a5d100634ca1f60244936743e176aaccd443a303138143fd5838
MD5 6a3ea18c14d7adb6e7c42cceaf6da54a
BLAKE2b-256 ff31e82fa8ad10f34e5c8a1150e76c12512751ab87b422f3d5fa6633ef41de52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page