Example #1
0
        public BulksignResult <EnvelopeApiModel> PrepareSendEnvelope([FromBody] FileInput[] files)
        {
            AuthenticationApiModel apiToken = ExtractApiAuthenticationToken();

            BulkSignApi api = new BulkSignApi(IntegrationSettings.BulksignRestUrl);

            BulksignResult <EnvelopeApiModel> result = api.PrepareSendEnvelope(apiToken, files);

            return(result);
        }
        public void DownloadCompletedDocuments(string envelopeId, string apiKey, string email)
        {
            log.Info($"Preparing to download documents for completed envelope '{envelopeId}' ");

            BulkSignApi api = new BulkSignApi(IntegrationSettings.BulksignRestUrl);

            AuthenticationApiModel token = new AuthenticationApiModel()
            {
                UserEmail = email,
                Key       = apiKey
            };

            BulksignResult <EnvelopeStatusTypeApi> envelopeStatus = api.GetEnvelopeStatus(token, envelopeId);

            if (envelopeStatus.IsSuccessful == false)
            {
                //it seems the envelope doesn't exist
                if (envelopeStatus.ErrorCode == ApiErrorCode.API_ERROR_CODE_ENVELOPE_WITH_ID_NOT_FOUND)
                {
                    log.Error($"{nameof(DownloadCompletedDocuments)} , for envelopeId '{envelopeId}', GetEnvelopeStatus returned '{ApiErrorCode.API_ERROR_MESSAGE_ENVELOPE_WITH_ID_NOT_FOUND}' , envelope doesn't exists anymore");

                    new DbIntegration().UpdateEnvelopeStatus(envelopeId, Constants.ENVELOPE_DELETED);
                }
                else
                {
                    log.Error($" {nameof(DownloadCompletedDocuments)} failed for '{envelopeId}', calling GetEnvelopeStatus failed with code : '{envelopeStatus.ErrorCode}', message : '{envelopeStatus.ErrorMessage}' ");
                }

                return;
            }

            if (envelopeStatus.Response != EnvelopeStatusTypeApi.Completed)
            {
                log.Error($" Invalid envelope status received in {nameof(DownloadCompletedDocuments)} for envelopeId '{envelopeId}', status {envelopeStatus.ToString()} ");

                //just update the status
                new DbIntegration().UpdateEnvelopeStatus(envelopeId, envelopeStatus.ToString().ToLower());
                return;
            }

            BulksignResult <byte[]> result = api.DownloadEnvelopeCompletedDocuments(token, envelopeId);

            if (result.IsSuccessful == false)
            {
                log.Error($" {nameof(DownloadCompletedDocuments)} failed, code : {result.ErrorCode}, message : {result.ErrorMessage} ");
                return;
            }

            string fullPath = IntegrationSettings.CompletedEnvelopePath + @"\" + envelopeId + ".zip";

            File.WriteAllBytes(fullPath, result.Response);

            new DbIntegration().UpdateEnvelopeCompletedDocumentPath(envelopeId, fullPath);
        }
        public void CheckEnvelopeStatus(SentEnvelopeModel envelope)
        {
            try
            {
                log.Info($"Checking status for envelope '{envelope.Id}' ");

                BulkSignApi api = new BulkSignApi(IntegrationSettings.BulksignRestUrl);

                AuthenticationApiModel token = new AuthenticationApiModel()
                {
                    UserEmail = envelope.SenderEmail,
                    Key       = envelope.ApiToken
                };

                BulksignResult <EnvelopeStatusTypeApi> envelopeStatus = api.GetEnvelopeStatus(token, envelope.Id);


                if (envelopeStatus.IsSuccessful == false)
                {
                    //it seems the envelope doesn't exist anymore, must have been deleted
                    if (envelopeStatus.ErrorCode == ApiErrorCode.API_ERROR_CODE_ENVELOPE_WITH_ID_NOT_FOUND)
                    {
                        log.Error($"{nameof(DownloadCompletedDocuments)} , GetEnvelopeStatus returned {ApiErrorCode.API_ERROR_MESSAGE_ENVELOPE_WITH_ID_NOT_FOUND} , envelope doesn't exists");

                        new DbIntegration().UpdateEnvelopeStatus(envelope.Id, Constants.ENVELOPE_DELETED);
                    }
                    else
                    {
                        log.Error($" {nameof(DownloadCompletedDocuments)} failed for '{envelope.Id}', calling GetEnvelopeStatus failed with code : '{envelopeStatus.ErrorCode}', message : '{envelopeStatus.ErrorMessage}' ");
                    }

                    return;
                }

                //was the status changed
                if ((int)envelopeStatus.Response != Constants.NUMERIC_ENVELOPE_STATUS_IN_PROGRESS)
                {
                    log.Info($"Updating status for envelope '{envelope.Id}', new status is '{envelopeStatus.Response.ToString()}' ");
                    new DbIntegration().UpdateEnvelopeStatus(envelope.Id, envelopeStatus.Response.ToString());
                }
                else
                {
                    log.Info($"Status for envelope '{envelope.Id}' is not changed");
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
        public string SendDocumentForSigning(string name, string email, string filePath)
        {
            BulkSignApi api = new BulkSignApi();

            BundleApiModel bundle = new BundleApiModel();

            bundle.Name = "Website Integration Sample";
            bundle.DisableNotifications = true;             //no email notifications


            RecipientApiModel recipient = new RecipientApiModel();

            recipient.Index         = 1;
            recipient.Email         = email;
            recipient.Name          = name;
            recipient.RecipientType = RecipientTypeApi.Signer;

            bundle.Recipients = new RecipientApiModel[1] {
                recipient
            };


            DocumentApiModel document = new DocumentApiModel();

            document.FileName             = "test.pdf";
            document.FileContentByteArray = new FileContentByteArray()
            {
                ContentBytes = File.ReadAllBytes(filePath)
            };

            bundle.Documents = new DocumentApiModel[1] {
                document
            };


            AuthorizationApiModel auth = new AuthorizationApiModel();

            auth.UserEmail = BulksignAccountEmail;
            auth.UserToken = BulksignAccountToken;


            BulksignResult <SendBundleResultApiModel> result = api.SendBundle(auth, bundle);

            if (result.IsSuccessful)
            {
                return(api.GetSignUrlForAccessCode(result.Response.AccessCodes[0].AccessCode));
            }

            throw new InvalidOperationException(result.ErrorMessage);
        }
Example #5
0
        public BulksignResult <SendEnvelopeResultApiModel> SendEnvelopeFromTemplate([FromBody] EnvelopeFromTemplateApiModel model)
        {
            AuthenticationApiModel apiToken = ExtractApiAuthenticationToken();

            BulkSignApi api = new BulkSignApi(IntegrationSettings.BulksignRestUrl);

            BulksignResult <SendEnvelopeResultApiModel> result = api.SendEnvelopeFromTemplate(apiToken, model);

            if (result.IsSuccessful)
            {
                try
                {
                    new DbIntegration().AddSentEnvelope(apiToken.UserEmail, apiToken.Key, result.Response.EnvelopeId, string.Empty);
                }
                catch (Exception ex)
                {
                    log.Error(ex, $"Failed to store data about envelope '{result.Response}' ");
                }
            }

            return(result);
        }
Example #6
0
        public BulksignResult <string> DeleteEnvelope(string envelopeId)
        {
            AuthenticationApiModel apiToken = ExtractApiAuthenticationToken();

            BulkSignApi api = new BulkSignApi(IntegrationSettings.BulksignRestUrl);

            BulksignResult <string> result = api.DeleteEnvelope(apiToken, envelopeId);

            if (result.IsSuccessful)
            {
                try
                {
                    new DbIntegration().UpdateEnvelopeStatus(envelopeId, Constants.ENVELOPE_DELETED);
                }
                catch (Exception ex)
                {
                    log.Error(ex, $"Failed to store envelope '{result.Response}'");
                }
            }

            return(result);
        }
Example #7
0
        public BulksignResult <SendEnvelopeResultApiModel> SendEnvelope([FromBody] EnvelopeApiModel bundle)
        {
            AuthenticationApiModel apiToken = ExtractApiAuthenticationToken();

            BulkSignApi api = new BulkSignApi(IntegrationSettings.BulksignRestUrl);

            BulksignResult <SendEnvelopeResultApiModel> result = api.SendEnvelope(apiToken, bundle);

            if (result.IsSuccessful)
            {
                try
                {
                    string bundleConfiguration = IntegrationSettings.StoreEnvelopeConfiguration ? JsonConvert.SerializeObject(bundle) : string.Empty;

                    new DbIntegration().AddSentEnvelope(apiToken.UserEmail, apiToken.Key, result.Response.EnvelopeId, bundleConfiguration);
                }
                catch (Exception ex)
                {
                    log.Error(ex, $"Failed to store envelope '{result.Response.EnvelopeId}'");
                }
            }

            return(result);
        }