Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incrementQuantity() & decrementQuantity() Throwing Error #224

Closed
haszzam opened this issue Dec 16, 2023 · 5 comments · Fixed by #226
Closed

Fix incrementQuantity() & decrementQuantity() Throwing Error #224

haszzam opened this issue Dec 16, 2023 · 5 comments · Fixed by #226
Labels

Comments

@haszzam
Copy link

haszzam commented Dec 16, 2023

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.

image

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.

image

The problem is that the decrementQuantity() is not passing the $item or the $price_id to the updateQuantity() method as you can see below
image

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');.

@haszzam haszzam changed the title Fix updateQuantity() Throwing Error Fix updateQuantity() & decrementQuantity() Throwing Error Dec 16, 2023
@haszzam haszzam changed the title Fix updateQuantity() & decrementQuantity() Throwing Error Fix incrementQuantity() & decrementQuantity() Throwing Error Dec 16, 2023
@haszzam
Copy link
Author

haszzam commented Dec 17, 2023

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.

#223 (comment)

Thanks!

@driesvints
Copy link
Member

@haszzam heya! Sorry for the late reply here. Don't worry about it. I appreciate you notifying us! I've sent in a PR here: #226

@driesvints driesvints added the bug label Dec 21, 2023
@haszzam
Copy link
Author

haszzam commented Dec 21, 2023

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().

@driesvints
Copy link
Member

Oh you're correct. Added that as well 👍

@haszzam
Copy link
Author

haszzam commented Dec 23, 2023

Thanks @driesvints I really appreciate your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants