public function member(StripeBilling $billing)
 {
     $customerId = Auth::user()->customer_id;
     $card = null;
     if (!empty($customerId)) {
         $card = $billing->retrieveCard($customerId);
     }
     $planId = Auth::user()->plan_id;
     $plan = MembershipPlan::findOrFail($planId);
     return view('dashboard.index', ['card' => $card, 'membershipPlan' => $plan]);
 }
 public function postDonate($type, Request $request, StripeBilling $billing, Email $mailer, ReceiptMailer $receipt)
 {
     $this->validate($request, ['first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email', 'amount' => 'required|integer']);
     $amount = str_replace('$', '', $request->get('amount'));
     $amount = round($amount) * 100;
     try {
         $charge = $billing->donate(array('amount' => $amount, 'email' => $request->get('email'), 'stripe-token' => $request->get('stripe-token')));
     } catch (\Exception $e) {
         Flash::danger($e->getMessage());
         return redirect()->refresh();
     }
     if (!empty($charge['created'])) {
         if (empty($request->get('anonymous'))) {
             $data = ['charge_id' => $charge['id'], 'name' => $request->get('first_name') . ' ' . $request->get('last_name'), 'email' => $request->get('email'), 'company' => $request->get('company'), 'street_address' => $request->get('address1') . ' ' . $request->get('address2'), 'city' => $request->get('city'), 'state' => $request->get('state_province'), 'zip' => $request->get('postal_code'), 'amount' => $amount];
             Donation::create($data);
             $data['type'] = $type;
             $data['view'] = 'emails.donations.notification';
             $data['recipient'] = env('MEMBERSHIP_EMAIL');
             $data['subject'] = 'Donation from ' . $request->get('first_name') . ' ' . $request->get('last_name');
             $mailer->send($data);
             $receipt->sendDonationReceipt($data);
         }
     }
     Flash::success('Thank you for your generosity. You will receipt your receipt via email.');
     return redirect()->home();
 }
 public function postChangePlan(Request $request, StripeBilling $billing)
 {
     $customerId = Auth::user()->customer_id;
     $planChanged = false;
     if (!empty($customerId)) {
         $newPlan = MembershipPlan::where('slug', $request->get('membership_plan'))->firstOrFail();
         $planChanged = $billing->updatePlan($customerId, $newPlan->slug);
         $user = Auth::user();
         $user->plan_id = $newPlan->id;
         $user->save();
     }
     if ($planChanged) {
         Flash::success('Your plan was successfully changed. You have been billed at the new rate.');
     } else {
         Flash::danger('We have no card on file for you.');
     }
     return redirect('dashboard');
 }