51 return $result->addError(
new Error(
'Provider is not configured'));
53 $requestBody = Json::encode($messageFields);
55 $result->setServiceRequest(
new DTO\
Request([
58 'body' => $requestBody,
64 $error = $httpClient->getError();
65 $errorCode = array_key_first($error);
66 $result->setServiceResponse(
new DTO\
Response([
69 return $result->addError(
new Error($error[$errorCode], $errorCode));
72 $result->setServiceResponse(
new DTO\
Response([
73 'statusCode' => $httpClient->getStatus(),
74 'headers' => $httpClient->getHeaders()->toArray(),
75 'body' => $httpClient->getResult(),
77 $responseCode = $httpClient->getStatus();
78 if ($responseCode !== 200)
80 return $result->addError(
new Error(
"HTTP response code {$responseCode}",
"HTTP_{$responseCode}"));
83 $responseBody = $httpClient->getResult();
84 if ($responseBody ==
'')
86 return $result->addError(
new Error(
"Empty response",
"EMPTY_RESPONSE"));
91 $decoded = Json::decode($responseBody);
92 $result->setExternalId($decoded[
'message_id']);
93 $result->setAccepted();
97 $result->addError(
new Error(
"JSON decode error",
"JSON_ERROR"));