lmsqueezy / laravel

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

Trying to access array offset on value of type null #17

Closed romaldyminaya closed 1 year ago

romaldyminaya commented 1 year ago

Hi team,

I'm trying to generate the subscription link but I get this error message, over and over again. image

Here I cannot generate the link and I followed all the steps from the documentation:

image

driesvints commented 1 year ago

Can you please post the full stack trace? Right now we have no idea where this error occurs.

romaldyminaya commented 1 year ago

Hi,

Please check here https://flareapp.io/share/V7jqgRXP#F54

romaldyminaya commented 1 year ago

I did a DD in inside the subscribe -> checkout method and the guzzle is returning a 404. image

driesvints commented 1 year ago

@romaldyminaya LS let me know that they pushed a fix for this. Can you try again?

romaldyminaya commented 1 year ago

Nice @driesvints ,

Now I have the following message https://flareapp.io/share/V7jqxxoP#F60.

I must tell that I'm using the billable trait not in a user model but a company model instead.

<?php

namespace App\Models;

use App\Enums\IndustryType;
use Illuminate\Support\Str;
use App\Models\Settings\Tax;
use App\Models\Traits\HasUuids;
use App\Models\Settings\TaxNumber;
use LemonSqueezy\Laravel\Billable;
use Spatie\Multitenancy\Models\Tenant;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Company extends Tenant
{
    use HasUuids;
    use Billable;

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'is_phone_confirmed' => 'boolean',
        'is_email_confirmed' => 'boolean',
        'is_setup'           => 'boolean',
        'starting_plan'      => 'string',
        'country_code'       => 'string',
        'industry'           => IndustryType::class,
    ];

    /**
     * @return HasMany
     */
    public function users(): HasMany
    {
        return $this->hasMany(User::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Casts\Attribute
     */
    protected function name(): Attribute
    {
        return Attribute::make(
            set: fn ($value) => Str::of($value)->lower(),
            get: fn ($value) => Str::of($value)->title(),
        );
    }

    /**
     * @return \Illuminate\Database\Eloquent\Casts\Attribute
     */
    protected function email(): Attribute
    {
        return Attribute::make(
            set: fn ($value) => Str::of($value)->trim()->lower(),
            get: fn ($value) => $value,
        );
    }

    /**
     * @return \Illuminate\Database\Eloquent\Casts\Attribute
     */
    protected function administratorEmail(): Attribute
    {
        return Attribute::make(
            set: fn ($value) => Str::of($value)->trim()->lower(),
            get: fn ($value) => $value,
        );
    }

    /**
     * @return \Illuminate\Database\Eloquent\Casts\Attribute
     */
    protected function administratorName(): Attribute
    {
        return Attribute::make(
            set: fn ($value) => Str::of($value)->lower(),
            get: fn ($value) => Str::of($value)->title(),
        );
    }

    /**
     * @return string|null
     */
    public function lemonSqueezyName(): ?string
    {
        return $this->administratorName;
    }

    /**
     * @return string|null
     */
    public function lemonSqueezyEmail(): ?string
    {
        return $this->administratorEmail;
    }

    /**
     * @return string|null
     */
    public function lemonSqueezyCountry(): ?string
    {
        return $this->country_code;
    }
}
romaldyminaya commented 1 year ago

@driesvints Hi again,

I'm sending the following id to the subscribe method: image

driesvints commented 1 year ago

I must tell that I'm using the billable trait not in a user model but a company model instead.

hmm that shouldn't matter really. Are you sure you're using the correct api key for the correct environment? Is this production or testing?

driesvints commented 1 year ago

The variant ID you're sharing exists in your Lemon Squeezy dashboard in a product? Can you post a screenshot of that as proof?

romaldyminaya commented 1 year ago

Hi @driesvints ,

Would it be that I'm using the wrong code, would you mind please share with me a screenshot of what code are you using too ?

image

driesvints commented 1 year ago

Your variant id from your code example doesn’t seem to match with the length of your variant id. Are you sure you’re using a variant id? It seems to have the length of a uuid but you’ve covered it up so I’m not sure.

romaldyminaya commented 1 year ago

Hi @driesvints ,

This is the resonse I get from the GET VARIANTS endpoint:

image

Im using the code pointed with the yellow draw line. But still have the same results.

In the lemon squeeze panel I don't see a place where we can copy or paste the id for a specific subscription created.

image

I tried passing the product name, product slug, product id, product's variant id, product's variant slug and still have the same response.

driesvints commented 1 year ago

You don’t need the slug. You need the id from one level up. It’s the variant id you need.

romaldyminaya commented 1 year ago

Hi @driesvints ,

Now I found the problem. When I updated, i didn't refresh the config so I had the wrong store ID requested by the same config file:

    /*
    |--------------------------------------------------------------------------
    | Lemon Squeezy Store
    |--------------------------------------------------------------------------
    |
    | This is the ID of your Lemon Squeezy store. You can find your store
    | ID in the Lemon Squeezy dashboard. The entered value should be the
    | part after the # sign.
    |
    */

    'store' => env('LEMON_SQUEEZY_STORE'),

Now its working, thanks in advance.

driesvints commented 1 year ago

@romaldyminaya ah great