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

Integrity constraint violation: 1048 Column 'name' cannot be null. #266

Closed
bluzeey opened this issue Jul 10, 2024 · 8 comments
Closed

Integrity constraint violation: 1048 Column 'name' cannot be null. #266

bluzeey opened this issue Jul 10, 2024 · 8 comments

Comments

@bluzeey
Copy link

bluzeey commented Jul 10, 2024

Cashier Paddle Version

2.4

Laravel Version

11.2.0

PHP Version

8.2

Database Driver & Version

My SQL 8.0 for MacOS ( Homebrew)

Description

I am creating a user when i login them through Socialite. Here's the controller function.

public function handleGoogleCallback(Request $request)
    {
        try {
            $socialite = Socialite::driver('google')->user();
            $now = Carbon::now();
            $weekLater = $now->copy()->addDays(7);

            // Retrieve or create the user
            $user = User::firstOrCreate(
                [ 'email' => $socialite->getEmail()],
                [
                    'name'          => $socialite->getName(),
                    'email'         => $socialite->getEmail(),
                    'avatar'        => $socialite->getAvatar(),
                    'user_id'       => $socialite->getId(),
                    'social_token'  => $socialite->token,
                    'login_type'    => 'google',
                    'password'      => bcrypt('test@123'),
                    'trial_ends_at' => $weekLater,
                ]
            );
            // Log out any existing user session and log in the new user
            Auth::logout();
            session()->flush();
            // Update the name if it's null

            Auth::login($user);
            // Calculate the remaining trial days
            $trialLeft = Carbon::today()->diffInDays(Carbon::parse($user->trial_ends_at), false);

            // Redirect with appropriate message
            if ($trialLeft >= 0) {
                $message = "Trial left for $trialLeft days.";
                return redirect(route('dashboard'))->banner($message);
            } else {
                $billingUrl = route('billing'); // Ensure you have a named route for billing
                $message = "Your trial period has ended. Please <a href='{$billingUrl}'>subscribe to a plan</a>.";
                return redirect(route('billing'))->with('danger', $message);
            }
        } catch (\Exception $e) {
            Log::error($e);
            return redirect('/login')->withErrors(['error' => 'Google authentication failed.']);
        }
    }

However the checkout function which I have used. Keeps on throwing this error while creating the customer. Here's what i get for example. I have cross checked my functions twice. But the user has all the attributes.
:
"SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (Connection: mysql, SQL: insert into customers (billable_id, billable_type, paddle_id, name, email, trial_ends_at, updated_at, created_at) values (1, App\Models\User, ctm_01j1f4eqj4mv97kgsdpb0w2836, ?, [email protected], ?, 2024-07-09 21:01:04, 2024-07-09 21:01:04))"

 public function checkout(Request $request,$priceId)
   {
       // If your checkout requires auth user
       // Replace this with Auth::user()->checkout($priceId)->returnTo(route('dashboard'))
       $checkout = $request->user()->checkout($priceId)->returnTo(route('dashboard'));

       $checkout = [
           'items' => $checkout->getItems(),
           'custom' => $checkout->getCustomData(),
           'return_url' => $checkout->getReturnUrl(),
       ];

       return \response()->json($checkout);
   }
   ```

### Steps To Reproduce

Steps to reproduce. 
1.) Create a new laravel app. 
2.) Integrate Socialite for logging in your user. 
3.) Integrating Cashier Paddle your products. 
@crynobone
Copy link
Member

Hey there, thanks for reporting this issue.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?

Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@bluzeey
Copy link
Author

bluzeey commented Jul 12, 2024

Hey @crynobone , thanks for responding, I have created the repository for reproducing the bug. You will need though a google app with api keys and also paddle sandbox store. Here's the link : https://github.com/bluzeey/bug-report. The last commit has everything pertaining to the issue i am facing. Feel free to let me know how i can assist further

@crynobone
Copy link
Member

Please refer to https://laravel.com/docs/11.x/queues#jobs-and-database-transactions and the documentation regarding after_commit.

@crynobone
Copy link
Member

Hi there,

Thanks for reporting the problem you are encountering, but it looks like this is a question which may be better suited for a support channel. We only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repository you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

@doncadavona
Copy link
Contributor

doncadavona commented Jul 19, 2024

I encountered the same error too:
image

I found out that there is no name stored in the customer's Paddle dashboard. If I add a name to it manually, it gets resolved.
This is probably caused by some of my customers I registered earlier during development, which I didn't pass a name to paddle checkout before:
https://sandbox-vendors.paddle.com/customers-v2
image

I created a PR for this to be gracefully handled here:
#268

image

@bluzeey
Copy link
Author

bluzeey commented Jul 23, 2024

@doncadavona Apologies, so the way I resolved this was that , I created the customer first and saved it in user. And then created the checkout , that had solved my error.

@doncadavona
Copy link
Contributor

doncadavona commented Aug 1, 2024

Thanks @bluzeey .

For the others, you may run composer update to update Cashier Paddle to 2.5.1 which includes a fix for this issue.

See Merge Request

@bluzeey
Copy link
Author

bluzeey commented Aug 5, 2024

Hey @doncadavona , I had updated the cashier paddle to 2.5.1 , I am facing some other error. But not facing the name to be null

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

No branches or pull requests

3 participants