src/Soap/TurboSmsSoapAdapter.php
private function processResultMessages(Message $message, array $recipients, $resultMessages): ResultCollection
    {
        if (is_scalar($resultMessages)) {
            $key = $this->responseParser->parse($resultMessages);

            if ($key === 'signature_not_allowed') {
                throw new SenderNameNotAllowedException(sprintf(
                    'The signature (sender) "%s" not allowed.',
                    $message->getSender()
                ));
            } elseif ($key === 'signature_invalid') {
                throw new InvalidSenderNameException(sprintf(
                    'Invalid signature (sender): %s',
                    $message->getSender()
                ));
            }

            throw new SendSmsException(sprintf(
                'Cannot resolve the error for sending SMS. Error: %s',
                $resultMessages
            ));
        }

        $sendResult = $resultMessages[0];
        $sendResultKey = $this->responseParser->parse($sendResult);

        if ($sendResultKey === 'missing_required_parameters') {
            throw new MissingRequiredParameterException('Missing required parameters.');
        }

        if ($sendResultKey !== 'success' && $sendResultKey !== 'fail') {
            throw new SendSmsException(sprintf(
                'Fail send sms. Result messages: %s',
                json_encode($resultMessages)
            ));
        }

        array_shift($resultMessages);

        $resultData = [];

        foreach ($recipients as $recipient) {
            $messageId = array_shift($resultMessages);
            $success = preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/', $messageId);

            if ($success) {
                $resultData[] = Result::successfully($recipient, $messageId);
            } else {
                $reason = $this->tryResolveErrorReason($messageId);
                $resultData[] = Result::failed($recipient, new Error($reason, $messageId));
            }
        }

        return new ResultCollection(...$resultData);
    }
private function processResultMessages(Message $message, array $recipients, $resultMessages): ResultCollection
    {
        if (is_scalar($resultMessages)) {
            $key = $this->responseParser->parse($resultMessages);

            if ($key === 'signature_not_allowed') {
                throw new SenderNameNotAllowedException(sprintf(
                    'The signature (sender) "%s" not allowed.',
                    $message->getSender()
                ));
            } elseif ($key === 'signature_invalid') {
                throw new InvalidSenderNameException(sprintf(
                    'Invalid signature (sender): %s',
                    $message->getSender()
                ));
            }

            throw new SendSmsException(sprintf(
                'Cannot resolve the error for sending SMS. Error: %s',
                $resultMessages
            ));
        }

        $sendResult = $resultMessages[0];
        $sendResultKey = $this->responseParser->parse($sendResult);

        if ($sendResultKey === 'missing_required_parameters') {
            throw new MissingRequiredParameterException('Missing required parameters.');
        }

        if ($sendResultKey !== 'success' && $sendResultKey !== 'fail') {
            throw new SendSmsException(sprintf(
                'Fail send sms. Result messages: %s',
                json_encode($resultMessages)
            ));
        }

        array_shift($resultMessages);

        $resultData = [];

        foreach ($recipients as $recipient) {
            $messageId = array_shift($resultMessages);
            $success = preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/', $messageId);

            if ($success) {
                $resultData[] = Result::successfully($recipient, $messageId);
            } else {
                $reason = $this->tryResolveErrorReason($messageId);
                $resultData[] = Result::failed($recipient, new Error($reason, $messageId));
            }
        }

        return new ResultCollection(...$resultData);
    }
private function processResultMessages ( Message $ message , array $ recipients , $ resultMessages ) : ResultCollection { if ( is_scalar ( $ resultMessages ) ) { $ key = $ this -> responseParser -> parse ( $ resultMessages ) ; if ( $ key === 'signature_not_allowed' ) { throw new SenderNameNotAllowedException ( sprintf ( 'The signature (sender) "%s" not allowed.' , $ message -> getSender ( ) ) ) ; } elseif ( $ key === 'signature_invalid' ) { throw new InvalidSenderNameException ( sprintf ( 'Invalid signature (sender): %s' , $ message -> getSender ( ) ) ) ; } throw new SendSmsException ( sprintf ( 'Cannot resolve the error for sending SMS. Error: %s' , $ resultMessages ) ) ; } $ sendResult = $ resultMessages [ 0 ] ; $ sendResultKey = $ this -> responseParser -> parse ( $ sendResult ) ; if ( $ sendResultKey === 'missing_required_parameters' ) { throw new MissingRequiredParameterException ( 'Missing required parameters.' ) ; } if ( $ sendResultKey !== 'success' && $ sendResultKey !== 'fail' ) { throw new SendSmsException ( sprintf ( 'Fail send sms. Result messages: %s' , json_encode ( $ resultMessages ) ) ) ; } array_shift ( $ resultMessages ) ; $ resultData = [ ] ; foreach ( $ recipients as $ recipient ) { $ messageId = array_shift ( $ resultMessages ) ; $ success = preg_match ( '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/' , $ messageId ) ; if ( $ success ) { $ resultData [ ] = Result :: successfully ( $ recipient , $ messageId ) ; } else { $ reason = $ this -> tryResolveErrorReason ( $ messageId ) ; $ resultData [ ] = Result :: failed ( $ recipient , new Error ( $ reason , $ messageId ) ) ; } } return new ResultCollection ( ... $ resultData ) ; }
Process the response from TurboSMS

@param Message      $message
@param Phone[]      $recipients
@param string|array $resultMessages

@return ResultCollection

@throws \Exception
Process the response from TurboSMS