Closed curtisdelicata closed 6 months ago
ed894852bc
)[!TIP] I'll email you at genealogysoftwareuk@gmail.com when I complete this pull request!
Here are the GitHub Actions logs prior to making any changes:
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.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
app/Filament/Pages/ManageSubscription.php
✓ https://github.com/liberu-genealogy/genealogy-laravel/commit/19d2676fd3dfedbe6f4842a2197cf84de23b2eff Edit
Create app/Filament/Pages/ManageSubscription.php with contents:
• Create a new Filament page named `ManageSubscription` extending `CustomFilamentBasePage` to ensure it fits within the application's existing page structure.
• Import `StripeSubscriptionService` to interact with Stripe for subscription management tasks.
• Define a Livewire component within this page to handle dynamic UI elements such as displaying current subscription details, and providing forms for updating and canceling subscriptions.
• Use Tailwind CSS classes for styling to maintain consistency with the application's design system.
• Implement methods within the Livewire component to interact with `StripeSubscriptionService` for fetching current subscription details, updating subscriptions, and handling cancellations.
app/Filament/Pages/ManageSubscription.php
✓ Edit
Check app/Filament/Pages/ManageSubscription.php with contents:
Ran GitHub Actions for 19d2676fd3dfedbe6f4842a2197cf84de23b2eff:
app/Http/Livewire/SubscriptionManager.php
✓ https://github.com/liberu-genealogy/genealogy-laravel/commit/436d233a7d73bd0650e7dca0cf99f8759e8f529d Edit
Create app/Http/Livewire/SubscriptionManager.php with contents:
• Create a Livewire component named `SubscriptionManager` to encapsulate the logic for managing subscriptions.
• Import `StripeSubscriptionService` to perform operations such as retrieving subscription details, updating, and canceling subscriptions.
• Define public properties to hold subscription details and any form inputs required for updating subscriptions.
• Implement methods for interacting with the Stripe API through `StripeSubscriptionService`, including fetching subscription details on component mount, updating subscription details, and handling subscription cancellations.
• Ensure all interactions provide user feedback, such as success or error messages, using session flashes or Livewire's messaging system.
app/Http/Livewire/SubscriptionManager.php
✓ Edit
Check app/Http/Livewire/SubscriptionManager.php with contents:
Ran GitHub Actions for 436d233a7d73bd0650e7dca0cf99f8759e8f529d:
app/Services/StripeSubscriptionService.php
✓ https://github.com/liberu-genealogy/genealogy-laravel/commit/e6b4025cef64b385b959831362fce1003ac1359d Edit
Modify app/Services/StripeSubscriptionService.php with contents:
• Add new methods to `StripeSubscriptionService` for updating and canceling subscriptions using the Stripe API.
• These methods should accept necessary parameters such as subscription ID and any update parameters (e.g., new plan ID for updates).
• Ensure methods handle API responses appropriately, updating the database as needed and returning success or error information to the caller.
--- +++ @@ -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()]; + } + }
app/Services/StripeSubscriptionService.php
✓ Edit
Check app/Services/StripeSubscriptionService.php with contents:
Ran GitHub Actions for e6b4025cef64b385b959831362fce1003ac1359d:
routes/web.php
✓ https://github.com/liberu-genealogy/genealogy-laravel/commit/95a6690a24798ec1a77875e79555c65dd3466acf Edit
Modify routes/web.php with contents:
• Register a new route for the subscription management page, ensuring it's protected by appropriate middleware (e.g., auth).
• Point the route to the `ManageSubscription` Filament page.
--- +++ @@ -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'); +
routes/web.php
✓ Edit
Check routes/web.php with contents:
Ran GitHub Actions for 95a6690a24798ec1a77875e79555c65dd3466acf:
I have finished reviewing the code for completeness. I did not find errors for sweep/create_a_subscription_management_filamen
.
💡 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.
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)