From 3ebb35a5cd65a8a3b01093607e86b706f582ed83 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 25 Jun 2024 13:54:58 +0200 Subject: [PATCH] fix: remove lemon + paddle things --- app/Livewire/Subscription/Actions.php | 65 --------------- app/Models/Subscription.php | 17 +--- bootstrap/helpers/subscriptions.php | 63 --------------- config/subscription.php | 28 +------ docker-compose.prod.yml | 21 ----- resources/views/components/paddle.blade.php | 80 ------------------- .../views/components/pricing-plans.blade.php | 26 +++--- .../livewire/subscription/actions.blade.php | 38 +-------- .../subscription/pricing-plans-old.blade.php | 67 ---------------- resources/views/livewire/team/index.blade.php | 2 +- tests/Feature/DockerCommandsTest.phpold | 62 -------------- tests/Feature/RemoteProcessTest.phpold | 32 -------- 12 files changed, 21 insertions(+), 480 deletions(-) delete mode 100644 resources/views/components/paddle.blade.php delete mode 100644 resources/views/livewire/subscription/pricing-plans-old.blade.php delete mode 100644 tests/Feature/DockerCommandsTest.phpold delete mode 100644 tests/Feature/RemoteProcessTest.phpold diff --git a/app/Livewire/Subscription/Actions.php b/app/Livewire/Subscription/Actions.php index db1f565a6..1388d3244 100644 --- a/app/Livewire/Subscription/Actions.php +++ b/app/Livewire/Subscription/Actions.php @@ -3,7 +3,6 @@ namespace App\Livewire\Subscription; use App\Models\Team; -use Illuminate\Support\Facades\Http; use Livewire\Component; class Actions extends Component @@ -15,70 +14,6 @@ public function mount() $this->server_limits = Team::serverLimit(); } - public function cancel() - { - try { - $subscription_id = currentTeam()->subscription->lemon_subscription_id; - if (! $subscription_id) { - throw new \Exception('No subscription found'); - } - $response = Http::withHeaders([ - 'Accept' => 'application/vnd.api+json', - 'Content-Type' => 'application/vnd.api+json', - 'Authorization' => 'Bearer '.config('subscription.lemon_squeezy_api_key'), - ])->delete('https://api.lemonsqueezy.com/v1/subscriptions/'.$subscription_id); - $json = $response->json(); - if ($response->failed()) { - $error = data_get($json, 'errors.0.status'); - if ($error === '404') { - throw new \Exception('Subscription not found.'); - } - throw new \Exception(data_get($json, 'errors.0.title', 'Something went wrong. Please try again later.')); - } else { - $this->dispatch('success', 'Subscription cancelled successfully. Reloading in 5s.'); - $this->dispatch('reloadWindow', 5000); - } - } catch (\Throwable $e) { - return handleError($e, $this); - } - } - - public function resume() - { - try { - $subscription_id = currentTeam()->subscription->lemon_subscription_id; - if (! $subscription_id) { - throw new \Exception('No subscription found'); - } - $response = Http::withHeaders([ - 'Accept' => 'application/vnd.api+json', - 'Content-Type' => 'application/vnd.api+json', - 'Authorization' => 'Bearer '.config('subscription.lemon_squeezy_api_key'), - ])->patch('https://api.lemonsqueezy.com/v1/subscriptions/'.$subscription_id, [ - 'data' => [ - 'type' => 'subscriptions', - 'id' => $subscription_id, - 'attributes' => [ - 'cancelled' => false, - ], - ], - ]); - $json = $response->json(); - if ($response->failed()) { - $error = data_get($json, 'errors.0.status'); - if ($error === '404') { - throw new \Exception('Subscription not found.'); - } - throw new \Exception(data_get($json, 'errors.0.title', 'Something went wrong. Please try again later.')); - } else { - $this->dispatch('success', 'Subscription resumed successfully. Reloading in 5s.'); - $this->dispatch('reloadWindow', 5000); - } - } catch (\Throwable $e) { - return handleError($e, $this); - } - } - public function stripeCustomerPortal() { $session = getStripeCustomerPortalSession(currentTeam()); diff --git a/app/Models/Subscription.php b/app/Models/Subscription.php index 35dc43c0c..1bd84a664 100644 --- a/app/Models/Subscription.php +++ b/app/Models/Subscription.php @@ -15,22 +15,7 @@ public function team() public function type() { - if (isLemon()) { - $basic = explode(',', config('subscription.lemon_squeezy_basic_plan_ids')); - $pro = explode(',', config('subscription.lemon_squeezy_pro_plan_ids')); - $ultimate = explode(',', config('subscription.lemon_squeezy_ultimate_plan_ids')); - - $subscription = $this->lemon_variant_id; - if (in_array($subscription, $basic)) { - return 'basic'; - } - if (in_array($subscription, $pro)) { - return 'pro'; - } - if (in_array($subscription, $ultimate)) { - return 'ultimate'; - } - } elseif (isStripe()) { + if (isStripe()) { if (! $this->stripe_plan_id) { return 'zero'; } diff --git a/bootstrap/helpers/subscriptions.php b/bootstrap/helpers/subscriptions.php index 224a65f0a..aadd2dd34 100644 --- a/bootstrap/helpers/subscriptions.php +++ b/bootstrap/helpers/subscriptions.php @@ -1,51 +1,8 @@ user()->id; - $team_id = currentTeam()->id ?? null; - $email = auth()->user()->email ?? null; - $name = auth()->user()->name ?? null; - $url = "https://store.coollabs.io/checkout/buy/$checkout_id?"; - if ($user_id) { - $url .= "&checkout[custom][user_id]={$user_id}"; - } - if (isset($team_id)) { - $url .= "&checkout[custom][team_id]={$team_id}"; - } - if ($email) { - $url .= "&checkout[email]={$email}"; - } - if ($name) { - $url .= "&checkout[name]={$name}"; - } - - return $url; -} - -function getPaymentLink() -{ - return currentTeam()->subscription->lemon_update_payment_menthod_url; -} - -function getRenewDate() -{ - return Carbon::parse(currentTeam()->subscription->lemon_renews_at)->format('Y-M-d H:i:s'); -} - -function getEndDate() -{ - return Carbon::parse(currentTeam()->subscription->lemon_renews_at)->format('Y-M-d H:i:s'); -} - function isSubscriptionActive() { if (! isCloud()) { @@ -60,12 +17,6 @@ function isSubscriptionActive() if (is_null($subscription)) { return false; } - if (isLemon()) { - return $subscription->lemon_status === 'active'; - } - // if (isPaddle()) { - // return $subscription->paddle_status === 'active'; - // } if (isStripe()) { return $subscription->stripe_invoice_paid === true; } @@ -82,12 +33,6 @@ function isSubscriptionOnGracePeriod() if (! $subscription) { return false; } - if (isLemon()) { - $is_still_grace_period = $subscription->lemon_ends_at && - Carbon::parse($subscription->lemon_ends_at) > Carbon::now(); - - return $is_still_grace_period; - } if (isStripe()) { return $subscription->stripe_cancel_at_period_end; } @@ -98,18 +43,10 @@ function subscriptionProvider() { return config('subscription.provider'); } -function isLemon() -{ - return config('subscription.provider') === 'lemon'; -} function isStripe() { return config('subscription.provider') === 'stripe'; } -function isPaddle() -{ - return config('subscription.provider') === 'paddle'; -} function getStripeCustomerPortalSession(Team $team) { Stripe::setApiKey(config('subscription.stripe_api_key')); diff --git a/config/subscription.php b/config/subscription.php index 07665075f..3e0182de9 100644 --- a/config/subscription.php +++ b/config/subscription.php @@ -1,7 +1,8 @@ env('SUBSCRIPTION_PROVIDER', null), // stripe, paddle, lemon + 'provider' => env('SUBSCRIPTION_PROVIDER', null), // stripe + // Stripe 'stripe_api_key' => env('STRIPE_API_KEY', null), 'stripe_webhook_secret' => env('STRIPE_WEBHOOK_SECRET', null), @@ -22,29 +23,4 @@ 'stripe_price_id_dynamic_monthly' => env('STRIPE_PRICE_ID_DYNAMIC_MONTHLY', null), 'stripe_price_id_dynamic_yearly' => env('STRIPE_PRICE_ID_DYNAMIC_YEARLY', null), - - // Paddle - 'paddle_vendor_id' => env('PADDLE_VENDOR_ID', null), - 'paddle_vendor_auth_code' => env('PADDLE_VENDOR_AUTH_CODE', null), - 'paddle_webhook_secret' => env('PADDLE_WEBHOOK_SECRET', null), - 'paddle_public_key' => env('PADDLE_PUBLIC_KEY', null), - 'paddle_price_id_basic_monthly' => env('PADDLE_PRICE_ID_BASIC_MONTHLY', null), - 'paddle_price_id_basic_yearly' => env('PADDLE_PRICE_ID_BASIC_YEARLY', null), - 'paddle_price_id_pro_monthly' => env('PADDLE_PRICE_ID_PRO_MONTHLY', null), - 'paddle_price_id_pro_yearly' => env('PADDLE_PRICE_ID_PRO_YEARLY', null), - 'paddle_price_id_ultimate_monthly' => env('PADDLE_PRICE_ID_ULTIMATE_MONTHLY', null), - 'paddle_price_id_ultimate_yearly' => env('PADDLE_PRICE_ID_ULTIMATE_YEARLY', null), - - // Lemon - 'lemon_squeezy_api_key' => env('LEMON_SQUEEZY_API_KEY', null), - 'lemon_squeezy_webhook_secret' => env('LEMON_SQUEEZY_WEBHOOK_SECRET', null), - 'lemon_squeezy_checkout_id_basic_monthly' => env('LEMON_SQUEEZY_CHECKOUT_ID_BASIC_MONTHLY', null), - 'lemon_squeezy_checkout_id_basic_yearly' => env('LEMON_SQUEEZY_CHECKOUT_ID_BASIC_YEARLY', null), - 'lemon_squeezy_checkout_id_pro_monthly' => env('LEMON_SQUEEZY_CHECKOUT_ID_PRO_MONTHLY', null), - 'lemon_squeezy_checkout_id_pro_yearly' => env('LEMON_SQUEEZY_CHECKOUT_ID_PRO_YEARLY', null), - 'lemon_squeezy_checkout_id_ultimate_monthly' => env('LEMON_SQUEEZY_CHECKOUT_ID_ULTIMATE_MONTHLY', null), - 'lemon_squeezy_checkout_id_ultimate_yearly' => env('LEMON_SQUEEZY_CHECKOUT_ID_ULTIMATE_YEARLY', null), - 'lemon_squeezy_basic_plan_ids' => env('LEMON_SQUEEZY_BASIC_PLAN_IDS', ''), - 'lemon_squeezy_pro_plan_ids' => env('LEMON_SQUEEZY_PRO_PLAN_IDS', ''), - 'lemon_squeezy_ultimate_plan_ids' => env('LEMON_SQUEEZY_ULTIMATE_PLAN_IDS', ''), ]; diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 357138ca1..b8156cab5 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -69,27 +69,6 @@ services: - STRIPE_PRICE_ID_ULTIMATE_MONTHLY_OLD - STRIPE_PRICE_ID_ULTIMATE_YEARLY_OLD - STRIPE_EXCLUDED_PLANS - - PADDLE_VENDOR_ID - - PADDLE_WEBHOOK_SECRET - - PADDLE_VENDOR_AUTH_CODE - - PADDLE_PUBLIC_KEY - - PADDLE_PRICE_ID_BASIC_MONTHLY - - PADDLE_PRICE_ID_BASIC_YEARLY - - PADDLE_PRICE_ID_PRO_MONTHLY - - PADDLE_PRICE_ID_PRO_YEARLY - - PADDLE_PRICE_ID_ULTIMATE_MONTHLY - - PADDLE_PRICE_ID_ULTIMATE_YEARLY - - LEMON_SQUEEZY_API_KEY - - LEMON_SQUEEZY_WEBHOOK_SECRET - - LEMON_SQUEEZY_CHECKOUT_ID_BASIC_MONTHLY - - LEMON_SQUEEZY_CHECKOUT_ID_BASIC_YEARLY - - LEMON_SQUEEZY_CHECKOUT_ID_PRO_MONTHLY - - LEMON_SQUEEZY_CHECKOUT_ID_PRO_YEARLY - - LEMON_SQUEEZY_CHECKOUT_ID_ULTIMATE_MONTHLY - - LEMON_SQUEEZY_CHECKOUT_ID_ULTIMATE_YEARLY - - LEMON_SQUEEZY_BASIC_PLAN_IDS - - LEMON_SQUEEZY_PRO_PLAN_IDS - - LEMON_SQUEEZY_ULTIMATE_PLAN_IDS ports: - "${APP_PORT:-8000}:80" expose: diff --git a/resources/views/components/paddle.blade.php b/resources/views/components/paddle.blade.php deleted file mode 100644 index 5aa10b200..000000000 --- a/resources/views/components/paddle.blade.php +++ /dev/null @@ -1,80 +0,0 @@ - - Subscribe - - - Subscribe - - - - Subscribe - - - Subscribe - - - - Subscribe - - - Subscribe - - - - - - diff --git a/resources/views/components/pricing-plans.blade.php b/resources/views/components/pricing-plans.blade.php index 5977323f2..873ecfc47 100644 --- a/resources/views/components/pricing-plans.blade.php +++ b/resources/views/components/pricing-plans.blade.php @@ -34,15 +34,16 @@ class="font-bold dark:text-warning">{{ config('constants.limits.trial_period') }
- {{--
+

Unlimited Trial Get Started

-

Start self-hosting without limits with +

Start self-hosting without limits + with our OSS version. Same features as the paid version, but you have to manage by yourself.

-
--}} +

Ultimate

-

+

Custom {{-- pay-as-you-go --}} @@ -198,7 +200,7 @@ class="grid max-w-sm grid-cols-1 -mt-16 divide-y divide-neutral-200 dark:divide- {{-- /month + VAT --}}

- + pay-as-you-go @@ -213,8 +215,8 @@ class="grid max-w-sm grid-cols-1 -mt-16 divide-y divide-neutral-200 dark:divide- single location.

  • -

    Your current plan

    -
    @endif - {{-- @if (subscriptionProvider() === 'lemon') -
    Status: {{ currentTeam()->subscription->lemon_status }}
    -
    Type: {{ currentTeam()->subscription->lemon_variant_name }}
    - @if (currentTeam()->subscription->lemon_status === 'cancelled') -
    Subscriptions ends at: {{ getRenewDate() }}
    -
    If you would like to change the subscription to a lower/higher plan, please - contact - us.
    - @else -
    Renews at: {{ getRenewDate() }}
    - @endif -
    -
    - @if (currentTeam()->subscription->lemon_status === 'cancelled') - Resume Subscription - - @else - Cancel Subscription - @endif -
    - -
    - @endif --}}
    diff --git a/resources/views/livewire/subscription/pricing-plans-old.blade.php b/resources/views/livewire/subscription/pricing-plans-old.blade.php deleted file mode 100644 index e4a3cc762..000000000 --- a/resources/views/livewire/subscription/pricing-plans-old.blade.php +++ /dev/null @@ -1,67 +0,0 @@ - - @if (config('subscription.provider') === 'stripe') - - - {{ $isTrial ? 'Start Trial' : 'Subscribe' }} - - - - {{ $isTrial ? 'Start Trial' : 'Subscribe' }} - - - - - {{ $isTrial ? 'Start Trial' : 'Subscribe' }} - - - {{ $isTrial ? 'Start Trial' : 'Subscribe' }} - - - - - {{ $isTrial ? 'Start Trial' : 'Subscribe' }} - - - {{ $isTrial ? 'Start Trial' : 'Subscribe' }} - - - @endif - @if (config('subscription.provider') === 'paddle') - - @endif - @if (config('subscription.provider') === 'lemon') - - Subscribe - - - Subscribe - - - - Subscribe - - - Subscribe - - - - Subscribe - - - Subscribe - - - @endif - diff --git a/resources/views/livewire/team/index.blade.php b/resources/views/livewire/team/index.blade.php index 7178e01aa..40c81766c 100644 --- a/resources/views/livewire/team/index.blade.php +++ b/resources/views/livewire/team/index.blade.php @@ -25,7 +25,7 @@
    This is the default team. You can't delete it.
    @elseif(auth()->user()->teams()->get()->count() === 1 || auth()->user()->currentTeam()->personal_team)
    You can't delete your last / personal team.
    - @elseif(currentTeam()->subscription && currentTeam()->subscription?->lemon_status !== 'cancelled') + @elseif(currentTeam()->subscription)
    Please cancel your subscription here before delete this team.
    @else diff --git a/tests/Feature/DockerCommandsTest.phpold b/tests/Feature/DockerCommandsTest.phpold deleted file mode 100644 index 77e9d77e1..000000000 --- a/tests/Feature/DockerCommandsTest.phpold +++ /dev/null @@ -1,62 +0,0 @@ -seed(DatabaseSeeder::class); -}); - -it('starts a docker container correctly', function () { - - - test()->actingAs(User::factory([ - 'uuid' => Str::uuid(), - 'email' => Str::uuid() . '@example.com', - ])->create()); - - $coolifyNamePrefix = 'coolify_test_'; - - - $format = '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}"}'; - $areThereCoolifyTestContainers = "docker ps --filter=\"name={$coolifyNamePrefix}*\" --format '{$format}' "; - - // Generate a known name - $containerName = 'coolify_test_' . now()->format('Ymd_his'); - $host = Server::where('name', 'testing-local-docker-container')->first(); - - remote_process([ - "docker rm -f $(docker ps --filter='name={$coolifyNamePrefix}*' -aq) > /dev/null 2>&1" - ], $host); - - // Assert there's no containers start with coolify_test_* - $activity = remote_process([$areThereCoolifyTestContainers], $host); - $tidyOutput = RunRemoteProcess::decodeOutput($activity); - $containers = format_docker_command_output_to_json($tidyOutput); - expect($containers)->toBeEmpty(); - - // start a container nginx -d --name = $containerName - $activity = remote_process(["docker run -d --rm --name {$containerName} nginx"], $host); - expect($activity->getExtraProperty('exitCode'))->toBe(0); - - // docker ps name = $container - $activity = remote_process([$areThereCoolifyTestContainers], $host); - $tidyOutput = RunRemoteProcess::decodeOutput($activity); - $containers = format_docker_command_output_to_json($tidyOutput); - expect($containers->where('Names', $containerName)->count())->toBe(1); - - // Stop testing containers - $activity = remote_process([ - "docker ps --filter='name={$coolifyNamePrefix}*' -aq && " . - "docker rm -f $(docker ps --filter='name={$coolifyNamePrefix}*' -aq)" - ], $host); - expect($activity->getExtraProperty('exitCode'))->toBe(0); -}); diff --git a/tests/Feature/RemoteProcessTest.phpold b/tests/Feature/RemoteProcessTest.phpold deleted file mode 100644 index ca3777e9d..000000000 --- a/tests/Feature/RemoteProcessTest.phpold +++ /dev/null @@ -1,32 +0,0 @@ -seed(DatabaseSeeder::class); -}); - -it('outputs correctly', function () { - - $host = Server::where('name', 'testing-local-docker-container')->first(); - - $activity = remote_process([ - 'pwd', - 'x=1; while [ $x -le 3 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done', - ], $host); - - - $tidyOutput = RunRemoteProcess::decodeOutput($activity); - - expect($tidyOutput) - ->toContain('Welcome 1 times') - ->toContain('Welcome 3 times') - ->not()->toBeJson(); -});