Example #1
0
 public static function getMinWithdraw(User $user)
 {
     $min = 50;
     $coupon = CouponMapper::byCode('ADD25USD');
     if ($coupon) {
         if (CouponMapper::usedByUser($user, $coupon)) {
             if (!CouponMapper::paidByUser($user, $coupon)) {
                 $min = $min + 25;
             }
         }
     }
     return $min;
 }
Example #2
0
 public function withdraw(Request $request)
 {
     $min = PaymentMapper::getMinWithdraw($this->user);
     $rules = ['amount' => 'required|numeric|min:' . $min . '|max:1000', 'account' => 'required|email'];
     $this->validate($request, $rules);
     $amount = floatval($request->get('amount'));
     if ($amount > $this->user->availableBalance()) {
         return redirect('/user/twitcher/billing')->withErrors(['amount' => 'You have no such money']);
     }
     $account = $request->get('account');
     PaymentMapper::withdrawPaypalPrepare($this->user, $account, $amount);
     NotificationMapper::withdraw($this->user, $amount, 'USD', 'paypal', $account);
     LogMapper::log('withdraw', $this->user->id, 'request', ['account' => $account, 'merchant' => 'paypal', 'amount' => $amount]);
     $coupon = CouponMapper::byCode('ADD25USD');
     if ($coupon) {
         if (!CouponMapper::paidByUser($this->user, $coupon)) {
             CouponMapper::pay($this->user, $coupon);
         }
     }
     return redirect('/user/twitcher/billing')->with(['success' => 'You required withdrawal']);
 }