Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
51.16% |
22 / 43 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| SeniorRequestCancellationExport | |
51.16% |
22 / 43 |
|
0.00% |
0 / 1 |
10.19 | |
0.00% |
0 / 1 |
| execute | |
51.16% |
22 / 43 |
|
0.00% |
0 / 1 |
10.19 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Shared\Integrations\Senior; |
| 4 | |
| 5 | use Domain\Request\DTOs\CancelRequestSeniorDTO; |
| 6 | use Domain\Shared\Integrations\Senior\Exceptions\IntegrationSoapSeniorException; |
| 7 | use Illuminate\Support\Facades\Auth; |
| 8 | use SoapFault; |
| 9 | |
| 10 | use function __; |
| 11 | |
| 12 | class SeniorRequestCancellationExport extends SeniorImportBase |
| 13 | { |
| 14 | /** |
| 15 | * @throws IntegrationSoapSeniorException |
| 16 | */ |
| 17 | public function execute(CancelRequestSeniorDTO $cancelRequestSeniorDTO): ?object |
| 18 | { |
| 19 | $wsdlURI = config('integration.url') . '/sapiens_Synccom_senior_g5_co_mcm_est_requisicoes?wsdl'; |
| 20 | $credentials = (new SeniorCredentialResolver())->resolveForAuthenticatedUser(Auth::user(), true); |
| 21 | $payload = $cancelRequestSeniorDTO->toArray(); |
| 22 | $context = $this->makeSoapContext('cancelar', $wsdlURI, $payload); |
| 23 | $startedAt = microtime(true); |
| 24 | |
| 25 | try { |
| 26 | $this->logSoapInfo('senior.soap.started', $context); |
| 27 | |
| 28 | $client = new SeniorSoapClient($wsdlURI, $this->options); |
| 29 | $this->logSoapInfo('senior.soap.client_ready', array_merge($context, [ |
| 30 | 'elapsed_ms' => $this->elapsedMilliseconds($startedAt), |
| 31 | ])); |
| 32 | |
| 33 | $response = $client->Cancelar( |
| 34 | $credentials['user'], |
| 35 | $credentials['password'], |
| 36 | 0, |
| 37 | $payload |
| 38 | ); |
| 39 | |
| 40 | $this->logSoapInfo('senior.soap.finished', array_merge($context, [ |
| 41 | 'elapsed_ms' => $this->elapsedMilliseconds($startedAt), |
| 42 | ], $this->responseLogContext($response))); |
| 43 | |
| 44 | $returnCode = $this->resolveSoapReturnCode($response); |
| 45 | if ((isset($response->erroExecucao) || isset($response->erros)) || ($returnCode !== null && $returnCode !== 0)) { |
| 46 | $this->logSoapError('senior.soap.functional_error', array_merge($context, [ |
| 47 | 'elapsed_ms' => $this->elapsedMilliseconds($startedAt), |
| 48 | ], $this->responseLogContext($response))); |
| 49 | |
| 50 | throw new IntegrationSoapSeniorException( |
| 51 | __("Senior's SOAP request returned with an error: :message (:wsdl)", [ |
| 52 | 'message' => $this->resolveSoapErrorMessage($response), |
| 53 | 'wsdl' => $wsdlURI, |
| 54 | ]), |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | return $response; |
| 59 | } catch (SoapFault $soapFault) { |
| 60 | $this->logSoapError('senior.soap.soap_fault', array_merge($context, [ |
| 61 | 'elapsed_ms' => $this->elapsedMilliseconds($startedAt), |
| 62 | 'message' => $soapFault->getMessage(), |
| 63 | ])); |
| 64 | |
| 65 | throw new IntegrationSoapSeniorException( |
| 66 | __("Failure to consume Senior's soap: :message (:wsdl)", [ |
| 67 | 'message' => $soapFault->getMessage(), |
| 68 | 'wsdl' => $wsdlURI, |
| 69 | ]), |
| 70 | previous: $soapFault |
| 71 | ); |
| 72 | } |
| 73 | } |
| 74 | } |