public async Task <ActionResult> GenerateMerchantCertificatesDialog(string merchantId)
        {
            var merchant = await _payMerchantClient.Api.GetByIdAsync(merchantId);

            var viewModel = new MerchantCertificateViewModel()
            {
                Caption             = "Generate merchant certificates",
                MerchantId          = merchant.Id,
                MerchantDisplayName = merchant.DisplayName
            };

            return(View(viewModel));
        }
        public async Task <JsonResult> GenerateMerchantCertificates(MerchantCertificateViewModel vm)
        {
            GenerateRsaKeysResponse certs = await _payAuthClient.GenerateRsaKeysAsync(new GenerateRsaKeysRequest
            {
                ClientId          = vm.MerchantId,
                ClientDisplayName = vm.MerchantDisplayName
            });

            var guidOfZip      = StringUtils.GenerateId();
            var publicKeyPath  = Path.Combine(Path.GetTempPath(), $"{StringUtils.GenerateId()}.crt");
            var privateKeyPath = Path.Combine(Path.GetTempPath(), $"{StringUtils.GenerateId()}.pem");
            var zipFilePath    = Path.Combine(Path.GetTempPath(), $"{guidOfZip}.zip");

            using (var sw = new StreamWriter(publicKeyPath))
                sw.WriteLine(certs.PublicKey);

            using (var sw = new StreamWriter(privateKeyPath))
                sw.WriteLine(certs.PrivateKey);

            using (var zip = ZipFile.Open(zipFilePath, ZipArchiveMode.Create))
            {
                zip.CreateEntryFromFile(publicKeyPath, $"rsa-public-key_{vm.MerchantDisplayName}.crt");
                zip.CreateEntryFromFile(privateKeyPath, $"rsa-private-key_{vm.MerchantDisplayName}.pem");
            }

            if (System.IO.File.Exists(publicKeyPath))
            {
                System.IO.File.Delete(publicKeyPath);
            }

            if (System.IO.File.Exists(privateKeyPath))
            {
                System.IO.File.Delete(privateKeyPath);
            }

            return(Json(guidOfZip));
        }