/** * Handle an authentication attempt. * * @return Response */ public function getDonations(Request $request) { try { $user = Auth::user(); if (Auth::check()) { if ($user->hasRole('developer')) { $donations = Donation::all(); return view('admin.wedonate.donations')->with('donations', $donations); } else { if ($user->hasRole('owner')) { $donations = Donation::all(); return view('admin.wedonate.donations')->with('donations', $donations); } else { if ($user->hasRole('hr')) { return view('admin.dash'); } else { if ($user->hasRole('donator')) { $donations = Donation::where('user_id', '=', $user->id)->get(); return view('donator.donations')->with('donations', $donations); } } } } } } catch (Exception $e) { throw $e; } }
public function getDonatorDonations(Request $request) { try { $donations = Donation::where('id', Auth::user())->get(); return view('donator.donations')->with('donations', $donations); } catch (Exception $e) { throw $e; } }
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 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; } }