Exemplo n.º 1
0
        public async Task <IActionResult> GenerateRsaKeys([FromBody] GenerateRsaKeysModel request)
        {
            try
            {
                // check that pay auth for merchant exists
                var payAuth = await _payAuthService.GetAsync(request.ClientId, LykkePayConstants.DefaultSystemId);

                var rsaKeys = _securityHelper.GenerateRsaKeys(request.ClientDisplayName);

                await _payAuthService.UpdateAsync(new Core.Domain.PayAuth
                {
                    SystemId    = LykkePayConstants.DefaultSystemId,
                    ClientId    = request.ClientId,
                    Certificate = rsaKeys.PublicKey
                });

                return(Ok(new GenerateRsaKeysResponse
                {
                    PublicKey = rsaKeys.PublicKey,
                    PrivateKey = rsaKeys.PrivateKey
                }));
            }
            catch (Exception e)
            {
                _log.Error(e, $"{e.Message}, request: {request.ToJson()}");

                return(BadRequest(ErrorResponse.Create(e.Message)));
            }
        }
        public async Task <IActionResult> UpdateApiKey([FromBody] UpdateApiKeyModel request)
        {
            try
            {
                await _payAuthService.UpdateAsync(Mapper.Map <Core.Domain.PayAuth>(request));

                return(Ok());
            }
            catch (ClientNotFoundException e)
            {
                _log.Error(e, $"{e.Message}, request: {request.ToJson()}");

                return(NotFound(ErrorResponse.Create(e.Message)));
            }
        }