app.utilities.stripe_event_handler

Stripe webhook event handler for the Mail List Shield application.

This module processes incoming Stripe webhook events for subscription management and credit purchases.

Functions

is_subscription_event(event)

Check if a Stripe event is subscription-related.

is_checkout_completed_event(event)

Check if a Stripe event is a completed checkout.

user_from_stripe_customer_id(customer_id)

Look up a user by their Stripe customer ID.

tier_from_stripe_price_id(price_id)

Look up a subscription tier by its Stripe price ID.

handle_stripe_event(event)

Process a Stripe webhook event.

Module Contents

app.utilities.stripe_event_handler.is_subscription_event(event)[source]

Check if a Stripe event is subscription-related.

Parameters:

event – The Stripe event object.

Returns:

True if the event type starts with ‘customer.subscription’.

Return type:

bool

app.utilities.stripe_event_handler.is_checkout_completed_event(event)[source]

Check if a Stripe event is a completed checkout.

Parameters:

event – The Stripe event object.

Returns:

True if the event type is ‘checkout.session.completed’.

Return type:

bool

app.utilities.stripe_event_handler.user_from_stripe_customer_id(customer_id)[source]

Look up a user by their Stripe customer ID.

Parameters:

customer_id – The Stripe customer ID.

Returns:

The matching user object.

Return type:

Users

Raises:

Exception – If no user is found with the given customer ID.

app.utilities.stripe_event_handler.tier_from_stripe_price_id(price_id)[source]

Look up a subscription tier by its Stripe price ID.

Parameters:

price_id – The Stripe price ID.

Returns:

The matching tier object.

Return type:

Tiers

Raises:

Exception – If no tier is found with the given price ID.

app.utilities.stripe_event_handler.handle_stripe_event(event)[source]

Process a Stripe webhook event.

Handles checkout completions (credit purchases) and subscription events (creation, updates, cancellation, deletion).

Parameters:

event – The Stripe event object to process.