Exemplo n.º 1
0
 /**
  * Handler to be executed after client subscription.
  *
  * @param ConnectionInterface $connection
  * @param Topic $topic
  * @return void
  */
 public function subscribe(ConnectionInterface $connection, Topic $topic)
 {
     parent::subscribe($connection, $topic);
     $driver = EloquentDriverRepository::find($connection->userId);
     $to = Carbon::createFromTimestamp(Carbon::now()->setTimezone(\Config::get('app.timezone'))->format('U'));
     $from = Carbon::createFromTimestamp(Carbon::now()->setTimezone(\Config::get('app.timezone'))->format('U') - 60 * 60 * \Config::get('notification_hours'));
     $notifications = $driver->with_notifications($from, $to);
     $connection->event($topic->getId(), $notifications);
 }
Exemplo n.º 2
0
 /**
  * @param $commission
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function billing($commission)
 {
     try {
         \DB::beginTransaction();
         if ($driver = EloquentDriverRepository::find($commission->driver_id)) {
             $notification = [];
             if ($driver->notify_billing) {
                 $notification['driver_id'] = $commission->driver_id;
                 $notification['billing'] = $commission->commissions . ' ' . $commission->currency;
                 if ($notification = NotificationRepository::create($notification)) {
                     \DB::commit();
                     return $this->setStatusCode(201)->respondWithItem($notification);
                 }
             }
         }
         return true;
     } catch (ValidationException $e) {
         return $this->errorWrongArgs($e->getErrors());
     }
 }
Exemplo n.º 3
0
 /**
  * Paypal subscription ipn handler.
  */
 public function subscribe()
 {
     try {
         \DB::beginTransaction();
         $listener = new Listener();
         $verifier = new CurlVerifier();
         $ipn = \Input::all();
         $ipnMessage = new Message($ipn);
         $verifier->setIpnMessage($ipnMessage);
         $verifier->setEnvironment(\Config::get('paxifi.paypal.environment'));
         $listener->setVerifier($verifier);
         $listener->listen(function () use($listener, $ipn, &$response) {
             // on verified IPN (everything is good!)
             $resp = $listener->getVerifier()->getVerificationResponse();
             // Find paid driver (custom is driver_id).
             if ($driver = EloquentDriverRepository::find(\Input::get('custom'))) {
                 \Event::fire('paxifi.paypal.subscription.' . $ipn['txn_type'], [$driver, $ipn]);
                 \DB::commit();
             }
         }, function () use($listener) {
             // on invalid IPN (somethings not right!)
             $report = $listener->getReport();
             $resp = $listener->getVerifier()->getVerificationResponse();
             return $this->setStatusCode(400)->respondWithError('Subscription failed.');
         });
     } catch (\RuntimeException $e) {
         return $this->setStatusCode(400)->respondWithError($e->getMessage());
     } catch (\Exception $e) {
         return $this->errorInternalError();
     }
 }