Fix incrementQuantity() & decrementQuantity() Throwing Error
haszzam opened this issue · comments
Cashier Paddle Version
2.x
Laravel Version
10.10
PHP Version
8.1
Database Driver & Version
No response
Description
Issue (1)
The incrementQuantity()
method was failing and throwing the error below.
In the updateQuantity()
running pluck(['quantity', 'price_id'])
on the result from get(['quantity', 'price_id'])
was returning null in the following line
$items = $this->items()->get(['quantity', 'price_id'])->pluck(['quantity', 'price_id'])->toArray();
I'm also not sure you could pass and array to pluck
, I think this was added by mistake.
Solution (1)
Removed pluck(['quantity', 'price_id'])
Steps To Reproduce (1)
Try running $user->subscription()->incrementQuantity(1, 'price_id');
.
Issue (2)
The decrementQuantity()
method was failing and throwing the error below.
The problem is that the decrementQuantity()
is not passing the $item
or the $price_id
to the updateQuantity()
method as you can see below
Solution (2)
Pass the $item
instance to the updateQuantity()
method.
return $this->updateQuantity(max(1, $item->quantity - $count));
Steps To Reproduce (2)
Try running $user->subscription()->decrementQuantity(1, 'price_id');
.
Hi @driesvints,
I know i'm bothering you a lot lately, But I tried to send a pull request with the fix for this issue but it failed the tests with the following message "Paddle API key not set."
I don't know where should I set the key and if I even should set a Paddle API key publicly.
If you can check it out and let me know what I have done wrong to fail the tests I would really appretiate it so that I can send a pull request directly if I found any other issues.
Thanks!
Hi @driesvints, Thank you!
BTW I checked the PR and it's only including the fix for the issue (1).
It does not fix the second issue with the decrementQuantity()
.
Oh you're correct. Added that as well 👍
Thanks @driesvints I really appreciate your help!