From 82e212def2f55b755e8df3410479ac865a572b75 Mon Sep 17 00:00:00 2001 From: roble Date: Sat, 7 Nov 2026 21:09:01 +0000 Subject: [PATCH 1/9] fix: push products with an empty description, and stop removing a provider price with a message An emptied rich editor saves

, which Stripe rejected as an empty description. A price pushed after the edit form opened could still be removed there, and the model guard answered with a 500. Co-Authored-By: Claude Opus 5.5 --- .../Resources/Products/Pages/EditProduct.php | 26 +++++++++++++++++++ src/Services/Gateways/StripeGateway.php | 3 ++- tests/Feature/ProductAdminGuardsTest.php | 18 +++++++++++++ tests/Feature/StripeCatalogRequestTest.php | 10 +++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/Filament/Resources/Products/Pages/EditProduct.php b/src/Filament/Resources/Products/Pages/EditProduct.php index 25388bf..7f0851b 100644 --- a/src/Filament/Resources/Products/Pages/EditProduct.php +++ b/src/Filament/Resources/Products/Pages/EditProduct.php @@ -6,6 +6,7 @@ use Filament\Actions\ForceDeleteAction; use Filament\Actions\RestoreAction; use Filament\Actions\ViewAction; +use Filament\Notifications\Notification; use Filament\Resources\Pages\EditRecord; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; @@ -52,6 +53,31 @@ protected function handleRecordUpdate(Model $record, array $data): Model return parent::handleRecordUpdate($record, $data); } + /** + * The form hides delete on a provider's price, but one pushed after the form opened + * still shows it. Stop before the repeater deletes it and the model's guard throws. + */ + protected function beforeSave(): void + { + $kept = collect($this->data['prices'] ?? [])->keys()->map(fn ($key) => (int) str_replace('record-', '', (string) $key)); + + $removed = $this->getRecord()->prices() + ->whereNotNull('provider_price_id') + ->whereNotIn('id', $kept) + ->exists(); + + if ($removed) { + Notification::make() + ->title(__('A price is managed by the provider')) + ->body(__('Archive it there and sync. The form has been reloaded.')) + ->danger() + ->send(); + + $this->fillForm(); + $this->halt(); + } + } + /** * Saved either way: an app may check a key it never declared. The warning catches a typo. * It says "Saved", so it waits for the commit: a listener can still roll the save back. diff --git a/src/Services/Gateways/StripeGateway.php b/src/Services/Gateways/StripeGateway.php index f652e36..8bfda56 100644 --- a/src/Services/Gateways/StripeGateway.php +++ b/src/Services/Gateways/StripeGateway.php @@ -353,7 +353,8 @@ public function createProduct(Product $product): string { return $this->call('create a product', fn () => $this->stripe->products->create(array_filter([ 'name' => $product->name, - 'description' => $product->description ? strip_tags($product->description) : null, + // An emptied editor leaves `

`; Stripe rejects an empty string. + 'description' => trim(strip_tags((string) $product->description)) ?: null, 'active' => $product->is_active, 'metadata' => ['slug' => $product->slug], ], fn ($value) => $value !== null))->id); diff --git a/tests/Feature/ProductAdminGuardsTest.php b/tests/Feature/ProductAdminGuardsTest.php index e30fed5..17d4d24 100644 --- a/tests/Feature/ProductAdminGuardsTest.php +++ b/tests/Feature/ProductAdminGuardsTest.php @@ -60,6 +60,24 @@ public function test_a_product_the_provider_does_not_know_is_still_editable(): v $this->assertSame('Renamed', $product->fresh()->name); } + /** + * A form opened before the price was pushed still offers to remove it. Saving then + * keeps the price, with an error, instead of a 500 from the model's guard. + */ + public function test_removing_a_price_pushed_after_the_form_opened_keeps_it(): void + { + $product = Product::factory()->create(['provider_product_id' => null]); + $price = Price::factory()->create(['product_id' => $product->id, 'provider_price_id' => null]); + + $page = Livewire::test(EditProduct::class, ['record' => $product->getKey()]); + + $price->forceFill(['provider' => 'stripe', 'provider_price_id' => 'price_pushed'])->save(); + + $page->fillForm(['prices' => []])->call('save'); + + $this->assertModelExists($price); + } + public function test_a_gateway_managed_price_keeps_its_amount(): void { $product = Product::factory()->create([ diff --git a/tests/Feature/StripeCatalogRequestTest.php b/tests/Feature/StripeCatalogRequestTest.php index e474535..b8b0942 100644 --- a/tests/Feature/StripeCatalogRequestTest.php +++ b/tests/Feature/StripeCatalogRequestTest.php @@ -62,6 +62,16 @@ protected function tearDown(): void parent::tearDown(); } + /** An emptied rich editor saves `

`; Stripe rejects an empty description outright. */ + public function test_an_empty_description_is_not_sent(): void + { + $product = Product::factory()->create(['description' => '

']); + + $this->gateway()->createProduct($product); + + $this->assertArrayNotHasKey('description', $this->requests[0]['params']); + } + public function test_a_products_features_are_sent_as_stripe_marketing_features(): void { $product = Product::factory()->create([ From 287b167193af8b535c191b6a56822f5521d19088 Mon Sep 17 00:00:00 2001 From: roble Date: Sun, 8 Nov 2026 11:03:45 +0000 Subject: [PATCH 2/9] feat: name what each one-time payment bought, and offer a bought one-off as Buy again Co-Authored-By: Claude Opus 5.5 --- .../saucebase-billing-development/SKILL.md | 2 +- resources/js/react/components/ProductCard.tsx | 14 ++++--- resources/js/react/pages/SettingsBilling.tsx | 31 +++++++++++---- resources/js/types/index.ts | 5 ++- resources/js/vue/components/ProductCard.vue | 8 +++- resources/js/vue/pages/SettingsBilling.vue | 13 ++++++- src/Enums/PlanAction.php | 3 ++ src/Services/PlanActions.php | 38 ++++++++++++++++++- src/Settings/BillingSection.php | 2 + tests/Feature/BillingPanelTest.php | 11 ++++++ tests/Feature/PlanActionsTest.php | 33 ++++++++++++++++ 11 files changed, 142 insertions(+), 18 deletions(-) diff --git a/resources/boost/skills/saucebase-billing-development/SKILL.md b/resources/boost/skills/saucebase-billing-development/SKILL.md index bdb9c66..2ce99ba 100644 --- a/resources/boost/skills/saucebase-billing-development/SKILL.md +++ b/resources/boost/skills/saucebase-billing-development/SKILL.md @@ -148,7 +148,7 @@ A new account takes the buyer's name and email; after that its details change on `PurchaseEligibility::assertCanBuy()` throws the refusal's message; `CheckoutController::create()` calls it before a session exists and `StartCheckout` again for the guest who signed in part-way (the session-reuse return runs first, so a checkout already paid at the provider still completes). It runs before payment, so two checkouts opened at once can both be paid; Stripe's *Limit customers to one subscription* closes that, listed in the README as optional. -**Pricing buttons come from the server.** `PlanActions::for()` sends `priceActions` (per displayed price) and `productActions` (per plan shown without a price). `buy` appears only where eligibility allows; the rest label a refusal — `change`, `later`, `included`, `current`, `unavailable` — plus `contact` for a `cta_url` and, for the Free plan, `signup` (guest), `current` (nothing paid) or `included` (paid plan). The cards only render what they are sent. +**Pricing buttons come from the server.** `PlanActions::for()` sends `priceActions` (per displayed price) and `productActions` (per plan shown without a price). `buy` appears only where eligibility allows (`buy_again` for a one-off the owner already paid for, refunds aside: another call, renewed package updates); the rest label a refusal — `change`, `later`, `included`, `current`, `unavailable` — plus `contact` for a `cta_url` and, for the Free plan, `signup` (guest), `current` (nothing paid) or `included` (paid plan). The cards only render what they are sent. **Lifetime replacing a subscription.** After a Lifetime checkout commits, `endSubscriptionReplacedByLifetime()` cancels the current subscription at period end — only if its plan is the one the Lifetime replaces. It runs on every delivery, since a failed provider call is retried and the retry finds the session already completed. Until the provider accepts the cancellation the subscription shows as renewing; once `cancelled_at` is set the panel says it ends, replaced by lifetime. The app freezes it: `billing.plan.change` 404s and resume is refused (`PurchaseEligibility::isReplacedByLifetime()`). That is app policy — the provider stays the source of truth, and a customer who resumes it in the provider's portal keeps an ordinary subscription. diff --git a/resources/js/react/components/ProductCard.tsx b/resources/js/react/components/ProductCard.tsx index ba94026..fd4fa7c 100644 --- a/resources/js/react/components/ProductCard.tsx +++ b/resources/js/react/components/ProductCard.tsx @@ -47,7 +47,8 @@ export default function ProductCard({ ? 'bg-primary hover:bg-primary/90 focus-visible:outline-primary text-white' : 'text-foreground ring-border hover:bg-foreground/10 ring-1 ring-inset'; - const startsCheckout = action === 'buy' || action === 'trial'; + const startsCheckout = + action === 'buy' || action === 'buy_again' || action === 'trial'; const enabled = startsCheckout || action === 'signup' || action === 'owner_only'; @@ -72,10 +73,12 @@ export default function ProductCard({ } if (startsCheckout && price) { - const auth = page.props.auth as { - user?: unknown; - modal_enabled?: boolean; - } | undefined; + const auth = page.props.auth as + | { + user?: unknown; + modal_enabled?: boolean; + } + | undefined; if (!auth?.user && auth?.modal_enabled) { setIsStartingCheckout(true); @@ -110,6 +113,7 @@ export default function ProductCard({ later: t('Available when your current plan ends'), unavailable: t('Not available'), owner_only: t('Ask an owner'), + buy_again: t('Buy again'), trial: t('Start :days-day free trial', { days: String(product.trial_days ?? 0), }), diff --git a/resources/js/react/pages/SettingsBilling.tsx b/resources/js/react/pages/SettingsBilling.tsx index 594c281..81472fa 100644 --- a/resources/js/react/pages/SettingsBilling.tsx +++ b/resources/js/react/pages/SettingsBilling.tsx @@ -1,7 +1,7 @@ -import { DangerZone, EmptyState } from '@/components/ui/saucebase'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; +import { DangerZone, EmptyState } from '@/components/ui/saucebase'; import { router } from '@inertiajs/react'; import { formatDate } from '@saucebase/core/lib/dates'; import { useDialog } from '@saucebase/react/hooks/useDialog'; @@ -9,7 +9,6 @@ import { useT, useTranslation } from '@saucebase/react/i18n'; import { CreditCard, Loader2 } from 'lucide-react'; import { useEffect, useMemo, useState } from 'react'; import { toast } from 'sonner'; -import PlanFeatures from '../components/PlanFeatures'; import { getIntervalLabel } from '../../lib/intervals'; import { formatMoney } from '../../lib/money'; import type { @@ -19,6 +18,7 @@ import type { PaymentMethod, Subscription, } from '../../types'; +import PlanFeatures from '../components/PlanFeatures'; const longDate: Intl.DateTimeFormatOptions = { year: 'numeric', @@ -193,7 +193,9 @@ export default function SettingsBilling({

{!subscription && lifetimePlans.length ? t('Your plan and payments') - : t('Manage your subscription, payment method, and invoices')} + : t( + 'Manage your subscription, payment method, and invoices', + )}

{/* Lifetime plans are owned for good, alongside any subscription */} @@ -223,7 +225,11 @@ export default function SettingsBilling({ data-testid="lifetime-plan-amount" className="text-foreground font-semibold tabular-nums" > - {formatMoney(plan.amount, plan.currency, locale)} + {formatMoney( + plan.amount, + plan.currency, + locale, + )}

{t('Paid once')} @@ -254,7 +260,10 @@ export default function SettingsBilling({ {subscription ? (

{/* Current plan */} - +

- {subscription.plan_name ?? t('Unknown Plan')} + {subscription.plan_name ?? + t('Unknown Plan')}

{subscription.amount !== null && ( @@ -290,7 +300,8 @@ export default function SettingsBilling({ )} {subscription.interval && ( - {(subscription.interval_count ?? 1) > 1 + {(subscription.interval_count ?? + 1) > 1 ? t('every :count :interval', { count: String( subscription.interval_count, @@ -604,6 +615,9 @@ export default function SettingsBilling({ {t('Date')} + + {t('Item')} + {t('Amount')} @@ -626,6 +640,9 @@ export default function SettingsBilling({ longDate, )} + + {payment.name ?? '—'} + {formatMoney( payment.amount, diff --git a/resources/js/types/index.ts b/resources/js/types/index.ts index 12fa4b7..8058c84 100644 --- a/resources/js/types/index.ts +++ b/resources/js/types/index.ts @@ -26,11 +26,12 @@ export interface Price { /** * What a pricing card's button does, decided on the server (`PlanActions`). * Mirrors the PHP `PlanAction` enum; change one, change the other. `buy`, - * `trial`, `signup`, `change` and `contact` act; `owner_only` explains who can; the rest + * `buy_again`, `trial`, `signup`, `change` and `contact` act; `owner_only` explains who can; the rest * are disabled labels. */ export type PlanAction = | 'buy' + | 'buy_again' | 'signup' | 'change' | 'contact' @@ -116,6 +117,8 @@ export interface LifetimePlan { /** A one-time payment: a lifetime plan's only record, since it has no invoice. */ export interface OneTimePayment { id: number; + /** The plan bought; null once its price is gone. */ + name: string | null; amount: number; currency: string; status: 'succeeded' | 'refunded'; diff --git a/resources/js/vue/components/ProductCard.vue b/resources/js/vue/components/ProductCard.vue index 5ebc321..e96cae8 100644 --- a/resources/js/vue/components/ProductCard.vue +++ b/resources/js/vue/components/ProductCard.vue @@ -30,7 +30,10 @@ const ctaClass = computed(() => ); const startsCheckout = computed( - () => props.action === 'buy' || props.action === 'trial', + () => + props.action === 'buy' || + props.action === 'buy_again' || + props.action === 'trial', ); const enabled = computed( @@ -247,6 +250,9 @@ watch(priceKey, () => { +