Ejemplo n.º 1
0
 public function handleCharge(Request $request)
 {
     // Create the charge on Stripe's servers - this will charge the user's card
     $amount = $request->amount;
     //The user gets to keep 95% of the transaction. Stripe gets 2.9% + $0.30, I keep the rest. $$$$$
     $application_fee = ($amount - ($amount * 0.029 + 0.3) - 0.95 * $amount) * 100;
     try {
         $user = \App\User::find($request->user_id);
         \Stripe\Charge::create(array("amount" => $amount * 100, "currency" => "usd", "source" => $request->token, "description" => $request->description, 'destination' => $user->stripeAccount->stripe_id, 'application_fee' => $application_fee));
         \App\Charge::Create(['user_id' => $user->id, 'amount' => $amount]);
         event(new \App\Events\ChargeSucceeded($request->email, $user));
         return response()->json(['status' => 'Payment Succeeded!']);
     } catch (\Stripe\Error\Card $e) {
         // The card has been declined
         return response()->json(['status' => 'Payment Declined!']);
     }
 }