public static function now($pin, $uid, $method = 'pin')
 {
     $voucher = Voucher::where('pin', $pin)->firstOrFail();
     $rc['voucher_id'] = $voucher->id;
     $rc['recharged_on'] = date('Y-m-d H:i:s');
     $rc['aq_invocked'] = 0;
     $rc['expiration'] = AccessManager::makeExpiry($voucher->validity, $voucher->validity_unit, 'd M Y H:i');
     $rc['time_limit'] = NULL;
     $rc['data_limit'] = NULL;
     if ($voucher->plan_type == 1) {
         //if limited
         $limit = $voucher->limits;
         // $rc['limit_type'] = $limit->limit_type;
         if ($limit->limit_type == 0 || $limit->limit_type == 2) {
             $rc['time_limit'] = $limit->time_limit * constant($limit->time_unit);
         }
         if ($limit->limit_type == 1 || $limit->limit_type == 2) {
             $rc['data_limit'] = $limit->data_limit * constant($limit->data_unit);
         }
     }
     $recharge = Recharge::firstOrNew(['user_id' => $uid]);
     $recharge->fill($rc);
     if (!$recharge->save()) {
         return FALSE;
     }
     $voucher->fill(['user_id' => $uid, 'method' => $method]);
     if (!$voucher->save()) {
         return FALSE;
     }
     return TRUE;
 }
 public static function generate($postData)
 {
     $postData['expires_on'] = AccessManager::makeExpiry($postData['validity'], $postData['validity_unit']);
     return DB::transaction(function () use($postData) {
         for ($i = 0; $i < $postData['count']; $i++) {
             $postData['pin'] = self::_generatePin();
             if (!($coupon = static::create($postData))) {
                 throw new Exception("Voucher Creation Failed.");
             }
             $pins[] = $coupon->pin;
         }
         return $pins;
     });
 }