laravel / cashier-mollie

MIT License
375 stars 63 forks source link

Subscription cancel not working #102

Closed larsjanssen6 closed 5 years ago

larsjanssen6 commented 5 years ago

Hi,

When I try to cancel a subscription:

if($subscription->cancelled()) {
    return Action::message('Subscription already cancelled');
}

$subscription->cancel();

I get this error message:

Argument 1 passed to Laravel\Cashier\Subscription::cancelAt() must be an instance of Carbon\Carbon, instance of Carbon\CarbonImmutable given, called in /vendor/laravel/cashier-mollie/src/Subscription.php on line 247

It goes wrong in this method:

/**
 * Cancel the subscription at the end of the billing period.
 *
 * @param string|null $reason
 * @return $this
 */
public function cancel($reason = SubscriptionCancellationReason::UNKNOWN)
{
    // If the user was on trial, we will set the grace period to end when the trial
    // would have ended. Otherwise, we'll retrieve the end of the billing cycle
    // period and make that the end of the grace period for this current user.

    $grace_ends_at = $this->onTrial() ? $this->trial_ends_at : $this->cycle_ends_at;

    return $this->cancelAt($grace_ends_at, $reason);
}

When I dd($this->cycle_ends_at); I get a string. But I would except a Carbon instance. The cancelAt method expects a Carbon instance that's why I receive this error.

Am I doing something wrong or is this a bug ?

sandervanhooft commented 5 years ago

Hi @larsjanssen6,

Given the error message it doesn't seem to be an issue with a string, but with Carbon\Carbon vs Carbon\CarbonImmutable. Can you confirm this?

larsjanssen6 commented 5 years ago

@sandervanhooft Yes correct.

sandervanhooft commented 5 years ago

Are you in any way overriding the default Carbon behavior?

larsjanssen6 commented 5 years ago

When I try it in a fresh laravel project + mollie cashier package it's working. So I guess it's something in my project. I don't override the default carbon behavior. Will let you know when I find it. Thanks for your reaction :)

sandervanhooft commented 5 years ago

No problem @larsjanssen6. Thanks for letting me know!

rubenbuijs commented 4 years ago

Had the same issue. Happened because I was trying to cancel a subscription that was in it's grace period.