lmsqueezy / laravel

A package to easily integrate your Laravel application with Lemon Squeezy.
https://lemonsqueezy.com
MIT License
520 stars 51 forks source link

Redirect to customer portal is throwing a type error #112

Closed AKurka closed 1 week ago

AKurka commented 1 week ago

Lemon Squeezy for Laravel Version

1.7.0

Laravel Version

11.9

PHP Version

8.3.13

Description

Hi !

I installed the lemonsqueezy laravel package to use it in an app with Inertia. I'm getting errors while trying to access the the customer portal.

I get this Laravel error :

App\Models\User::customerPortalUrl(): Return value must be of type string, null returned

Steps To Reproduce

Global

I added the billable trait to my User model.

I added this cast because i'm using an enum for my country value :

public function lemonSqueezyCountry(): ?string
    {
        return strtoupper($this->country->value);
    }

For the customer portal

I call a route using this method :

public function __invoke(Request $request)
    {
        return $request->user()->redirectToCustomerPortal();
    }
AKurka commented 1 week ago

EDIT :

I investigated in the sources files and the error come from this function : customerPortalUrl in the ManageCustomertrait.

The customer_portal URL is null. The response come from this request :

$response = LemonSqueezy::api('GET', "customers/{$this->customer->lemon_squeezy_id}");
driesvints commented 1 week ago

Heya. This is expected and in the docs:

In order to call this method your billable already needs to have a subscription or made a purchase through Lemon Squeezy.

https://github.com/lmsqueezy/laravel/tree/main?tab=readme-ov-file#customer-portal

AKurka commented 1 week ago

Yes ! I’ve alerady made a payment with lemonsqueezy. I checker the order id, the customer id and everything is filled.

driesvints commented 1 week ago

Actually it seems the requirement is to have a subscription. See https://docs.lemonsqueezy.com/api/customers/the-customer-object#urls

I've updated the docs.