Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
Ignore never-started subscriptions when detecting a first-time customer
Paulo Castellano2c1cd4ec6100
diff --git a/app/Support/Billing/FirstMonthCheckoutDiscount.php b/app/Support/Billing/FirstMonthCheckoutDiscount.phpindex aec286b73..2fba2131c 100644--- a/app/Support/Billing/FirstMonthCheckoutDiscount.php+++ b/app/Support/Billing/FirstMonthCheckoutDiscount.php@@ -7,6 +7,7 @@ namespace App\Support\Billing;use App\Models\Account;use Laravel\Cashier\SubscriptionBuilder;use RuntimeException;+use Stripe\Subscription as StripeSubscription;final class FirstMonthCheckoutDiscount{@@ -44,7 +45,9 @@ final class FirstMonthCheckoutDiscount* customer checking out a single workspace: the fixed `amount_off` is only* correct for a quantity of one, and the $1 offer is for first-time signups* — not a returning account re-subscribing with workspaces it kept from a- * lapsed subscription.+ * lapsed subscription. A subscription that never left `incomplete` never+ * became real, so a new customer retrying after a failed first attempt+ * still qualifies; any started subscription (even canceled) does not.*/private static function qualifiesForPaidFirstMonth(Account $account): bool{@@ -53,6 +56,11 @@ final class FirstMonthCheckoutDiscount}return $account->workspaces()->count() === 1- && ! $account->subscriptions()->exists();+ && ! $account->subscriptions()+ ->whereNotIn('stripe_status', [+ StripeSubscription::STATUS_INCOMPLETE,+ StripeSubscription::STATUS_INCOMPLETE_EXPIRED,+ ])+ ->exists();}}diff --git a/tests/Unit/Support/Billing/FirstMonthCheckoutDiscountTest.php b/tests/Unit/Support/Billing/FirstMonthCheckoutDiscountTest.phpindex c7f3cd347..86d048ce7 100644--- a/tests/Unit/Support/Billing/FirstMonthCheckoutDiscountTest.php+++ b/tests/Unit/Support/Billing/FirstMonthCheckoutDiscountTest.php@@ -24,12 +24,12 @@ function firstMonthSubscription(Account $account): SubscriptionBuilderreturn $account->newSubscription(Account::SUBSCRIPTION_NAME, 'price_monthly_test');}-function givePriorSubscription(Account $account): void+function givePriorSubscription(Account $account, string $status = 'canceled'): void{$account->subscriptions()->create(['type' => Account::SUBSCRIPTION_NAME,'stripe_id' => 'sub_'.fake()->uuid(),- 'stripe_status' => 'canceled',+ 'stripe_status' => $status,'stripe_price' => 'price_monthly_test',]);}@@ -69,7 +69,7 @@ test('skips the coupon when more than one workspace is billed', function () {->and($subscription->couponId)->toBeNull();});-test('skips the coupon when the account has subscribed before', function () {+test('skips the coupon when the account has a prior canceled subscription', function () {Workspace::factory()->create(['account_id' => $this->account->id]);givePriorSubscription($this->account);@@ -81,6 +81,18 @@ test('skips the coupon when the account has subscribed before', function () {->and($subscription->couponId)->toBeNull();});+test('still applies the coupon when the only prior subscription never left incomplete', function () {+ Workspace::factory()->create(['account_id' => $this->account->id]);+ givePriorSubscription($this->account, 'incomplete_expired');++ $subscription = firstMonthSubscription($this->account);++ FirstMonthCheckoutDiscount::apply($subscription, $this->account);++ expect($subscription->couponId)->toBe('TRIAL1USD')+ ->and($subscription->allowPromotionCodes)->toBeFalse();+});+test('throws instead of charging full price when a qualifying checkout has no coupon', function () {config(['cashier.first_month_coupon_id' => '']);Workspace::factory()->create(['account_id' => $this->account->id]);