Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Add stripe_excluded_plans config variable and handle excluded plans in webhook

Andras Bacsai9617000daa72
diff --git a/config/subscription.php b/config/subscription.php
index f646723f81..677689ff1c 100644
--- a/config/subscription.php
+++ b/config/subscription.php
@@ -11,6 +11,7 @@ return [
'stripe_price_id_pro_yearly' => env('STRIPE_PRICE_ID_PRO_YEARLY', null),
'stripe_price_id_ultimate_monthly' => env('STRIPE_PRICE_ID_ULTIMATE_MONTHLY', null),
'stripe_price_id_ultimate_yearly' => env('STRIPE_PRICE_ID_ULTIMATE_YEARLY', null),
+ 'stripe_excluded_plans' => env('STRIPE_EXCLUDED_PLANS', null),
// Paddle
diff --git a/routes/webhooks.php b/routes/webhooks.php
index e6a6a0af90..2d36cf4b78 100644
--- a/routes/webhooks.php
+++ b/routes/webhooks.php
@@ -237,7 +237,7 @@ Route::post('/payments/stripe/events', function () {
try {
$webhookSecret = config('subscription.stripe_webhook_secret');
$signature = request()->header('Stripe-Signature');
-
+ $excludedPlans = config('subscription.stripe_excluded_plans');
$event = \Stripe\Webhook::constructEvent(
request()->getContent(),
$signature,
@@ -253,6 +253,10 @@ Route::post('/payments/stripe/events', function () {
switch ($type) {
case 'checkout.session.completed':
$clientReferenceId = data_get($data, 'client_reference_id');
+ if (is_null($clientReferenceId)) {
+ send_internal_notification('Checkout session completed without client reference id.');
+ break;
+ }
$userId = Str::before($clientReferenceId, ':');
$teamId = Str::after($clientReferenceId, ':');
$subscriptionId = data_get($data, 'subscription');
@@ -288,6 +292,10 @@ Route::post('/payments/stripe/events', function () {
$subscription = Subscription::where('stripe_customer_id', $customerId)->firstOrFail();
}
$planId = data_get($data, 'lines.data.0.plan.id');
+ if (Str::contains($excludedPlans, $planId)) {
+ send_internal_notification('Subscription excluded: ' . $subscription->team->id);
+ break;
+ }
$subscription->update([
'stripe_plan_id' => $planId,
'stripe_invoice_paid' => true,
@@ -308,6 +316,10 @@ Route::post('/payments/stripe/events', function () {
$status = data_get($data, 'status');
$subscriptionId = data_get($data, 'items.data.0.subscription');
$planId = data_get($data, 'items.data.0.plan.id');
+ if (Str::contains($excludedPlans, $planId)) {
+ send_internal_notification('Subscription excluded: ' . $subscription->team->id);
+ break;
+ }
$cancelAtPeriodEnd = data_get($data, 'cancel_at_period_end');
$alreadyCancelAtPeriodEnd = data_get($subscription, 'stripe_cancel_at_period_end');
$feedback = data_get($data, 'cancellation_details.feedback');