Specification
The process is initiated by any employee with necessary scopes in this legal entity and involves the transfer of a signed person with electronic digital signature.
Process is asynchronous. If all validations are successfully completed, the asynchronous process of creating a person starts by processing the message.
Service logic
Only authenticated and authorized user can use this service
Only APPROVED declaration request can be signed
The request can be signed only by the employee who works in the same legal entity in which the request was made.
Authorize user
Verify the validity of access token
Return 401 in case validation fails
Check scopes in order to perform this action (scope = 'declaration_request:sign')
Return 403 in case invalid scope(s)
Digital signature
Decode content that is encrypted in an electronic digital signature.
Use Digital signature WS. Method checks digital signature and returns result.
See service specification
Validate DRFO
Check that DRFO in Certificate details exists and not empty
Check that DRFO in Certificate details is equal to DRFO in Party
Get party.tax_id using employee_id in person payload
Compare DRFO in Certificate with party.tax_id
Convert DRFO and TAX_ID to uppercase
Compare DRFO and TAX_ID as Cyrillic letters
Convert DRFO to Cyrillic and compare as Cyrillic letters
In case validation fails - generate 422 error
Latin to Cyrillic mapping
%{"A" => "А", "B" => "В", "C" => "С", "E" => "Е", "H" => "Н", "I" => "І", "K" => "К", "M" => "М", "O" => "О", "P" => "Р", "T" => "Т", "X" => "Х"} |
Validate request
Validate request using JSON schema (See specification)
In case validation fails - generate 422 error
Check declaration request status
If status is not APPROVED, - returned error 'Incorrect status'
Check signed content
Check decoded signed content with previously created on IL.db.
SELECT data FROM declaration_requests WHERE id = {:id} |
In case if they are not equal - generate 422 error (message: "Signed content does not match the previously created content")
Check employee
Declaration_request can be signed by any employee with necessery scopes in equal legal_entity_id.
Extract legal_entity_id (client_id) from token
Extract employee_id from request
Check if $.client_id=employees.legal_entity_id
in case error return 422
Validate human readable declaration number
Search declaration_number in declarations.declaration_number.
if exists return 422 - message 'Declaration with the same declaration_number is already exist in DB'
Update declaration request:
Change entity status in IL_DB.declaration_request to SIGNED
Set updated_at - now() (Get current date-time)
Set updated_by - user_id (Extract user from token)
Save signed declaration to media storage
Get url for declaration upload.
Use Request a Secret WSParameter
Source
action'GET'bucket'DECLARATIONS'resource_id: DECLARATION_IDresource_name: DECLARATION_NAME
Upload signed declaration to media storage
Get active declarations
Search for active declarations using MPI ID
If found, - terminate them and create new declaration.
If not found - create new declaration.
Terminate declaration
In case active declarations found - terminate all by changing status to INACTIVE.
Create declaration
Check authentication_method_current
SELECT authentication_method_current FROM declaration_requests WHERE id = {:id}
If "type" = "OFFLINE"
set declaration status to "PENDING_VERIFICATION"
set reason to 'offline'
if "type" = "OTP" - set declaration status to "ACTIVE"
Check persons 'no_tax_id' flag
if 'no_tax_id'=true
set declaration status to "PENDING_VERIFICATION"
set reason to 'no_tax_id'
Create a new declaration by adding a new entity to the declarations table ops_db without declaration_id.
if there is existing record in the declarations table with the same id and declaration_request_id, return ok to IL
Mapping:
Update declaration request status
Update declaration request:
UPDATE declaration_requests SET status = 'SIGNED' WHERE id = {:id} |