Ejemplo n.º 1
0
 /**
  * Returns the available balance for this Account.
  *
  * @return Price
  *
  * @throws OperationResultException
  * @throws RequestException
  */
 public function getBalance()
 {
     $operationName = Operations::GET_ACCOUNT_BALANCE;
     $operationResultName = OperationResults::GET_ACCOUNT_BALANCE_RESULT;
     $request = new Request($operationName);
     /** @var \SimpleXMLElement|bool $operationResult */
     $operationResult = $request->execute()->retrieveResult($operationResultName);
     return Price::parseFromXml($operationResult->AvailableBalance);
 }
Ejemplo n.º 2
0
 /**
  * Sends a message to multiple Workers in one API call.
  *
  * @param Worker[]  $workers An array of maximum 100 Workers.
  * @param string    $subject The subject for the notification email.
  * @param string    $message The message. HTML markup is not allowed.
  *
  * @return bool|array Returns 'true' on success for all Workers. Returns an
  * array of error messages with the respective Worker ID as key otherwise.
  *
  * @throws \InvalidArgumentException If $subject and $message are not valid,
  * or there were more than 100 Workers to notify.
  * @throws OperationResultException
  * @throws RequestException
  */
 public static function sendBulkMessage(array $workers, $subject, $message)
 {
     self::validateMessage($subject, $message);
     if (count($workers) > 100) {
         throw new \InvalidArgumentException('$workers expects maximum 100 Workers');
     }
     $operationName = Operations::NOTIFY_WORKERS;
     $operationResultName = OperationResults::NOTIFY_WORKERS_RESULT;
     $data = array('Subject' => $subject, 'MessageText' => $message);
     $i = 0;
     foreach ($workers as $worker) {
         $i++;
         $data["WorkerId.{$i}"] = $worker->getId();
     }
     $request = new Request($operationName, $data);
     /** @var \SimpleXMLElement|bool $operationResult */
     $operationResult = $request->execute()->retrieveResult($operationResultName);
     $fails = array();
     if ($operationResult instanceof \SimpleXMLElement && property_exists($operationResult, 'NotifyWorkersFailureStatus')) {
         foreach ($operationResult->NotifyWorkersFailureStatus as $failure) {
             $wId = (string) $failure->WorkerId;
             $fails[$wId] = (string) $failure->NotifyWorkersFailureMessage;
         }
     }
     foreach ($workers as $worker) {
         $worker->validated = !array_key_exists($worker->getId(), $fails);
     }
     if (count($fails)) {
         return $fails;
     }
     return $operationResult;
 }