Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 64 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SeniorPurchaseSolicitationExport | |
0.00% |
0 / 64 |
|
0.00% |
0 / 3 |
240 | |
0.00% |
0 / 1 |
| generate | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
42 | |||
| link | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
42 | |||
| retrieveUserAndPassword | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Shared\Integrations\Senior; |
| 4 | |
| 5 | use Domain\Shared\Integrations\Senior\Exceptions\IntegrationSoapSeniorException; |
| 6 | use Illuminate\Support\Facades\Auth; |
| 7 | use SoapFault; |
| 8 | |
| 9 | use function __; |
| 10 | |
| 11 | class SeniorPurchaseSolicitationExport extends SeniorImportBase |
| 12 | { |
| 13 | /** |
| 14 | * @throws IntegrationSoapSeniorException |
| 15 | */ |
| 16 | public function generate(array $payload): object |
| 17 | { |
| 18 | $wsdlURI = config('integration.url') . '/sapiens_Synccom_senior_g5_co_mcm_est_geracaosolicitacaocompra?wsdl'; |
| 19 | $credentials = $this->retrieveUserAndPassword(); |
| 20 | $context = $this->makeSoapContext('GerarSolicitacaoCompra', $wsdlURI, $payload); |
| 21 | $startedAt = microtime(true); |
| 22 | |
| 23 | try { |
| 24 | $this->logSoapInfo('senior.soap.started', $context); |
| 25 | |
| 26 | $client = new SeniorSoapClient($wsdlURI, $this->options); |
| 27 | $response = $client->GerarSolicitacaoCompra( |
| 28 | $credentials['user'], |
| 29 | $credentials['password'], |
| 30 | 0, |
| 31 | $payload |
| 32 | ); |
| 33 | |
| 34 | $this->logSoapInfo('senior.soap.finished', array_merge($context, [ |
| 35 | 'elapsed_ms' => $this->elapsedMilliseconds($startedAt), |
| 36 | ])); |
| 37 | |
| 38 | $returnCode = $this->resolveSoapReturnCode($response); |
| 39 | if ((isset($response->erroExecucao) || isset($response->erros)) || ($returnCode !== null && $returnCode !== 1)) { |
| 40 | throw new IntegrationSoapSeniorException( |
| 41 | __("Senior's SOAP request returned with an error: :message (:wsdl)", [ |
| 42 | 'message' => $this->resolveSoapErrorMessage($response), |
| 43 | 'wsdl' => $wsdlURI, |
| 44 | ]), |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | return (object) $response; |
| 49 | } catch (SoapFault $soapFault) { |
| 50 | throw new IntegrationSoapSeniorException( |
| 51 | __("Failure to consume Senior's soap: :message (:wsdl)", [ |
| 52 | 'message' => $soapFault->getMessage(), |
| 53 | 'wsdl' => $wsdlURI, |
| 54 | ]), |
| 55 | previous: $soapFault |
| 56 | ); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @throws IntegrationSoapSeniorException |
| 62 | */ |
| 63 | public function link(array $payload): void |
| 64 | { |
| 65 | $wsdlURI = config('integration.url') . '/sapiens_Synccom_br_soelx_MovimentoEstoque?wsdl'; |
| 66 | $credentials = $this->retrieveUserAndPassword(); |
| 67 | |
| 68 | try { |
| 69 | $client = new SeniorSoapClient($wsdlURI, $this->options); |
| 70 | $response = $client->VincularRequisicaoSolicitacao( |
| 71 | $credentials['user'], |
| 72 | $credentials['password'], |
| 73 | 0, |
| 74 | $payload |
| 75 | ); |
| 76 | |
| 77 | $returnCode = $this->resolveSoapReturnCode($response); |
| 78 | if ((isset($response->erroExecucao) || isset($response->erros)) || ($returnCode !== null && $returnCode !== 1)) { |
| 79 | throw new IntegrationSoapSeniorException( |
| 80 | __("Senior's SOAP request returned with an error: :message (:wsdl)", [ |
| 81 | 'message' => $this->resolveSoapErrorMessage($response), |
| 82 | 'wsdl' => $wsdlURI, |
| 83 | ]), |
| 84 | ); |
| 85 | } |
| 86 | } catch (SoapFault $soapFault) { |
| 87 | throw new IntegrationSoapSeniorException( |
| 88 | __("Failure to consume Senior's soap: :message (:wsdl)", [ |
| 89 | 'message' => $soapFault->getMessage(), |
| 90 | 'wsdl' => $wsdlURI, |
| 91 | ]), |
| 92 | previous: $soapFault |
| 93 | ); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | private function retrieveUserAndPassword(): array |
| 98 | { |
| 99 | $authenticatedUser = Auth::user(); |
| 100 | |
| 101 | if ($authenticatedUser && $authenticatedUser->hasWarehouseRequesterAccess()) { |
| 102 | return (new SeniorCredentialResolver())->resolveForAuthenticatedUser($authenticatedUser); |
| 103 | } |
| 104 | |
| 105 | return [ |
| 106 | 'user' => (string) config('integration.user'), |
| 107 | 'password' => (string) config('integration.user_password'), |
| 108 | ]; |
| 109 | } |
| 110 | } |
| 111 |