django_program.registration.stripe_client

Stripe client wrapper for per-conference Stripe API operations.

Each conference has its own Stripe account keys, so the client is initialized with a Conference instance and uses the modern stripe.StripeClient pattern (v1 namespace) for all API calls.

Classes

StripeClient

Per-conference Stripe API client.

class django_program.registration.stripe_client.StripeClient[source]

Bases: object

Per-conference Stripe API client.

Wraps stripe.StripeClient (v1 namespace) and binds every call to the conference’s secret key and the globally configured API version.

Parameters:

conference (Conference) – The conference whose Stripe keys will be used.

Raises:

ValueError – If the conference has no Stripe secret key configured.

__init__(conference)[source]

Initialize the client with per-conference Stripe credentials.

Parameters:

conference (Conference) – A Conference instance with stripe_secret_key set.

Raises:

ValueError – If the conference has no Stripe secret key.

get_or_create_customer(user)[source]

Return an existing StripeCustomer or create one via the Stripe API.

Looks up the local StripeCustomer record for this user and conference. If none exists, creates a Stripe customer in the conference’s Stripe account and persists the mapping locally.

Parameters:

user (AbstractBaseUser) – The Django user to map to a Stripe customer.

Return type:

StripeCustomer

Returns:

The StripeCustomer record linking the user to a Stripe customer ID.

create_payment_intent(order, customer_id)[source]

Create a Stripe PaymentIntent for the given order.

Converts the order total to the smallest currency unit and passes the order reference as an idempotency key so retried requests are safe.

Parameters:
  • order (Order) – The order to collect payment for.

  • customer_id (str) – The Stripe customer ID to associate with the intent.

Return type:

str

Returns:

The client_secret string for the frontend payment flow.

capture_payment_intent(intent_id)[source]

Capture a previously authorized PaymentIntent.

Parameters:

intent_id (str) – The Stripe PaymentIntent ID to capture.

Return type:

PaymentIntent

Returns:

The captured stripe.PaymentIntent object.

create_refund(payment_intent_id, amount=None, reason='requested_by_customer')[source]

Create a full or partial refund for a PaymentIntent.

Parameters:
  • payment_intent_id (str) – The Stripe PaymentIntent ID to refund.

  • amount (Decimal | None) – Optional partial refund amount as a Decimal. When None the full PaymentIntent amount is refunded.

  • reason (str) – The Stripe refund reason string (e.g. "requested_by_customer", "duplicate", "fraudulent").

Return type:

Refund

Returns:

The created stripe.Refund object.

create_connection_token()[source]

Create a Stripe Terminal connection token for the JS SDK.

Return type:

str

Returns:

The connection token secret string.

list_readers(*, location=None)[source]

List available Terminal readers, optionally filtered by location.

Parameters:

location (str | None) – Optional Stripe Location ID to filter by.

Return type:

list[Reader]

Returns:

List of reader objects.

create_terminal_payment_intent(*, amount, currency, customer_id=None, metadata=None, description='')[source]

Create a PaymentIntent with capture_method=manual for Terminal pre-auth.

Parameters:
  • amount (Decimal) – Payment amount as Decimal.

  • currency (str) – ISO 4217 currency code.

  • customer_id (str | None) – Optional Stripe customer ID.

  • metadata (dict[str, str] | None) – Optional metadata dict.

  • description (str) – Optional description.

Return type:

PaymentIntent

Returns:

The created PaymentIntent object.

process_terminal_payment(*, reader_id, payment_intent_id)[source]

Send a PaymentIntent to a Terminal reader for card collection.

Parameters:
  • reader_id (str) – The Stripe Terminal Reader ID.

  • payment_intent_id (str) – The PaymentIntent ID to collect.

Return type:

Reader

Returns:

The updated Reader object with action status.

cancel_reader_action(reader_id)[source]

Cancel the current action on a Terminal reader.

Parameters:

reader_id (str) – The Stripe Terminal Reader ID.

Return type:

Reader

Returns:

The updated Reader object.