Пример #1
0
 public function getDelete($provider = 'facebook')
 {
     $profile = UserProfile::where('user_id', '=', \Auth::user()->user_id)->where('provider_name', '=', $provider)->delete();
     $this->flashMessage('Sucessfully removed ' . ucfirst($provider) . '.');
     return redirect('/admin/profile');
 }
Пример #2
0
 public function postStripe(Request $request)
 {
     // TODO: batch the updates into one call. Need a somethign that does it all sequentially.
     // TODO: Fix all this. not good to do it all here.
     //Start transaction
     DB::beginTransaction();
     try {
         $cause = Cause::where('id', $request->input('cause'))->first();
         $user = Auth::user();
         Log::debug('A donation has been made by the user: '******' to the cause name: ' . $cause->name);
         $j = User::where('id', '=', 1)->first();
         $payment = new PaymentsStripe();
         $payment->uuid = Uuid::generate(4);
         $payment->status = 'pending';
         $payment->email = $request->input('email');
         $payment->user_uuid = Auth::user()->uuid;
         $payment->cause_uuid = $request->input('cause');
         $payment->amount = $request->input('amount');
         $payment->token_id = $request->input('token_id');
         $payment->save();
         // LETS FREAKING PAY THIS MOOLAH
         $gateway = Omnipay::create('Stripe');
         $gateway->initialize(array());
         $transaction = $gateway->purchase(['amount' => (double) $payment->amount, 'currency' => 'AUD', 'token' => $payment->token_id]);
         $response = $transaction->send();
         if ($response->isSuccessful()) {
             $payment->status = 'paid';
             $payment->charge_id = $response->getTransactionReference();
             $payment->save();
             $donation = new Donation();
             $donation->uuid = Uuid::generate(4);
             $donation->type = 'single';
             $donation->status = 'paid';
             $donation->user_id = Auth::user()->id;
             $donation->cause_id = $cause->id;
             $donation->DGR = $cause->DGR;
             $donation->amount = $payment->amount;
             $donation->processor = 'stripe';
             $donation->payment_id = $payment->id;
             $donation->save();
             $splits = $this->calcDonationSplit($donation->amount);
             // WEDONATE keeps
             $wedonate_funds = WedonateFund::where('type', '=', 'single')->first();
             $amount = $wedonate_funds->amount + $splits->weDonate_keeps;
             $wedonate_funds->amount = $amount;
             $wedonate_funds->save();
             // IDONATE
             $split = new DonationSplit();
             $split->uuid = Uuid::generate(4);
             $split->type = 'iDonate';
             $split->user_id = Auth::user()->id;
             $split->cause_id = $cause->id;
             $split->recipient_type = 'cause';
             $split->amount = $splits->iDonate;
             $split->status = 1;
             $split->donation_id = $donation->id;
             $split->save();
             $cause = Cause::where('id', $cause->id)->first();
             $cause->total_donations += $split->amount;
             $cause->number_of_donations += 1;
             $cause->save();
             // UDONATE REFERRER
             $split = new DonationSplit();
             $split->uuid = Uuid::generate(4);
             $split->type = 'uDonate_referrer';
             $split->user_id = Auth::user()->id;
             if ($user->profile->referrer_id) {
                 $split->recipient_id = $user->profile->referrer_id;
             } else {
                 $split->recipient_id = $j->id;
             }
             $split->recipient_type = 'user';
             $split->amount = $splits->uDonate_referrer;
             $split->status = 1;
             $split->donation_id = $donation->id;
             $split->save();
             // Save the udonate refferer
             $ref = UserProfile::where('user_id', $split->recipient_id)->first();
             $ref->iDonate += $splits->uDonate_referrer;
             $ref->save();
             // UDONATE REFERREE
             $split = new DonationSplit();
             $split->uuid = Uuid::generate(4);
             $split->type = 'uDonate_referree';
             $split->user_id = $user->id;
             $split->recipient_id = $user->id;
             $split->recipient_type = 'self';
             $split->amount = $splits->uDonate_referree;
             $split->status = 1;
             $split->donation_id = $donation->id;
             $split->save();
             $ref = UserProfile::where('user_id', $split->recipient_id)->first();
             $ref->iDonate += $splits->uDonate_referrer;
             $ref->save();
             // update users amount for future REFERRE
             $user->profile->referrer_amount_forward += $split->amount;
             $user->profile->total_donations += $donation->amount;
             $user->profile->donations_count += 1;
             $user->profile->iDonate += $splits->iDonate;
             $user->profile->uDonate += $splits->uDonate;
             $user->profile->weDonate += $splits->weDonate;
             $user->profile->save();
             // weDONATE
             $split = new DonationSplit();
             $split->uuid = Uuid::generate(4);
             $split->type = 'weDonate';
             $split->user_id = $user->id;
             $split->recipient_type = 'everyone';
             $split->amount = $splits->weDonate;
             $split->status = 1;
             $split->donation_id = $donation->id;
             $split->save();
             // Split the weDonate for each user
             $users_count = User::all()->count();
             $split = (double) $splits->weDonate / $users_count;
             DB::table('user_profiles')->increment('iDonate', $split);
             DB::table('user_profiles')->increment('total_donations', $split);
             // Split if for each donation too
             $causes_count = Cause::all()->count();
             $split = (double) $splits->weDonate / $causes_count;
             DB::table('causes')->where('active', 1)->increment('total_donations', $split);
             // TODO: Do rank
             $ranks = UserProfile::all();
             $ranks = $ranks->sortByDesc('total_donations');
             $count = 1;
             foreach ($ranks as $rank) {
                 $rank->ranking = $count;
                 $rank->save();
                 $count++;
             }
             Log::info('Donation paid');
             // If we reach here, then
             // data is valid and working.
             // Commit the queries!
             DB::commit();
             return redirect(route('getDonationSuccess', $payment->uuid));
         } else {
             $message = $response->getMessage();
             Log::debug($message);
             $donation_errors = new PaymentError();
             $donation_errors->uuid = Uuid::generate(4);
             $donation_errors->payment_id = $payment->id;
             $donation_errors->error_message = $message;
             $donation_errors->save();
             $user = Auth::user();
             $data = new \stdClass();
             $data->title = Log::debug('Donation Unsuccessful by the user_id=' . Auth::user()->id);
             Mail::send('emails.donate-result', $data, function ($m) {
                 $m->to($user->email, $user->name)->subject('weDonate - Donation Unsuccessful!');
             });
             // If we reach here, then
             // data is valid and working.
             // Commit the queries!
             DB::commit();
             return redirect(route('getDonationFailure', $payment->uuid));
         }
     } catch (Exception $e) {
         DB::rollback();
         throw $e;
     }
 }
 public function getUserRemove(Request $request, $uuid)
 {
     try {
         $user = User::where('uuid', $uuid)->first();
         $profile = UserProfile::where('user_id', $user->id)->delete();
         $user = User::where('uuid', $uuid)->delete();
         return redirect(route('getUsers'))->withFlashMessage('User Deleted Successfully.');
     } catch (Exception $e) {
         throw $e;
     }
 }
Пример #4
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request $request
  * @param  int $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $user = User::findOrFail($id);
     $user->fill($request->all());
     $user->save();
     if (Input::file('image') and Input::file('image')->isValid()) {
         $destinationPath = 'uploads/users/user_' . $user->id . '/';
         // upload path
         $extension = Input::file('image')->getClientOriginalExtension();
         // getting image extension
         $fileName = rand(11111, 99999) . '.' . $extension;
         // renameing image
         // Metemos la foto en el sistema
         Input::file('image')->move($destinationPath, $fileName);
         // uploading file to given path
         // Borramos las fotos del sistema
         $photos = UserProfile::where('user_id', $user->id)->get();
         if ($photos) {
             File::delete(array_pluck($photos, 'path'));
         }
         // Borramos las fotos de la BD
         UserProfile::where('user_id', $user->id)->delete();
         // Metemos la foto en la BD
         UserProfile::create(['path' => $destinationPath . $fileName, 'user_id' => $user->id]);
         //return redirect('/uploads/'.$fileName);
     }
     return redirect()->back();
 }