|
2 | 2 |
|
3 | 3 | namespace App\Actions; |
4 | 4 |
|
| 5 | +use Illuminate\Contracts\Filesystem\FileNotFoundException; |
| 6 | +use Illuminate\Support\Facades\File; |
| 7 | + |
5 | 8 | class Billing |
6 | 9 | { |
7 | | - public function setup(string $path, bool $enabled): void |
| 10 | + protected array $filesToDelete = [ |
| 11 | + 'config/billing.php', |
| 12 | + 'app/DTOs/BillingPlanDTO.php', |
| 13 | + 'app/Models/Subscription.php', |
| 14 | + 'app/Providers/BillingServiceProvider.php', |
| 15 | + 'resources/views/layouts/billing.blade.php', |
| 16 | + 'database/migrations/2019_05_03_000001_create_customers_table.php', |
| 17 | + 'database/migrations/2019_05_03_000002_create_subscriptions_table.php', |
| 18 | + 'database/migrations/2019_05_03_000003_create_subscription_items_table.php', |
| 19 | + 'database/migrations/2019_05_03_000004_create_transactions_table.php', |
| 20 | + 'resources/js/types/plan.d.ts', |
| 21 | + 'resources/js/types/subscription.d.ts', |
| 22 | + ]; |
| 23 | + |
| 24 | + protected array $directoriesToDelete = [ |
| 25 | + 'app/Http/Controllers/Billing', |
| 26 | + 'resources/views/billing', |
| 27 | + 'tests/Feature/Billing', |
| 28 | + ]; |
| 29 | + |
| 30 | + protected array $filesToRemoveBlocks = [ |
| 31 | + 'routes/web.php', |
| 32 | + 'bootstrap/providers.php', |
| 33 | + 'resources/js/components/app-sidebar.tsx', |
| 34 | + 'resources/js/components/app-sidebar.vue', |
| 35 | + 'resources/js/components/user-menu-content.tsx', |
| 36 | + 'resources/js/components/user-menu-content.vue', |
| 37 | + 'resources/views/index.blade.php', |
| 38 | + 'resources/views/components/navbar.blade.php', |
| 39 | + 'app/Models/User.php', |
| 40 | + '.env', |
| 41 | + '.env.example', |
| 42 | + ]; |
| 43 | + |
| 44 | + /** |
| 45 | + * @throws FileNotFoundException |
| 46 | + */ |
| 47 | + public function setup(string $path, string $billing): void |
8 | 48 | { |
9 | | - if ($enabled) { |
| 49 | + if ($billing === 'stripe') { |
| 50 | + throw new \RuntimeException('Stripe is not supported yet.'); |
| 51 | + } |
| 52 | + |
| 53 | + if ($billing !== 'none') { |
10 | 54 | return; |
11 | 55 | } |
12 | 56 |
|
13 | | - $billingRoutes = file_get_contents($path.'/routes/billing.php'); |
14 | | - $billingRoutes = remove_blocks($billingRoutes, 'billing-routes'); |
15 | | - file_put_contents($path.'/routes/billing.php', $billingRoutes); |
| 57 | + delete_files($path, $this->filesToDelete); |
| 58 | + delete_directories($path, $this->directoriesToDelete); |
| 59 | + remove_blocks($path, $this->filesToRemoveBlocks, 'billing'); |
16 | 60 |
|
17 | | - $billingLayout = file_get_contents($path.'/resources/js/layouts/billing/layout.vue'); |
18 | | - $billingLayout = preg_replace('/\{\s*title:\s*\'Billing\',\s*href:\s*route\([^)]+\),\s*icon:\s*CreditCardIcon,\s*\},?\n?/m', '', $billingLayout); |
19 | | - file_put_contents($path.'/resources/js/layouts/billing/layout.vue', $billingLayout); |
| 61 | + // manual removals |
| 62 | + $userModel = File::get($path.'/app/Models/User.php'); |
| 63 | + $userModel = str_replace('@method Subscription|null subscription($type = \'default\')', '', $userModel); |
| 64 | + File::put($path.'/app/Models/User.php', $userModel); |
20 | 65 | } |
21 | 66 |
|
22 | | - public function cleanup(string $path, bool $enabled): void |
| 67 | + /** |
| 68 | + * @throws FileNotFoundException |
| 69 | + */ |
| 70 | + public function cleanup(string $path, string $billing): void |
23 | 71 | { |
24 | | - if ($enabled) { |
| 72 | + remove_block_tags($path, $this->filesToRemoveBlocks, 'billing'); |
| 73 | + |
| 74 | + if ($billing === 'none') { |
| 75 | + exec('composer remove laravel/cashier --working-dir='.$path); |
| 76 | + exec('composer remove laravel/cashier-paddle --working-dir='.$path); |
| 77 | + |
25 | 78 | return; |
26 | 79 | } |
27 | 80 |
|
28 | | - exec('composer remove laravel/cashier --working-dir='.$path); |
29 | | - exec('composer remove laravel/cashier-paddle --working-dir='.$path); |
| 81 | + if ($billing === 'stripe') { |
| 82 | + exec('composer remove laravel/cashier-paddle --working-dir='.$path); |
| 83 | + } |
| 84 | + |
| 85 | + if ($billing === 'paddle') { |
| 86 | + exec('composer remove laravel/cashier --working-dir='.$path); |
| 87 | + } |
30 | 88 | } |
31 | 89 | } |
0 commit comments