From ba424efd39474cee60c8cd95ceed01ac919407c2 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 27 Oct 2023 10:17:13 +0200 Subject: [PATCH 1/6] cloud: fix subs --- app/Models/Subscription.php | 8 ++++++-- config/sentry.php | 2 +- config/version.php | 2 +- routes/webhooks.php | 4 ++-- versions.json | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/Models/Subscription.php b/app/Models/Subscription.php index 23ed70f8f..cd35dc477 100644 --- a/app/Models/Subscription.php +++ b/app/Models/Subscription.php @@ -39,14 +39,18 @@ class Subscription extends Model if (!$subscription) { return null; } - $subscriptionPlanId = data_get($subscription,'stripe_plan_id'); + $subscriptionPlanId = data_get($subscription, 'stripe_plan_id'); if (!$subscriptionPlanId) { return null; } + $subscriptionInvoicePaid = data_get($subscription, 'stripe_invoice_paid'); + if (!$subscriptionInvoicePaid) { + return null; + } $subscriptionConfigs = collect(config('subscription')); $stripePlanId = null; $subscriptionConfigs->map(function ($value, $key) use ($subscriptionPlanId, &$stripePlanId) { - if ($value === $subscriptionPlanId){ + if ($value === $subscriptionPlanId) { $stripePlanId = $key; }; })->first(); diff --git a/config/sentry.php b/config/sentry.php index 826794a5a..4b4820837 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.105', + 'release' => '4.0.0-beta.106', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 5bcfd4f1b..95806e408 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ $planId, 'stripe_cancel_at_period_end' => $cancelAtPeriodEnd, ]); - if ($status === 'paused') { + if ($status === 'paused' || $status === 'incomplete_expired') { $subscription->update([ 'stripe_invoice_paid' => false, ]); - send_internal_notification('Subscription paused for team: ' . $subscription->team->id); + send_internal_notification('Subscription paused or incomplete for team: ' . $subscription->team->id); } // Trial ended but subscribed, reactive servers diff --git a/versions.json b/versions.json index cf69f206f..e658db6af 100644 --- a/versions.json +++ b/versions.json @@ -4,7 +4,7 @@ "version": "3.12.36" }, "v4": { - "version": "4.0.0-beta.105" + "version": "4.0.0-beta.106" } } } From 038ea08ca7a7c10be870df23e8b2e687ff664e4f Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 27 Oct 2023 10:26:35 +0200 Subject: [PATCH 2/6] add payment_intent.payment_failed to subs --- routes/webhooks.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/routes/webhooks.php b/routes/webhooks.php index ef75bbea8..dc1caa7c4 100644 --- a/routes/webhooks.php +++ b/routes/webhooks.php @@ -172,7 +172,7 @@ Route::post('/source/github/events', function () { $found = ApplicationPreview::where('application_id', $application->id)->where('pull_request_id', $pull_request_id)->first(); if ($found) { $found->delete(); - $container_name = generateApplicationContainerName($application,$pull_request_id); + $container_name = generateApplicationContainerName($application, $pull_request_id); // ray('Stopping container: ' . $container_name); instant_remote_process(["docker rm -f $container_name"], $application->destination->server); return response('Preview Deployment closed.'); @@ -288,6 +288,14 @@ Route::post('/payments/stripe/events', function () { 'stripe_invoice_paid' => true, ]); break; + case 'payment_intent.payment_failed': + $customerId = data_get($data, 'customer'); + $subscription = Subscription::where('stripe_customer_id', $customerId)->firstOrFail(); + $subscription->update([ + 'stripe_invoice_paid' => false, + ]); + send_internal_notification('Subscription payment failed: ' . $subscription->team->id); + break; case 'customer.subscription.updated': $customerId = data_get($data, 'customer'); $subscription = Subscription::where('stripe_customer_id', $customerId)->firstOrFail(); From ebe665534940abe788d9e48d9065bfa1f9d0df8f Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 27 Oct 2023 10:28:43 +0200 Subject: [PATCH 3/6] update invoice paid --- routes/webhooks.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/routes/webhooks.php b/routes/webhooks.php index dc1caa7c4..4c39905e7 100644 --- a/routes/webhooks.php +++ b/routes/webhooks.php @@ -281,12 +281,25 @@ Route::post('/payments/stripe/events', function () { break; case 'invoice.paid': $customerId = data_get($data, 'customer'); - $subscription = Subscription::where('stripe_customer_id', $customerId)->firstOrFail(); - $planId = data_get($data, 'lines.data.0.plan.id'); - $subscription->update([ - 'stripe_plan_id' => $planId, - 'stripe_invoice_paid' => true, - ]); + $email = data_get($data, 'customer_email'); + $subscription = Subscription::where('stripe_customer_id', $customerId)->first(); + if ($subscription) { + $planId = data_get($data, 'lines.data.0.plan.id'); + $subscription->update([ + 'stripe_plan_id' => $planId, + 'stripe_invoice_paid' => true, + ]); + break; + } + $team = Team::where('email', $email)->first(); + if ($team) { + $subscription = data_get($team, 'subscription'); + $planId = data_get($data, 'lines.data.0.plan.id'); + $subscription->update([ + 'stripe_plan_id' => $planId, + 'stripe_invoice_paid' => true, + ]); + } break; case 'payment_intent.payment_failed': $customerId = data_get($data, 'customer'); From 38f59b9410ca6b155120ab700534ab3335558f01 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 27 Oct 2023 10:30:15 +0200 Subject: [PATCH 4/6] revert --- routes/webhooks.php | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/routes/webhooks.php b/routes/webhooks.php index 4c39905e7..dc1caa7c4 100644 --- a/routes/webhooks.php +++ b/routes/webhooks.php @@ -281,25 +281,12 @@ Route::post('/payments/stripe/events', function () { break; case 'invoice.paid': $customerId = data_get($data, 'customer'); - $email = data_get($data, 'customer_email'); - $subscription = Subscription::where('stripe_customer_id', $customerId)->first(); - if ($subscription) { - $planId = data_get($data, 'lines.data.0.plan.id'); - $subscription->update([ - 'stripe_plan_id' => $planId, - 'stripe_invoice_paid' => true, - ]); - break; - } - $team = Team::where('email', $email)->first(); - if ($team) { - $subscription = data_get($team, 'subscription'); - $planId = data_get($data, 'lines.data.0.plan.id'); - $subscription->update([ - 'stripe_plan_id' => $planId, - 'stripe_invoice_paid' => true, - ]); - } + $subscription = Subscription::where('stripe_customer_id', $customerId)->firstOrFail(); + $planId = data_get($data, 'lines.data.0.plan.id'); + $subscription->update([ + 'stripe_plan_id' => $planId, + 'stripe_invoice_paid' => true, + ]); break; case 'payment_intent.payment_failed': $customerId = data_get($data, 'customer'); From 55f957df21d0e46a4c4741d10c0ad2f2524eb160 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 27 Oct 2023 10:42:56 +0200 Subject: [PATCH 5/6] fix: git ls-remote --- app/Jobs/ApplicationDeploymentJob.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 59d2a1e30..9fefde4a9 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -516,9 +516,20 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted private function check_git_if_build_needed() { $this->generate_git_import_commands(); + $private_key = base64_encode($this->application->private_key->private_key); + ray($private_key); $this->execute_remote_command( [ - executeInDocker($this->deployment_uuid, "GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$this->customPort} -o Port={$this->customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git ls-remote {$this->fullRepoUrl} {$this->branch}"), + executeInDocker($this->deployment_uuid, "mkdir -p /root/.ssh") + ], + [ + executeInDocker($this->deployment_uuid, "echo '{$private_key}' | base64 -d > /root/.ssh/id_rsa") + ], + [ + executeInDocker($this->deployment_uuid, "chmod 600 /root/.ssh/id_rsa") + ], + [ + executeInDocker($this->deployment_uuid, "GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$this->customPort} -o Port={$this->customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" git ls-remote {$this->fullRepoUrl} {$this->branch}"), "hidden" => true, "save" => "git_commit_sha" ], From 4f543ce20f3fbc0278bc3ef81764709688e18e3d Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 27 Oct 2023 10:43:05 +0200 Subject: [PATCH 6/6] remove ray --- app/Jobs/ApplicationDeploymentJob.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 9fefde4a9..abd93f684 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -517,7 +517,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted { $this->generate_git_import_commands(); $private_key = base64_encode($this->application->private_key->private_key); - ray($private_key); $this->execute_remote_command( [ executeInDocker($this->deployment_uuid, "mkdir -p /root/.ssh")