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.