app/Http/Controllers/PlansController.php
/*
        Error: Please input an ICCID.
        Error: Invalid ICCID. Verify that you have input the ICCID correctly.
        Error: Please read and agree to the TERMS and CONDITIONS.
        Error: Invalid ICCID. Verify you have not already used this ICCID in another plan and that you have input the ICCID correctly.
    */
Please input an ICCID.
Error: Invalid ICCID. Verify that you have input the ICCID correctly.
Error: Please read and agree to the TERMS and CONDITIONS.
Error: Invalid ICCID. Verify you have not already used this ICCID in another plan and that you have input the ICCID correctly.
Please input an ICCID . Error : Invalid ICCID . Verify that you have input the ICCID correctly . Error : Please read and agree to the TERMS and CONDITIONS . Error : Invalid ICCID . Verify you have not already used this ICCID in another plan and that you have input the ICCID correctly .
public function postPlanAdd(Request $request) {
        $user = Auth::user();
        $user_id = $user->id;
        if (!$request->iccid) {
            if (env('APP_BUSINESS_MODE') == 'rent') {
                session()->flash('danger', 'Please input an ICCID or EZCode.');
            } else {
                session()->flash('danger', $this->ts('input_ICCID'));
            }
            return redirect()->back();
        }
        $iccid = $request->iccid;
        $style = 'normal';
        $status = 'deactive';
        $region = env('APP_REGION');
        if (env('APP_BUSINESS_MODE') == 'rent') {
            if (!is_numeric($iccid)) {
                $is_ezcode = 1;
            } else {
                $is_ezcode = 0;
            }
        }
        if (env('APP_CHECK_TERMS')){
            if (!$request['agree-terms']) {
               session()->flash('danger', $this->ts('agree_TERMS'));
               return redirect()->back();
            }
        }
        $plan = DB::table('plans')->where('iccid', $iccid)->first();
        if ($plan) {
            if (env('APP_BUSINESS_MODE') == 'rent') {
                if ($is_ezcode) {
                    session()->flash('danger', 'This EZCode has already been registered.');
                } else {
                    session()->flash('danger', 'This ICCID has already been registered.');
                }
            } else {
                session()->flash('danger', $this->ts('ICCID_had_registered'));
            }
            return redirect()->back();
        }
        if (env('APP_BUSINESS_MODE') == 'rent'){
            if (is_numeric($iccid)) {
                if (env('APP_CHECK_SIM')){
                    $sim = DB::table('sims')->where('iccid', $iccid)->first();
                    if (!$sim) {
                        session()->flash('danger', $this->ts('Invalid ICCID'));
                        return redirect()->back();
                    }
                    $style = $sim->style; 
                    $region = $sim->region;
                }
            } else {
                $ezcode = DB::table('ezcode')->where('ezcode', $iccid)->first();
                if (!$ezcode) {
                    session()->flash('danger', $this->ts('Invalid EZCode'));
                    return redirect()->back();
                }
                $style = $ezcode->style; 
            }
        } else {
            if (env('APP_CHECK_SIM')){
                $sim = DB::table('sims')->where('iccid', $iccid)->first();
                if (!$sim) {
                    session()->flash('danger', $this->ts('Invalid ICCID'));
                    return redirect()->back();
                }
                $style = $sim->style; 
                $region = $sim->region;
            }
        }
        if (env('APP_PLAN') == 'test') {
            $style = 'test';
        }
        if ($style == 'test') {
            $status = 'active';
            if (env('APP_PLAN_POINTS')) {
                $points = env('APP_PLAN_POINTS');
            } else {
                $points = 5000;
            }
            if (env('APP_PLAN_MB')) {
                $plans = env('APP_PLAN_MB');
            } else {
                $plans = 1000; 
            }
        } else {
            $style = 'normal';
            $status = 'deactive';
            $points = 0;
            $plans = 0;
        }
 else {
        $plan = Plan::create([
            'iccid' => $iccid,
            'user_id' => $user_id,
            'region' => $region,
            'style' => $style,
            'status' => $status,
            'points' => $points,
            'plans' => $plans,
        ]);
        if ($style == 'test') {
            $data['sel_account_tab'] = 'plans';
            Auth::user()->update($data);
            session()->flash('success', 'Create Success');
            return redirect()->route('account.profile');
        } else {
            $mode = 'create';
            return view('plans.create', compact('user', 'plan', 'mode'));
        }
    }
public function postPlanAdd ( Request $ request ) { $ user = Auth :: user ( ) ; $ user_id = $ user -> id ; if ( ! $ request -> iccid ) { if ( env ( 'APP_BUSINESS_MODE' ) == 'rent' ) { session ( ) -> flash ( 'danger' , 'Please input an ICCID or EZCode.' ) ; } else { session ( ) -> flash ( 'danger' , $ this -> ts ( 'input_ICCID' ) ) ; } return redirect ( ) -> back ( ) ; } $ iccid = $ request -> iccid ; $ style = 'normal' ; $ status = 'deactive' ; $ region = env ( 'APP_REGION' ) ; if ( env ( 'APP_BUSINESS_MODE' ) == 'rent' ) { if ( ! is_numeric ( $ iccid ) ) { $ is_ezcode = 1 ; } else { $ is_ezcode = 0 ; } } if ( env ( 'APP_CHECK_TERMS' ) ) { if ( ! $ request [ 'agree-terms' ] ) { session ( ) -> flash ( 'danger' , $ this -> ts ( 'agree_TERMS' ) ) ; return redirect ( ) -> back ( ) ; } } $ plan = DB :: table ( 'plans' ) -> where ( 'iccid' , $ iccid ) -> first ( ) ; if ( $ plan ) { if ( env ( 'APP_BUSINESS_MODE' ) == 'rent' ) { if ( $ is_ezcode ) { session ( ) -> flash ( 'danger' , 'This EZCode has already been registered.' ) ; } else { session ( ) -> flash ( 'danger' , 'This ICCID has already been registered.' ) ; } } else { session ( ) -> flash ( 'danger' , $ this -> ts ( 'ICCID_had_registered' ) ) ; } return redirect ( ) -> back ( ) ; } if ( env ( 'APP_BUSINESS_MODE' ) == 'rent' ) { if ( is_numeric ( $ iccid ) ) { if ( env ( 'APP_CHECK_SIM' ) ) { $ sim = DB :: table ( 'sims' ) -> where ( 'iccid' , $ iccid ) -> first ( ) ; if ( ! $ sim ) { session ( ) -> flash ( 'danger' , $ this -> ts ( 'Invalid ICCID' ) ) ; return redirect ( ) -> back ( ) ; } $ style = $ sim -> style ; $ region = $ sim -> region ; } } else { $ ezcode = DB :: table ( 'ezcode' ) -> where ( 'ezcode' , $ iccid ) -> first ( ) ; if ( ! $ ezcode ) { session ( ) -> flash ( 'danger' , $ this -> ts ( 'Invalid EZCode' ) ) ; return redirect ( ) -> back ( ) ; } $ style = $ ezcode -> style ; } } else { if ( env ( 'APP_CHECK_SIM' ) ) { $ sim = DB :: table ( 'sims' ) -> where ( 'iccid' , $ iccid ) -> first ( ) ; if ( ! $ sim ) { session ( ) -> flash ( 'danger' , $ this -> ts ( 'Invalid ICCID' ) ) ; return redirect ( ) -> back ( ) ; } $ style = $ sim -> style ; $ region = $ sim -> region ; } } if ( env ( 'APP_PLAN' ) == 'test' ) { $ style = 'test' ; } if ( $ style == 'test' ) { $ status = 'active' ; if ( env ( 'APP_PLAN_POINTS' ) ) { $ points = env ( 'APP_PLAN_POINTS' ) ; } else { $ points = 5000 ; } if ( env ( 'APP_PLAN_MB' ) ) { $ plans = env ( 'APP_PLAN_MB' ) ; } else { $ plans = 1000 ; } } else { $ style = 'normal' ; $ status = 'deactive' ; $ points = 0 ; $ plans = 0 ; } $ plan = Plan :: create ( [ 'iccid' => $ iccid , 'user_id' => $ user_id , 'region' => $ region , 'style' => $ style , 'status' => $ status , 'points' => $ points , 'plans' => $ plans , ] ) ; if ( $ style == 'test' ) { $ data [ 'sel_account_tab' ] = 'plans' ; Auth :: user ( ) -> update ( $ data ) ; session ( ) -> flash ( 'success' , 'Create Success' ) ; return redirect ( ) -> route ( 'account.profile' ) ; } else { $ mode = 'create' ; return view ( 'plans.create' , compact ( 'user' , 'plan' , 'mode' ) ) ; } }
Error: Please input an ICCID.
Error : Please input an ICCID .
//{"_token":"xxxx","mode":"new","iccid":null,"submit-new-plan":"update"} //{"_token":"xxxx","mode":"new","iccid":null,"agree-terms":"on","submit-new-plan":"update"} /* check ICCID */ // $result = $this->validate($request, [ //    'iccid' => 'required|unique:plans|max:20', // ]); // session()->flash('danger', 'Please input an ICCID.'); // session()->flash('danger', 'Error: Please read and agree to the TERMS and CONDITIONS.'); /* search Plan */ //session()->flash('danger', 'Invalid ICCID. (** Verify you have not already used this ICCID in another plan and that you have input the ICCID correctly.)'); // session()->flash('danger', 'ICCID had used.'); // session()->flash('danger', 'This ICCID has already been registered.'); /* search SIM */ // session()->flash('danger', 'Invalid ICCID.'); // $region = $sim->region; // us, ca, eu, au, cn, tw // test, normal // test, normal // $region = $sim->region; // session()->flash('danger', 'Invalid ICCID.'); // $region = $sim->region; // us, ca, eu, au, cn, tw // test, normal // $style = 'test'; // MB // $region = env('APP_REGION'); // if ($region == 'au') { //     $style = 'normal'; //     $status = 'deactive'; //     $points = 0; //     $plans = 0; // } else if ($region == 'de') { //     $style = 'normal'; //     $status = 'deactive'; //     $points = 0; //     $plans = 0; // } else if ($region == 'tw') { //     $style = 'test'; //     $status = 'active'; //     $points = 100000; //     $plans = 10000; // } else if ($region == 'cn') { //     $style = 'test'; //     $status = 'active'; //     $points = 100000; //     $plans = 10000; // } else { //     $style = 'normal'; //     $status = 'deactive'; //     $points = 0; //     $plans = 0; // } /* Stripe - create customer id */ //        if ($request->mode == 'new') { //            $stripeToken = $_POST['stripeToken']; //            if (!$user->stripe_id) { //                // $ret = $user->createAsStripeCustomer($stripeToken); //                $ret = $user->createAsStripeCustomer($stripeToken, [ //                    // 'currency' => 'usd', //                ]); //            } //        } /* Stripe - subscribe plan */ //        $subscription_name = $iccid; //'89860117851014783481' //        $plan_id = 'plan_5000_1m_us'; //        // $plan_id = 'plan_100_1d_us'; //        if (!$request['auto-bill']) { //            $user->newSubscription($subscription_name, $plan_id)->create()->cancel(); //        } else { //            $user->newSubscription($subscription_name, $plan_id)->create(); //        } //        // $user->subscription($subscription_name)->cancel(); /* create Plan */ ////$ret = $this->m2m_iccid_active('89610185002185155463'); ////$ret = $this->m2m_iccid_deactive('89610185002185155463'); //$ret = $this->m2m_iccid_active($iccid); // if ($user->permission == 2) { //     $mode = 'create'; //     return view('plans.create', compact('user', 'plan', 'mode')); // } else { //     $data['sel_account_tab'] = 'plans'; //     Auth::user()->update($data); //     session()->flash('success', 'Create Success'); //     return redirect()->route('account.profile'); // }