Skip to content
Snippets Groups Projects
Commit eadcd1c2 authored by Jean-Laurent DUZANT's avatar Jean-Laurent DUZANT
Browse files

FEAT #20284 TIME 0:20 [FAST] : use uploadOTP

parent 8a867263
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ use ExternalSignatoryBook\models\ExternalSignatoryBookModel; ...@@ -20,6 +20,7 @@ use ExternalSignatoryBook\models\ExternalSignatoryBookModel;
use SrcCore\models\AuthenticationModel; use SrcCore\models\AuthenticationModel;
use Respect\Validation\Validator; use Respect\Validation\Validator;
use SrcCore\models\ValidatorModel; use SrcCore\models\ValidatorModel;
use Configuration\models\ConfigurationModel;
...@@ -52,48 +53,7 @@ class FastOTPController ...@@ -52,48 +53,7 @@ class FastOTPController
if (!empty($check['errors'])) { if (!empty($check['errors'])) {
return ['errors' => $check['errors']]; return ['errors' => $check['errors']];
} }
$multipartBody = [
'doc' => [
'isFile' => true,
'filename' => "{$args['name']}.pdf",
'content' => base64_decode($args['encodedDocument'])
],
'circuit' => json_encode([
'type' => 'BUREAUTIQUE_PDF',
'steps' => [
[
'step' => 'OTPSignature',
'members' => [$workflowExternalInformations['email']]
]
]
]),
'comment' => "{$args['name']} : {$args['description']}"
];
$uploadResponse = FastOTPController::onDemndUpload([
'connection_data' => $externalSB['connection_data'],
'multipartBody' => $multipartBody
]);
if (!empty($uploadResponse['errors'])) {
FastOTPController::updateErrorInfo([
'workflowId' => $args['workflowId'],
'informations' => ['errors' => $uploadResponse['userFriendlyMessage']]
]);
return ['errors' => $uploadResponse['errors']];
}
$fastDocumentId = $uploadResponse['response'];
$workflowExternalInformations['informations']['fastDocumentId'] = $fastDocumentId;
WorkflowExternalInformationModel::update([
'set' => [
'informations' => json_encode($workflowExternalInformations)
],
'where' => ['workflow_id = ?'],
'data' => [$args['workflowId']]
]);
$otpXml = FastOTPController::generateOtpXml([ $otpXml = FastOTPController::generateOtpXml([
'prettyPrint' => true, 'prettyPrint' => true,
...@@ -109,44 +69,40 @@ class FastOTPController ...@@ -109,44 +69,40 @@ class FastOTPController
return ['errors' => $otpXml['errors']]; return ['errors' => $otpXml['errors']];
} }
$today = new \DateTimeImmutable();
$multipartBody = [ $multipartBody = [
'otpinformation' => [ 'document' => [
'isFile' => true,
'filename' => "{$args['name']}_{$today->format('d-m-Y_H-i-s')}.pdf",
'content' => base64_decode($args['encodedDocument'])
],
'meta' => [
'isFile' => true, 'isFile' => true,
'filename' => $otpXml['filename'], 'filename' => $otpXml['filename'],
'content' => $otpXml['content'] 'content' => $otpXml['content']
] ],
'referrer' => ConfigurationModel::getApplicationUrl() . "rest/documents/{$args['documentId']}/workflows/{$args['workflowId']}/fastRedirectionUrl"
]; ];
$metaDataResponse = FastOTPController::defineDocumentMetadata([ $response = FastOTPController::uploadOTP([
'connection_data' => $externalSB['connection_data'], 'connection_data' => $externalSB['connection_data'],
'multipartBody' => $multipartBody, 'multipartBody' => $multipartBody
'fastDocumentId' => $fastDocumentId
]);
if (!empty($metaDataResponse['errors'])) {
FastOTPController::updateErrorInfo([
'workflowId' => $args['workflowId'],
'informations' => ['errors' => $metaDataResponse['userFriendlyMessage']]
]);
return ['errors' => $metaDataResponse['errors']];
}
$smsUrlResponse = FastOTPController::getSmsUrl([
'connection_data' => $externalSB['connection_data'],
'fastDocumentId' => $fastDocumentId
]); ]);
if (!empty($smsUrlResponse['errors'])) { if (!empty($response['errors'])) {
FastOTPController::updateErrorInfo([ FastOTPController::updateErrorInfo([
'workflowId' => $args['workflowId'], 'workflowId' => $args['workflowId'],
'informations' => ['errors' => $smsUrlResponse['errors']] 'informations' => ['errors' => $response['errors']]
]); ]);
return ['errors' => $smsUrlResponse['errors']]; return ['errors' => $response['errors']];
} }
$workflowExternalInformations['informations']['fastUrl'] = $smsUrlResponse['response']['url']; $workflowExternalInformations['informations']['fastDocId'] = $response['response']['id'];
$workflowExternalInformations['informations']['fastUrl'] = $response['response']['url'];
$informations = json_encode($workflowExternalInformations['informations']); $informations = json_encode($workflowExternalInformations['informations']);
WorkflowExternalInformationModel::update(['set' => ['informations' => $informations], 'where' => ['workflow_id = ?'], 'data' => [$args['workflowId']]]);
WorkflowExternalInformationModel::update(['set' => ['informations' => $informations], 'where' => ['workflow_id = ?'], 'data' => [$args['workflowId']]]);
return true; return true;
} }
...@@ -179,7 +135,7 @@ class FastOTPController ...@@ -179,7 +135,7 @@ class FastOTPController
WorkflowExternalInformationModel::update([ WorkflowExternalInformationModel::update([
'set' => [ 'set' => [
'informations' => json_encode($args['workflowId']) 'informations' => json_encode($args['informations'])
], ],
'where' => ['workflow_id = ?'], 'where' => ['workflow_id = ?'],
'data' => [$args['workflowId']] 'data' => [$args['workflowId']]
...@@ -187,14 +143,14 @@ class FastOTPController ...@@ -187,14 +143,14 @@ class FastOTPController
return true; return true;
} }
public static function onDemndUpload(array $args) public static function uploadOTP(array $args)
{ {
ValidatorModel::notEmpty($args, ['connection_data', 'multipartBody']); ValidatorModel::notEmpty($args, ['connection_data', 'multipartBody']);
ValidatorModel::arrayType($args, ['connection_data', 'multipartBody']); ValidatorModel::arrayType($args, ['connection_data', 'multipartBody']);
$curlReturn = CurlModel::exec([ $curlReturn = CurlModel::exec([
'method' => 'POST', 'method' => 'POST',
'url' => $args['connection_data']['apiUri'] . "/documents/ondemand/" . $args['connection_data']['apiKey'] . "/upload", 'url' => $args['connection_data']['apiUri'] . "/documents/v2/otp/{$args['connection_data']['apiKey']}/signature-otp/upload",
'options' => [ 'options' => [
CURLOPT_SSLCERT => $args['connection_data']['certPath'], CURLOPT_SSLCERT => $args['connection_data']['certPath'],
CURLOPT_SSLCERTPASSWD => AuthenticationModel::decrypt(['cryptedPassword' => $args['connection_data']['certPass']]), CURLOPT_SSLCERTPASSWD => AuthenticationModel::decrypt(['cryptedPassword' => $args['connection_data']['certPass']]),
...@@ -203,13 +159,13 @@ class FastOTPController ...@@ -203,13 +159,13 @@ class FastOTPController
'multipartBody' => $args['multipartBody'] 'multipartBody' => $args['multipartBody']
]); ]);
if ($curlReturn['code'] != 200 || !is_int($curlReturn['response'])) { if ($curlReturn['code'] != 200 || !empty($curlReturn['response']['errorCode'])) {
if (!empty($curlReturn['resonse']['userFriendlyMessage'])) { if (!empty($curlReturn['resonse']['userFriendlyMessage']) && $curlReturn['resonse']['userFriendlyMessage'] != 'Erreur') {
return ['errors' => FastOTPController::OTP_ERROR . $curlReturn['response']['userFriendlyMessage']]; return ['errors' => FastOTPController::OTP_ERROR . $curlReturn['response']['userFriendlyMessage']];
} else {
return ['errors' => FastOTPController::OTP_ERROR . $curlReturn['response']['developerMessage']];
} }
return ['errors' => FastOTPController::OTP_ERROR . $curlReturn['response']['developerMessage']];
} }
return ['response' => $curlReturn['response']]; return ['response' => $curlReturn['response']];
} }
...@@ -240,57 +196,4 @@ class FastOTPController ...@@ -240,57 +196,4 @@ class FastOTPController
return ['filename' => $args['filename'], 'content' => $xmlData]; return ['filename' => $args['filename'], 'content' => $xmlData];
} }
public static function defineDocumentMetadata(array $args)
{
ValidatorModel::notEmpty($args, ['connection_data', 'multipartBody', 'fastDocumentId']);
ValidatorModel::arrayType($args, ['connection_data', 'multipartBody']);
ValidatorModel::intVal($args, ['fastDocumentId']);
$curlReturn = CurlModel::exec([
'method' => 'PUT',
'url' => $args['connection_data']['apiUri'] . "/documents/v2/otp/" . $args['fastDocumentId'] . "/metadata/define",
'options' => [
CURLOPT_SSLCERT => $args['connection_data']['certPath'],
CURLOPT_SSLCERTPASSWD => AuthenticationModel::decrypt(['cryptedPassword' => $args['connection_data']['certPass']]),
CURLOPT_SSLCERTTYPE => $args['connection_data']['certType']
],
'multipartBody' => $args['multipartBody']
]);
if ($curlReturn['code'] != 200) {
if (!empty($curlReturn['resonse']['userFriendlyMessage'])) {
return ['errors' => FastOTPController::OTP_ERROR . $curlReturn['response']['userFriendlyMessage']];
}
return ['errors' => FastOTPController::OTP_ERROR . $curlReturn['response']['developerMessage']];
}
return ['response' => true];
}
public static function getSmsUrl(array $args)
{
ValidatorModel::notEmpty($args, ['connection_data', 'fastDocumentId']);
ValidatorModel::arrayType($args, ['connection_data']);
ValidatorModel::intVal($args, ['fastDocumentId']);
$curlReturn = CurlModel::exec([
'method' => 'GET',
'url' => $args['connection_data']['apiUri'] . "/documents/v2/otp/url",
'options' => [
CURLOPT_SSLCERT => $args['connection_data']['certPath'],
CURLOPT_SSLCERTPASSWD => AuthenticationModel::decrypt(['cryptedPassword' => $args['connection_data']['certPass']]),
CURLOPT_SSLCERTTYPE => $args['connection_data']['certType']
],
'queryParams' => [
'id' => $args['fastDocumentId']
]
]);
if ($curlReturn['code'] != 200) {
if (!empty($curlReturn['resonse']['userFriendlyMessage'])) {
return ['errors' => FastOTPController::OTP_ERROR . $curlReturn['response']['userFriendlyMessage']];
}
return ['errors' => FastOTPController::OTP_ERROR . $curlReturn['response']['developerMessage']];
}
return ['response' => $curlReturn['response']];
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment