I have 2 routes, one for canceling subscription, and one for resuming, and unless I am missing something, both routes are identical except for the names/functions/urls. When I cancel resume the subscription, I click the /resume url, it performs the function, and then returns back, and it's all so fast it seems like it never leaves the page, then it flashes the success message.
My /cancel url just goes to a blank page (I am pretty sure this is correct, because you would never see this if it worked properly) and it performs the cancel function but never returns back. When I manually go back with my back button, it then flashes the success message. Just can't figure out why it will not go back on it's own, as intended. Please tell me if you need any other info besides this.
Working:
Route::get('/resume', function (Request $request) {
// $user = User::find(1);
$user = Auth::user();
$response = $user->subscription()->resume();
toastr()->success('Your subscription has been successfully resumed.', 'Success' , ['closeButton' => 'true','positionClass' => 'toast-top-center']);
return back();
});
Not working:
Route::get('/cancel', function (Request $request) {
// $user = User::find(1);
$user = Auth::user();
$response = $user->subscription()->cancel();
toastr()->success('Your subscription has been successfully cancelled.', 'Success' , ['closeButton' => 'true','positionClass' => 'toast-top-center']);
return back();
});
I feel like these aren't necessary, but just in case, here are the 2 functions in my subscription controller.
public function cancel(): self
{
$response = LemonSqueezy::api('DELETE', "subscriptions/{$this->lemon_squeezy_id}");
$this->sync($response['data']['attributes']);
return $this;
}
/**
* Resume the subscription.
*/
public function resume(): self
{
if ($this->expired()) {
throw new LogicException('Cannot resume an expired subscription.');
}
$response = LemonSqueezy::api('PATCH', "subscriptions/{$this->lemon_squeezy_id}", [
'data' => [
'type' => 'subscriptions',
'id' => $this->lemon_squeezy_id,
'attributes' => [
'cancelled' => false,
],
],
]);
$this->sync($response['data']['attributes']);
return $this;
}