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

Checkout only with email without $user #86

Open
NicolasMelian opened this issue Apr 24, 2024 · 3 comments
Open

Checkout only with email without $user #86

NicolasMelian opened this issue Apr 24, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@NicolasMelian
Copy link

Hi guys!

I would like to implement the checkout option only with email, currently in my web app people can buy documents and enter their email, they press "Buy" and the idea is to send them to the checkout:

  Route::get('/buy', function () {
         return auth()->user()->checkout('variant-id');
   });

But, since they are not users and I dont want to add that step since it isnt necessary on my website. I'm trying to implement this.

What occurred to me at the moment was to do this in my controller:

$email = $validated['email'];

 $user = User::where('email', $email)->first();

 if (!$user) {
              $user = new User();
             $user->email = $email;
             // You can add more fields here if necessary
             $user->save();
 }
Auth::login($user);

// Get the checkout URL
$url = ('buy');

return Inertia::location($url);

And I made the name and password nullable, but I don't know how correct it is to follow this path. I saw that this way of handling checkout is common in today's web apps to skip the registration step when it is not necessary.

What could be a more optimal way to do this?

I upload it here because maybe it can be useful to people too!

@karakhanyans
Copy link

Hi @NicolasMelian

I wrote a doc on how to do that here: https://larafast.com/blog/laravel-lemonsqueezy-for-non-auth-users

@karakhanyans
Copy link

Also, if you want to still store the information about the user who purchased with webhooks, you need to overwrite the LemonSqueezy webhook, which will save user info into the table, otherwise when there is no "customer" data provided order will not be created in db.

@driesvints driesvints added the enhancement New feature or request label Apr 25, 2024
@driesvints
Copy link
Contributor

I'll mark this as a feature request for now and will have a think on how to cater better for guest checkouts later one. Thanks for suggesting and thanks @karakhanyans for that example!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants