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

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

Closed
ousid opened this issue May 4, 2023 · 4 comments
Closed

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

ousid opened this issue May 4, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@ousid
Copy link
Contributor

ousid commented May 4, 2023

Trying to run a checkout with a variant ID, but I got the following issue: Trying to access array offset on value of type null

Steps to produce

  • Create a product
  • Create variants
  • Get the Variant ID
  • Create a checkout from an existing user
  • pass the checkout variable to x-lemon-button
  • Trying to access the pricing page.

Code sample:

public function __invoke()
{
   /** @var \App\Models\User */
   $user = Auth::user();
   $checkout = $user?->checkout('variant-id');

   return view('pricing', ....);
}

The Problem

After digging into the package source code, I found the issue in the url() method

Suggested solution

For now, I didn't have any clue on where is the problem exactly is. I'll update the issue once I solved the problem, with a PR.

@driesvints
Copy link
Collaborator

Thanks @ousid. I'm afraid we'll need some more info here like details on how the product and variant were configured because right now this was tested and should work. Can you also share the full code on how you pass the checkout to the view as well as how you assign the checkout to the blade component?

@driesvints driesvints added the bug Something isn't working label May 4, 2023
@ousid
Copy link
Contributor Author

ousid commented May 4, 2023

Well, here are the steps on how it's done:

  • Create New Product
  • Add Variants inside the product (free-premium)
  • Access the API endpoint to fetch the variants ID https://api.lemonsqueezy.com/v1/products/{ID}/relationships/variants
  • Pass the variant ID into the controller
    public function __invoke()
    {
        /** @var \App\Models\User */
        $user = Auth::user();
        $checkout = $user?->checkout('variant-id')
                        ?->withButtonColor('#F15BB5');

        return view('frontend.pricing', [
            'packages' => Package::get(),
            'checkout' => $checkout,
        ]);
    }

Here's the blade

<x-lemon-button 
    :href="$checkout" 
    class="cta-button" 
    aria-describedby="tier-standard">
    {{ $package->cta_button_text }}
</x-lemon-button>

when I dd the $href in the button component, it shows it's an instance from LemonSqueezy\Laravel\Checkout

You should note that the app is in test mode.

Here's a screenshot from the dashboard
image

PS: my app still in the dev mode, and I'm just testing the package out, to see if it works well.

@driesvints
Copy link
Collaborator

Hmm odd. It would help if you had an entire stacktrace to see where the error originates from.

@driesvints
Copy link
Collaborator

Feel free to re-open an issue once you have a complete stacktrace 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants