Example #1
0
 /**
  * Update the end subscription date of the user.
  *
  * @param array $custom The custom data passed to Paypal.
  *
  * @return bool|\App\Model\Entity\User
  */
 protected function _updateUser(array $custom)
 {
     $this->_controller->loadModel('Users');
     $user = $this->_controller->Users->find()->where(['id' => $custom['user_id']])->first();
     if (!$user) {
         Log::error(__('This user does not exist.'), 'paypal');
         return false;
     }
     if ($user->premium) {
         $this->_action = 'extend';
         $end = $user->end_subscription;
         $date = new Time($end);
     } else {
         $date = new Time();
     }
     $date->addMonths($custom['period']);
     $data = ['end_subscription' => $date];
     $this->_controller->Users->patchEntity($user, $data);
     $this->_controller->Users->save($user);
     return $user;
 }