/** * Handles a payment. * * @param App/Http/Requests/DonationRequest $request * @return Response */ public function postIndex(DonationRequest $request) { $errors = []; $fakeUser = false; $user = $this->user; $input = Input::all(); // Build our \App\Payment model. $payment = ['customer' => $user->user_id, 'attribution' => $input['attribution'], 'ip' => $request->getClientIp(), 'amount' => $input['amount'] * 100, 'currency' => "usd", 'subscription' => NULL]; // Handle input depending on the type of payment. // Stripe does subscriptions and charges differently. switch ($input['payment']) { case "once": $tx = ['description' => "Infinity Next Dev", 'source' => $input['stripeToken'], 'receipt_email' => $input['email']]; $receipt = $user->charge($payment['amount'], $tx); break; case "monthly": $tx = ['description' => "Infinity Next Dev", 'source' => $input['stripeToken'], 'email' => $input['email']]; $receipt = $user->subscription("monthly-{$input['amount']}")->create($input['stripeToken'], $tx); $payment['subscription'] = "monthly-{$input['amount']}"; break; } if ($receipt !== false) { // Record our payment. // This stores no identifying information, // besides an optional user ID. Payment::create($payment)->save(); } else { $errors[] = "Your card failed to process and has not been charged."; } if ($request->ajax()) { return response()->json(['amount' => count($errors) ? false : "\$" . $payment['amount'] / 100, 'errors' => $errors]); } else { return $this->view(static::VIEW_DONATE); } }
public function update(Donations $donations, DonationRequest $request) { $donations->update($request->all()); return redirect('donations'); }
/** * Handles a payment. * * @param App/Http/Requests/DonationRequest $request * @return Response */ public function postIndex(DonationRequest $request) { $errors = []; $fakeUser = false; $user = $this->user; $input = Input::all(); // Build our \App\Payment model. $payment = ['customer' => $user->user_id, 'attribution' => $input['attribution'], 'payment_ip' => $request->getClientIp(), 'amount' => $input['amount'] * 100, 'currency' => "usd", 'subscription' => NULL]; // Handle input depending on the type of payment. // Stripe does subscriptions and charges differently. switch ($input['payment']) { case "once": /* Stripe $tx = [ 'description' => "Infinity Next Dev", 'source' => $input['nonce'], 'receipt_email' => $input['email'], ]; */ $tx = ['amount' => $payment['amount'] / 100, 'paymentMethodNonce' => $input['nonce'], 'options' => ['submitForSettlement' => true]]; $receipt = $user->charge($payment['amount'], $tx); break; /* case "monthly": Stripe $tx = [ 'description' => "Infinity Next Dev", 'source' => $input['nonce'], 'email' => $input['email'], ]; $receipt = $user->subscription("monthly-{$input['amount']}")->create($input['nonce'], $tx); $tx = [ 'paymentMethodNonce' => $input['nonce'], 'email' => $input['email'], ]; $receipt = $user->subscription("monthly-{$input['amount']}")->create($input['nonce'], $tx); $payment['subscription'] = "monthly-{$input['amount']}"; break; */ } if ($receipt instanceof \Braintree_Result_Error) { $errors[] = $receipt->message; $receipt = false; } if ($receipt !== false) { if (env('APP_DEBUG') === false || env('APP_ENV', 'local') !== "production") { // Record our payment. // This stores no identifying information, // besides an optional user ID. Payment::create($payment)->save(); } } else { $errors[] = "Your card failed to process and has not been charged."; } if ($request->ajax()) { return response()->json(['amount' => count($errors) ? false : "\$" . $payment['amount'] / 100, 'errors' => $errors]); } else { return $this->view(static::VIEW_DONATE); } }