Пример #1
0
 public function redirectToVendorPlan()
 {
     if (Auth::guest()) {
         flash()->error('Your session is timed out. Please login and confirm again.');
         return Auth::guest('/login');
     }
     /*
      * View Plan for subscription
      * Using laravel cashier for plan retrieval
      * Method call from Route::get('/dashboard/vendor/plan', [ 'uses' => 'UserController@redirectToVendorPlan', 'as' => 'vendor.plan' ]);
      * */
     //$plan = StripePlan::where('active','=','1')->get();
     //$subscribed_plan =Subscription::where('user_id', Auth::user()->id)->get()->first()->name;
     $allplan = StripePlan::with('planFeature')->where('active', '=', '1')->get();
     //dd($allplan);
     $coupon_all = StripeCoupon::all();
     $plan_collect = [];
     foreach ($allplan as $plan) {
         if ($plan->interval_count > 1) {
             $plan->interval = "Every " . $plan->interval_count . " " . $plan->interval . "s";
         }
         $coupon_information = [];
         if ($plan->coupon_id != null) {
             foreach ($coupon_all as $coupon_single) {
                 if ($plan->coupon_id == $coupon_single->coupon_id) {
                     $coupon_information['coupon_name'] = $coupon_single->coupon_name;
                     $coupon_information['coupon_id'] = $coupon_single->coupon_id;
                     if ($coupon_single->percent_off != null) {
                         $coupon_information['discount'] = $coupon_single->percent_off . "%";
                         $coupon_information['discount_price'] = $plan->amount - $plan->amount * $coupon_single->percent_off / 100;
                     } else {
                         $coupon_information['discount'] = $coupon_single->amount_off / 100 . "/" . $coupon_single->currency;
                         $coupon_information['discount_price'] = $plan->amount - $coupon_single->amount_off / 100;
                     }
                     $coupon_information['currency'] = $coupon_single->currency;
                     $coupon_information['duration'] = $coupon_single->duration;
                     if ($coupon_single->duration == 'repeating') {
                         $coupon_information['duration'] = $coupon_single->duration_in_months . " Months";
                     }
                     $coupon_information['max_redemptions'] = $coupon_single->max_redemptions;
                     $coupon_redeem = Carbon::parse($coupon_single->redeem_by);
                     $coupon_information['redeem_by'] = $coupon_redeem->toFormattedDateString();
                 }
             }
         }
         $plan->coupon = $coupon_information;
         $plan_collect[] = $plan;
     }
     $allplan = collect($plan_collect);
     $user = Auth::user();
     $user_subscriptions = User::with('subscriptions')->whereId($user->id)->first();
     return view('plan', compact('allplan'))->with('user', $user_subscriptions)->with('authenticated', Auth::check());
 }
Пример #2
0
 public function deletePlan(Request $plan_id)
 {
     $this->validate($plan_id, ['plan' => 'required']);
     $plan_id = $plan_id->plan;
     //$plan_id = Crypt::decrypt($plan_id->confirm_action);
     //if($plan_id == null) //Todo List: Abort or redirect back same page with meaning full message.
     //Stripe::setApiKey(getenv('STRIPE_SECRET'));
     //Plan::retrieve($plan_id)->delete(); // Delete From Remote Database
     $stripe_plan = StripePlan::where('plan_id', '=', $plan_id)->first();
     $plan_name = $stripe_plan->name;
     $plan_name = $plan_name . "(Removed)";
     StripePlan::where('plan_id', '=', $plan_id)->update(['name' => $plan_name, 'active' => 0]);
     // view generate
     $allPlan = StripePlan::with('planFeature')->get();
     $plan_collect = [];
     foreach ($allPlan as $plan) {
         if ($plan->interval_count > 1) {
             $plan->interval = "Every " . $plan->interval_count . " " . $plan->interval . "s";
         }
         $plan_collect[] = $plan;
     }
     $sln = 1;
     $allPlan = collect($plan_collect);
     $allPlan = compact('allPlan', 'sln');
     return response()->view('super-admin.includes.plan-dom', $allPlan)->header('Content-Type', 'html');
     //StripePlan::where('plan_id','=',$plan_id)->delete(); // Delete From local database
     //return Response::json([true]);
     //return redirect()->route('admin::viewPlan')->with(['success'=>'Successfully Deleted.']);
 }
Пример #3
0
 public function getFeature($plan_id, $feature_name)
 {
     if ($plan_id != null) {
         $feature = StripePlan::with('planFeature')->where('plan_id', '=', $plan_id)->first();
         return in_array($feature_name, array_column(isset($feature) ? $feature->planFeature->toArray() : [], 'feature_name'));
     }
     return false;
 }