Skip to main content

StripeSubscriptionManager

\Benecaster\Payment\StripeSubscriptionManager

Class Premium

Thin wrapper over the Stripe Subscriptions and Billing Portal APIs. Ships in feature/built-in-membership-lifecycle. Does not persist Benecaster subscription records, manage feed tokens, or fire Benecaster action hooks — all orchestration lives above this class in NativeBridge and MembershipWebhookHandlers. Add-ons should react to Benecaster lifecycle actions rather than calling the Stripe API directly via this class.

Methods

Method Visibility Since Description
create_subscription( int $show_id, string $customer_id, string $price_id, array $params = [], ?string $idempotency_key = null ): \Stripe\Subscription Public Creates a new Stripe subscription. Derive the idempotency key from show_id, customer_id, and price_id to make retries safe against duplicate charges.
cancel_subscription( int $show_id, string $subscription_id, bool $at_period_end = true ): \Stripe\Subscription Public Cancels a Stripe subscription. Defaults to cancel_at_period_end = true so the subscriber retains access through the current billing period.
update_subscription( int $show_id, string $subscription_id, array $params, ?string $idempotency_key = null ): \Stripe\Subscription Public Updates a subscription. Used for tier switches and billing-period changes. Stripe handles proration automatically per the account's proration settings.
create_billing_portal_session( int $show_id, string $customer_id, string $return_url ): \Stripe\BillingPortal\Session Public Creates a Stripe Billing Portal session for self-service subscription management. The subscriber is redirected to the Stripe-hosted portal and back to $return_url when done.
list_invoices( int $show_id, string $customer_id, int $limit = 24 ): \Stripe\Collection Public Returns the subscriber's invoice list from Stripe. $limit is clamped to [1, 100]. Added in feature/built-in-membership-portal-emails.
create_setup_intent( int $show_id, string $customer_id ): \Stripe\SetupIntent Public Creates an off-session SetupIntent scoped to card payment methods. Used to mount a Stripe Elements PaymentElement for payment method updates.
attach_payment_method( int $show_id, string $customer_id, string $payment_method_id ): void Public Attaches a PaymentMethod to the customer and sets it as invoice_settings.default_payment_method. Always call alongside set_subscription_default_payment_method() to update both layers.
set_subscription_default_payment_method( int $show_id, string $subscription_id, string $payment_method_id ): \Stripe\Subscription Public Pins a PaymentMethod to the subscription so the next renewal uses it without falling back to the customer default.
retrieve_payment_method( int $show_id, string $payment_method_id ): \Stripe\PaymentMethod Public Retrieves a PaymentMethod object (brand, last4, expiry). Used to populate the billing portal UI.
retrieve_customer( int $show_id, string $customer_id ): \Stripe\Customer Public Retrieves a Stripe Customer object. Used when the portal needs to read the customer's current default payment method.