laravel / cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.

Home Page:https://laravel.com/docs/cashier-paddle

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

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

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!

@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

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!