Skip to main content

SubscriberBuyupRepository

\Benecaster\Membership\SubscriberBuyupRepository

Class Premium

Data access for benecaster_subscriber_buyups, the buy-up grants. A row counts as a live grant while its status is active and current_period_end is in the future. A row set to cancel at period end stays active, and keeps granting access and taking a cap slot, until the period ends.

A grant is one row per subscriber per held buy-up. It is usually a purchase, but it can also be a free grant: from the backfill when a $0 price is saved, a sign-up on that period, or a billing-period switch onto it. Every grant names a Stripe subscription item, including a free one, which carries a $0 item.

Which show a grant unlocks is decided by the buy-up’s own show, not the show_id copied onto the grant. The grant’s copy is used only when the buy-up has no show (unassigned) or no longer exists, so access somebody paid for is kept rather than revoked over a data-repair state.

Methods

Method Visibility Since Description
user_holds_buyup( int $user_id, int $buyup_id, ?int $show_id = null ): bool Public — True when the user has a live grant for the buy-up. With $show_id, the grant must unlock content on that show.
count_active_grants_for_buyup( int $buyup_id ): int Public — Active grants on a buy-up, including those set to cancel at period end. What the subscriber cap is compared against.
find_active_for_user_show( int $user_id, int $show_id ): array Public — The user's live grants on a show.
find_by_stripe_subscription_item_id( string $stripe_subscription_item_id ): ?array Public — The grant carried by a Stripe subscription item, or null. How webhook handlers find the grant for an item.
update_stripe_item( int $id, string $stripe_subscription_item_id ): bool Public — Points a grant at a different Stripe subscription item. It exists for one caller, and without it the column would look immutable. When a billing-period switch lands, Stripe replaces every item on the subscription, buy-ups included. Benecaster uses this to re-point each grant at its new item before Benecaster's buy-up sync sees the event. Otherwise the sync would find the old item missing and cancel a grant the subscriber is still paying for.
mark_cancel_at_period_end( int $id ): bool Public — Records that the subscriber removed the buy-up; access continues until the period ends.
mark_cancelled( int $id ): bool Public — Ends the grant.

Notes

Read methods not listed here (user_holds_any(), find_active_token_types(), find_active_for_user_show_buyup(), find_active_grants_for_buyup(), find_all_active_by_user_show()) and the writers insert() and update_period() are used by the access checks, the purchase path and the webhook listeners.