public function stripe() { $user = User::whereType('client')->get()->random(8); $faker = $this->faker; foreach ($user as $u) { try { $amount = rand(5, 50); $payment = UserPayment::create(['user_id' => $u->id, 'merchant' => 'stripe', 'transaction_number' => rand(1000000, 2000000), 'title' => 'refill', 'amount' => $amount, 'currency' => 'USD']); LogMapper::log('payment', $amount, 'refilled', ['payment_id' => $payment->id, 'merchant' => 'stripe']); NotificationMapper::refilled($payment); } catch (\Exception $e) { dd($e->getTraceAsString()); } } }
public function stripe(Request $request) { $rules = ['amount' => 'required|numeric|min:5|max:1000', 'card_number' => 'required|digits_between:6,21', 'card_holder' => 'required|min:2|max:250', 'card_year' => 'required|numeric|min:1900|max:' . (date('Y') + 10), 'card_month' => 'required|numeric|min:1|max:12', 'card_cvc' => 'required|numeric|min:100|max:999']; $this->validate($request, $rules); $amount = $request->get('amount'); $card_number = $request->get('card_number'); $card_holder = $request->get('card_holder'); $card_year = $request->get('card_year'); $card_month = $request->get('card_month'); $card_cvc = $request->get('card_cvc'); $stripeService = new StripePaymentService(); $card = ['number' => $card_number, 'exp_month' => $card_month, 'exp_year' => $card_year, 'cvc' => $card_cvc, 'name' => $card_holder]; try { $charge = $stripeService->refill($card, $amount, $this->user); LogMapper::log('stripe_success', $amount, $this->user->id, ['response' => $stripeService->response]); } catch (\Exception $e) { LogMapper::log('stripe_error', $e->getMessage(), 'stripe_card', ['user' => $this->user->id, 'card' => $card, 'amount' => $amount]); return Redirect::to('/user/client/billing')->withErrors(['stripe' => 'Failed payment']); } $payment = PaymentMapper::refillFromStripe($this->user, $stripeService); LogMapper::log('payment', $amount, 'refilled', ['payment_id' => $payment->id, 'merchant' => 'stripe']); NotificationMapper::refilled($payment); return Redirect::to('/user/client/billing')->with(['success' => 'We got your payment']); }