I'm trying to update a subscription and add a coupon at the same time. Here's the code:
$user->subscription('subscription_name')->withCoupon($request->stripe_coupons)->swap($planName);
The error I'm getting is Call to undefined method Laravel\Cashier\Subscription::withCoupon()
My understanding is that this should just work. If I remove the ->withCoupon()
bit, it works fine, and I can see the method in the cashier code. What am I doing wrong??
Because it's been mentioned, as far as I can tell I'm on the latest version. Cashier was installed using composer require laravel/cashier
, but that seems to have put me on "laravel/cashier": "^9.3",
in my composer.json file.
How do I fix?
Based on the comments that I put, the code would be like this.
$subscription = $user->subscription('subscription_name');
// Swap Plan with Coupon
$subscription->swap($planName, [
'coupon' => $request->stripe_coupons,
]);
You can see the development code here
Repository laravel/cashier master
Updated
Apparently, version 10 is still in development. (dev-master)
Try updating the composer to see if it is updated.
composer update
If you do not update, do it manually. Modify composer.json.
"require":
{
...
"laravel/cashier": "dev-master",
...
}
Run composer update again to update the changes.
But if it works, it will be clear to you that, until you release the production version, you will not have that functionality available.
I warn you that it is not advisable to use the development version in production. Because they have not passed the necessary tests to verify a minimum stability.
After trying, you can always go back to the previous.
"require":
{
...
"laravel/cashier": "^9.3"
...
}
Run composer update again to update the changes.
Please, accept it as the correct answer, if it has been useful and a favorable vote if you think I deserve it, thank you very much.
A cordial greeting.