Пример #1
0
 /**
  * Get the current discount for the given user.
  *
  * @param  Request  $request
  * @param  string  $userId
  * @return Response
  */
 public function current(Request $request, $userId)
 {
     $user = Spark::user()->where('id', $userId)->firstOrFail();
     if ($coupon = $this->coupons->forBillable($user)) {
         return response()->json($coupon->toArray());
     }
 }
 /**
  * Redeem the given coupon code.
  *
  * @param  Request  $request
  * @return Response
  */
 public function redeem(Request $request)
 {
     $this->validate($request, ['coupon' => 'required']);
     // We will verify that the coupon can actually be redeemed. In some cases even
     // valid coupons can not get redeemed by an existing user if this coupon is
     // running as a promotion for brand new registrations to the application.
     if (!$this->coupons->canBeRedeemed($request->coupon)) {
         return response()->json(['coupon' => ['This coupon code is invalid.']], 422);
     }
     Spark::interact(RedeemCoupon::class, [$request->user(), $request->coupon]);
 }