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

Call to a member function lastPayment() on null

Benoit1980 opened this issue · comments

"require": {
    "php": "^7.4",
    "laravel/cashier-paddle": "^1.4.6",
    "laravel/framework": "^8.54.0",
},

Description:

When you run the $subscription->lastPayment(); to check the last payment of users but a user has never paid a membership, the payment is null. It looks like the method is not dealing with null output.

$lastPayment = $subscription->lastPayment();

if no payments are found will output:
Call to a member function lastPayment() on null

Thanks, I've sent in a PR here: #133

We just spotted $subscription is null in your code which is the actual bug

As your colleague says in the PR "Trial subscriptions do create a zero-valued invoice on trial start".
So really your last payment method should check for both a zero value invoice and an empty invoice as not everyone will use the trial method.

@Benoit1980 the error isn't happening on the subscription. The error you posted is that you don't have a subscription to begin with.

Yes, this is exactly what I am trying to explain and we both understand each other on this, but, it is the next part that is important.
Imagine if you add your script to an already launched site, many users in there will have absolutely no invoices.

If you have a navbar that checks the subscription status of every user, (some on trial, some old users with no subscriptions at all and others with a live subscription), it would have been much easier to have a single method to check for both no invoices and invoices status at once.

Hope I explained myself properly.