Skip to main content

BuyupRepository

\Benecaster\Membership\BuyupRepository

Class Premium

Data access for benecaster_buyups, the buy-up definitions. Each buy-up belongs to one show, and its available_to_tiers narrows it to particular tiers on that show (empty means every tier). Methods that answer “what may this subscriber buy?” are scoped to the show in SQL, and a buy-up with show_id = 0 (unassigned) is invisible to every show-scoped read.

Every read carries a prices array, the buy-up’s rows from benecaster_buyup_prices in display order, fetched in one extra query for the whole result set.

price, stripe_price_id_test and stripe_price_id_live are no longer columns. This class still emits those three keys, read from the buy-up’s default price row, and forwards a write of any of them to that row, so callers written before per-cadence pricing keep working. That compatibility surface is temporary, and it has two blind spots. It says nothing about the buy-up’s other cadences. And a buy-up with no price row at all reads as price = 0.0, the same as a genuine free row. Anything that needs to know which cadences exist, or to match a subscriber’s own period, must ask BuyupPriceRepository.

available_from and available_until (the sale window) are stored in UTC and converted here, in the writer. Callers pass site-local times and must not pre-convert, or the value shifts twice and a sale opens hours early or late. Reads return UTC; local_window() converts back for an editor.

Methods

Method Visibility Since Description
insert( array $data ): int Public — Inserts a buy-up and returns its id. show_id is required and must be positive. Window times are site-local.
update( int $id, array $changes ): bool Public — Updates the mutable fields. A price or stripe_price_id_* key is forwarded to the default price row through BuyupPriceRepository::update(), so a price write also clears that row's two Stripe Price IDs. Window times are site-local. show_id is not writable here; see assign_show().
assign_show( int $id, int $show_id ): bool Public — Attaches an unassigned buy-up to a show. The only way show_id changes, used by the unassigned-buy-ups recovery screen.
delete( int $id ): bool Public — Deletes the buy-up and its price rows.
find( int $id ): ?array Public — One buy-up by id, with prices, or null. Not show-scoped.
find_for_show( int $id, int $show_id ): ?array Public — One buy-up by id, only if it belongs to that show.
find_by_token_type( string $token_type, int $show_id ): ?array Public — The show's buy-up issuing a given access token type, or null.
find_by_show( int $show_id ): array Public — Every buy-up on a show, active and inactive.
find_unassigned(): array Public — Buy-ups with show_id = 0.
find_all(): array Public — Every buy-up on the install, including unassigned ones.
find_active_for_show_tiers( int $show_id, array $tier_slugs ): array Public — Active buy-ups on a show that are offered to any of the given tier slugs (or to every tier). What a subscriber on those tiers may be offered.
local_window( array $buyup ): array Public — Static. The buy-up's sale window in site-local time, as { from, until }, each a string or null.

Constants

Name Value Description
LEGACY_CURRENCY 'USD' The currency of a default price row created from a single price written through insert() or update() when the buy-up has none — the compatibility surface, whose price carries no currency. A caller that wants another currency writes a price row with its own currency through BuyupPriceRepository.