{"record":{"id":"ce82b234e4dceefa","repo":"coollabsio/coolify","slug":"subscription-already-exists-for-customer-custom","errorCode":null,"errorMessage":"Subscription already exists for customer: {$customerId}","messagePattern":"Subscription already exists for customer: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"app/Jobs/StripeProcessJob.php","lineNumber":211,"sourceCode":"                        // send_internal_notification('payment_intent.payment_failed, no subscription found in Coolify for customer: '.$customerId);\n                        break;\n                    }\n                    if ($subscription->stripe_invoice_paid) {\n                        // send_internal_notification('payment_intent.payment_failed but invoice is active for customer: '.$customerId);\n\n                        return;\n                    }\n                    // send_internal_notification('Subscription payment failed for customer: '.$customerId);\n                    break;\n                case 'customer.subscription.created':\n                    $customerId = data_get($data, 'customer');\n                    $subscriptionId = data_get($data, 'id');\n                    $teamId = data_get($data, 'metadata.team_id');\n                    $userId = data_get($data, 'metadata.user_id');\n                    if (! $teamId || ! $userId) {\n                        $subscription = Subscription::where('stripe_customer_id', $customerId)->first();\n                        if ($subscription) {\n                            throw new \\RuntimeException(\"Subscription already exists for customer: {$customerId}\");\n                        }\n                        throw new \\RuntimeException('No team id or user id found');\n                    }\n                    $team = Team::find($teamId);\n                    $found = $team->members->where('id', $userId)->first();\n                    if (! $found->isAdmin()) {\n                        // send_internal_notification(\"User {$userId} is not an admin or owner of team {$team->id}, customerid: {$customerId}.\");\n                        throw new \\RuntimeException(\"User {$userId} is not an admin or owner of team {$team->id}, customerid: {$customerId}.\");\n                    }\n                    Subscription::updateOrCreate(\n                        ['team_id' => $teamId],\n                        [\n                            'stripe_subscription_id' => $subscriptionId,\n                            'stripe_customer_id' => $customerId,\n                            'stripe_invoice_paid' => false,\n                        ]\n                    );\n                    break;","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/coollabsio/coolify/blob/70b9acc42467278373e00de77abb40684e25b395/app/Jobs/StripeProcessJob.php#L193-L229","documentation":"Error \"Subscription already exists for customer: {$customerId}\" thrown in coollabsio/coolify.","triggerScenarios":"Thrown at app/Jobs/StripeProcessJob.php:211 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"70b9acc42467278373e00de77abb40684e25b395","analyzedAt":"2026-08-17T01:41:01.313Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}