liberu-genealogy / genealogy-laravel

Full genealogy application using Laravel 11, PHP 8.3, Filament 3.2 and Livewire 3.5
https://www.liberu.net
MIT License
114 stars 60 forks source link

Sweep: create a subscription management filament 3 page using tailwind and livewire 3 and blade to manage the subscription to current account allow update and cancellation of stripe subscription #285

Closed curtisdelicata closed 6 months ago

curtisdelicata commented 6 months ago
Checklist - [X] Create `app/Filament/Pages/ManageSubscription.php` ✓ https://github.com/liberu-genealogy/genealogy-laravel/commit/19d2676fd3dfedbe6f4842a2197cf84de23b2eff [Edit](https://github.com/liberu-genealogy/genealogy-laravel/edit/sweep/create_a_subscription_management_filamen/app/Filament/Pages/ManageSubscription.php) - [X] Running GitHub Actions for `app/Filament/Pages/ManageSubscription.php` ✓ [Edit](https://github.com/liberu-genealogy/genealogy-laravel/edit/sweep/create_a_subscription_management_filamen/app/Filament/Pages/ManageSubscription.php) - [X] Create `app/Http/Livewire/SubscriptionManager.php` ✓ https://github.com/liberu-genealogy/genealogy-laravel/commit/436d233a7d73bd0650e7dca0cf99f8759e8f529d [Edit](https://github.com/liberu-genealogy/genealogy-laravel/edit/sweep/create_a_subscription_management_filamen/app/Http/Livewire/SubscriptionManager.php) - [X] Running GitHub Actions for `app/Http/Livewire/SubscriptionManager.php` ✓ [Edit](https://github.com/liberu-genealogy/genealogy-laravel/edit/sweep/create_a_subscription_management_filamen/app/Http/Livewire/SubscriptionManager.php) - [X] Modify `app/Services/StripeSubscriptionService.php` ✓ https://github.com/liberu-genealogy/genealogy-laravel/commit/e6b4025cef64b385b959831362fce1003ac1359d [Edit](https://github.com/liberu-genealogy/genealogy-laravel/edit/sweep/create_a_subscription_management_filamen/app/Services/StripeSubscriptionService.php#L16-L30) - [X] Running GitHub Actions for `app/Services/StripeSubscriptionService.php` ✓ [Edit](https://github.com/liberu-genealogy/genealogy-laravel/edit/sweep/create_a_subscription_management_filamen/app/Services/StripeSubscriptionService.php#L16-L30) - [X] Modify `routes/web.php` ✓ https://github.com/liberu-genealogy/genealogy-laravel/commit/95a6690a24798ec1a77875e79555c65dd3466acf [Edit](https://github.com/liberu-genealogy/genealogy-laravel/edit/sweep/create_a_subscription_management_filamen/routes/web.php#L1-L1) - [X] Running GitHub Actions for `routes/web.php` ✓ [Edit](https://github.com/liberu-genealogy/genealogy-laravel/edit/sweep/create_a_subscription_management_filamen/routes/web.php#L1-L1)
sweep-ai[bot] commented 6 months ago

🚀 Here's the PR! #294

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: ed894852bc)

[!TIP] I'll email you at genealogysoftwareuk@gmail.com when I complete this pull request!


Actions (click)

GitHub Actions✓

Here are the GitHub Actions logs prior to making any changes:

Sandbox logs for 4700e9e
Checking app/Services/StripeSubscriptionService.php for syntax errors... ✅ app/Services/StripeSubscriptionService.php has no syntax errors! 1/1 ✓
Checking app/Services/StripeSubscriptionService.php for syntax errors...
✅ app/Services/StripeSubscriptionService.php has no syntax errors!

Sandbox passed on the latest main, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/liberu-genealogy/genealogy-laravel/blob/aebb7eb696b8f50395460ab695f11759883cb761/database/migrations/2023_04_01_000000_add_stripe_subscription_columns_to_teams_table.php#L1-L29 https://github.com/liberu-genealogy/genealogy-laravel/blob/aebb7eb696b8f50395460ab695f11759883cb761/app/Services/StripeSubscriptionService.php#L1-L31 https://github.com/liberu-genealogy/genealogy-laravel/blob/aebb7eb696b8f50395460ab695f11759883cb761/app/Filament/Pages/Tenancy/RegisterTeam.php#L1-L49

Step 2: ⌨️ Coding

Ran GitHub Actions for 19d2676fd3dfedbe6f4842a2197cf84de23b2eff:

Ran GitHub Actions for 436d233a7d73bd0650e7dca0cf99f8759e8f529d:

--- 
+++ 
@@ -30,3 +30,62 @@
         ]);
     }
 }
+    /**
+     * Update an existing subscription.
+     *
+     * @param string $subscriptionId The ID of the subscription to update.
+     * @param string $newPlanId The ID of the new plan.
+     * @return array An array containing the result of the operation.
+     */
+    public function updateSubscription(string $subscriptionId, string $newPlanId): array
+    {
+        try {
+            $subscription = $this->stripeClient->subscriptions->update($subscriptionId, [
+                'items' => [
+                    ['id' => $subscriptionId, 'price' => $newPlanId],
+                ],
+            ]);
+
+            // Assuming there's a method in the Team model to update the subscription details
+            $team = Team::whereHas('subscriptions', function ($query) use ($subscriptionId) {
+                $query->where('stripe_subscription_id', $subscriptionId);
+            })->first();
+
+            if ($team) {
+                $team->subscriptions()->updateOrCreate(
+                    ['stripe_subscription_id' => $subscriptionId],
+                    ['stripe_plan_id' => $newPlanId]
+                );
+            }
+
+            return ['success' => true, 'message' => 'Subscription updated successfully.'];
+        } catch (\Exception $e) {
+            return ['success' => false, 'message' => 'Error updating subscription: ' . $e->getMessage()];
+        }
+    }
+
+    /**
+     * Cancel an existing subscription.
+     *
+     * @param string $subscriptionId The ID of the subscription to cancel.
+     * @return array An array containing the result of the operation.
+     */
+    public function cancelSubscription(string $subscriptionId): array
+    {
+        try {
+            $this->stripeClient->subscriptions->cancel($subscriptionId);
+
+            // Assuming there's a method in the Team model to handle subscription cancellation
+            $team = Team::whereHas('subscriptions', function ($query) use ($subscriptionId) {
+                $query->where('stripe_subscription_id', $subscriptionId);
+            })->first();
+
+            if ($team) {
+                $team->subscriptions()->where('stripe_subscription_id', $subscriptionId)->delete();
+            }
+
+            return ['success' => true, 'message' => 'Subscription cancelled successfully.'];
+        } catch (\Exception $e) {
+            return ['success' => false, 'message' => 'Error cancelling subscription: ' . $e->getMessage()];
+        }
+    }

Ran GitHub Actions for e6b4025cef64b385b959831362fce1003ac1359d:

--- 
+++ 
@@ -41,4 +41,6 @@
 Route::get('/contact', function () { return view('contact'); });
 Route::post('/contact/send', 'App\Http\Controllers\ContactController@sendEmail');

+Route::get('/manage-subscription', [\App\Filament\Pages\ManageSubscription::class, 'mount'])->middleware('auth')->name('manage.subscription');

+

Ran GitHub Actions for 95a6690a24798ec1a77875e79555c65dd3466acf:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/create_a_subscription_management_filamen.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.

This is an automated message generated by Sweep AI.