Support the ongoing development of Laravel.io →
Requests Input Packages

Subscription not working at the time user registration. I echoed stripe token which is perfect. but some how the subscription not working. this is my controller code:

 public function postStore() {


        $sid = Input::get('id');

        $rules = array(
            'first_name' => 'required',
            'last_name' => 'required',
            'email' => 'required'
        );

        if (isset($sid)) {
            $rules['password'] = 'confirmed|min:6';
        } else {
            $rules['password'] = 'required|confirmed|min:6';
        }

        $validation = Validator::make(Input::all(), $rules);

        if (!$validation->passes()) {
            if (isset($sid)) {
                return Redirect::to('users/edit/' . $sid)->withErrors($validation)->withInput();
            } else {
                return Redirect::to('users/create')->withErrors($validation)->withInput();
            }
        }

        $first_name = Input::get('first_name');
        $last_name = Input::get('last_name');
        $email = Input::get('email');
        $password = Input::get('password');
        $role = 4;
        $activated = true;
        $subscriptiont_type = Input::get('subscriptiont_type');

        if (isset($sid)) {
            // Edit existing
            try {
                $user = Sentry::findUserById($sid);

                $user->email = $email;
                if ($password != '') {
                    $user->password = $password;
                }
                $user->first_name = $first_name;
                $user->last_name = $last_name;
                $user->activated = $activated;

                // Find user's group
                $old_group = $user->getGroups()->first();
                $new_group = Sentry::findGroupById($role);

                // Assign the group to the user
                if ($old_group->id != $new_group->id) {
                    $user->removeGroup($old_group);
                    $user->addGroup($new_group);
                }

                // Update the user
                if (!$user->save()) {
                    $errors = new \Illuminate\Support\MessageBag;
                    $errors->add(
                            'editError', "The user cannot be updated due to some problem. Please try again."
                    );
                    return Redirect::to('users/edit/' . $sid)->withErrors($errors)->withInput();
                }
            } catch (Exception $exp) {
                $errors = new \Illuminate\Support\MessageBag;
                $errors->add(
                        'editError', "The user cannot be found because it does not exist or may have been deleted."
                );
                return Redirect::to('redminportal::pages/404');
            }
        } else {
            try {
                // Create the user
                $user = Sentry::getUserProvider()->create(array(
                    'email' => $email,
                    'password' => $password,
                    'first_name' => $first_name,
                    'last_name' => $last_name,
                    'activated' => $activated,
                ));

                // Find the group using the group id
                $adminGroup = Sentry::getGroupProvider()->findById($role);

                // Assign the group to the user
                $user->addGroup($adminGroup);

                $user->subscription('basic')->create(Input::get('stripeToken'));
                
            } catch (Exception $exp) {
                $errors = new \Illuminate\Support\MessageBag;
                $errors->add(
                        'editError', "The user cannot be created due to some problem. Please try again."
                );
                return Redirect::to('users/create')->withErrors($errors)->withInput();
            }
        }

        return Redirect::to('/');
    }
Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

ulshamim ulshamim Joined 17 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.