예제 #1
0
        public static string SendDocuSign(object fileId, DocuSignData docuSignData, Dictionary <string, string> requestHeaders)
        {
            if (docuSignData == null)
            {
                throw new ArgumentNullException("docuSignData");
            }
            var token   = DocuSignToken.GetToken();
            var account = GetDocuSignAccount(token);

            var  configuration = GetConfiguration(account, token);
            File sourceFile;
            var  document = CreateDocument(fileId, docuSignData.Name, docuSignData.FolderId, out sourceFile);

            var url = CreateEnvelope(account.AccountId, document, docuSignData, configuration);

            FilesMessageService.Send(sourceFile, requestHeaders, MessageAction.DocumentSendToSign, "DocuSign", sourceFile.Title);

            return(url);
        }
예제 #2
0
        private static string CreateEnvelope(string accountId, Document document, DocuSignData docuSignData, DocuSign.eSign.Client.Configuration configuration)
        {
            var eventNotification = new EventNotification
            {
                EnvelopeEvents = new List <EnvelopeEvent>
                {
                    //new EnvelopeEvent {EnvelopeEventStatusCode = DocuSignStatus.Sent.ToString()},
                    //new EnvelopeEvent {EnvelopeEventStatusCode = DocuSignStatus.Delivered.ToString()},
                    new EnvelopeEvent {
                        EnvelopeEventStatusCode = DocuSignStatus.Completed.ToString()
                    },
                    new EnvelopeEvent {
                        EnvelopeEventStatusCode = DocuSignStatus.Declined.ToString()
                    },
                    new EnvelopeEvent {
                        EnvelopeEventStatusCode = DocuSignStatus.Voided.ToString()
                    },
                },
                IncludeDocumentFields = "true",
                //RecipientEvents = new List<RecipientEvent>
                //    {
                //        new RecipientEvent {RecipientEventStatusCode = "Sent"},
                //        new RecipientEvent {RecipientEventStatusCode = "Delivered"},
                //        new RecipientEvent {RecipientEventStatusCode = "Completed"},
                //        new RecipientEvent {RecipientEventStatusCode = "Declined"},
                //        new RecipientEvent {RecipientEventStatusCode = "AuthenticationFailed"},
                //        new RecipientEvent {RecipientEventStatusCode = "AutoResponded"},
                //    },
                Url = CommonLinkUtility.GetFullAbsolutePath(DocuSignHandler.Path + "?" + FilesLinkUtility.Action + "=webhook"),
            };

            Global.Logger.Debug("DocuSign hook url: " + eventNotification.Url);

            var signers = new List <Signer>();

            docuSignData.Users.ForEach(uid =>
            {
                try
                {
                    var user = CoreContext.UserManager.GetUsers(uid);
                    signers.Add(new Signer
                    {
                        Email       = user.Email,
                        Name        = user.DisplayUserName(false),
                        RecipientId = user.ID.ToString(),
                    });
                }
                catch (Exception ex)
                {
                    Log.Error("Signer is undefined", ex);
                }
            });

            var envelopeDefinition = new EnvelopeDefinition
            {
                CustomFields = new CustomFields
                {
                    TextCustomFields = new List <TextCustomField>
                    {
                        new TextCustomField {
                            Name = UserField, Value = SecurityContext.CurrentAccount.ID.ToString()
                        },
                    }
                },
                Documents = new List <Document> {
                    document
                },
                EmailBlurb        = docuSignData.Message,
                EmailSubject      = docuSignData.Name,
                EventNotification = eventNotification,
                Recipients        = new Recipients
                {
                    Signers = signers,
                },
                Status = "created",
            };

            var envelopesApi    = new EnvelopesApi(configuration);
            var envelopeSummary = envelopesApi.CreateEnvelope(accountId, envelopeDefinition);

            Global.Logger.Debug("DocuSign createdEnvelope: " + envelopeSummary.EnvelopeId);

            var envelopeId = envelopeSummary.EnvelopeId;
            var url        = envelopesApi.CreateSenderView(accountId, envelopeId, new ReturnUrlRequest
            {
                ReturnUrl = CommonLinkUtility.GetFullAbsolutePath(DocuSignHandler.Path + "?" + FilesLinkUtility.Action + "=redirect")
            });

            Global.Logger.Debug("DocuSign senderView: " + url.Url);

            return(url.Url);
        }