Exemplo n.º 1
0
        //Docusign API dev guide says this method is subject to call limit and should not be used more than once every 15 min per unique envelope ID
        public static string GetDocumentStatus(string envelopeId, [IgnoreMappingDefault] DocusignCredentials overrideCredentials = null)
        {
            IDocusignCreds creds = overrideCredentials as IDocusignCreds ?? DSServiceClientFactory.DsSettings;

            var dsClient = DSServiceClientFactory.GetDsClient(creds);

            using (var scope = new System.ServiceModel.OperationContextScope(dsClient.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = DSServiceClientFactory.GetAuthHeaderRequestProperty(creds);

                return(dsClient.RequestStatus(envelopeId).Status.ToString());
            }
        }
Exemplo n.º 2
0
        public static FileData GetSignedDocument(string envelopeId, [IgnoreMappingDefault] DocusignCredentials overrideCredentials = null)
        {
            IDocusignCreds creds = overrideCredentials as IDocusignCreds ?? DSServiceClientFactory.DsSettings;

            var dsClient = DSServiceClientFactory.GetDsClient(creds);

            using (var scope = new System.ServiceModel.OperationContextScope(dsClient.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = DSServiceClientFactory.GetAuthHeaderRequestProperty(creds);

                var documentsPDFs = dsClient.RequestDocumentPDFs(envelopeId);

                if (documentsPDFs == null || documentsPDFs.DocumentPDF == null || documentsPDFs.DocumentPDF.Length == 0)
                {
                    return(null);
                }

                return(new FileData(string.Format("{0}.pdf", documentsPDFs.DocumentPDF[0].Name), documentsPDFs.DocumentPDF[0].PDFBytes));
            }
        }
Exemplo n.º 3
0
        public static FileData GetCertificate(string envelopeId, [IgnoreMappingDefault] DocusignCredentials overrideCredentials = null)
        {
            IDocusignCreds creds = overrideCredentials as IDocusignCreds ?? DSServiceClientFactory.DsSettings;

            DSAPIServiceSoapClient dsClient = DSServiceClientFactory.GetDsClient(creds);

            using (OperationContextScope scope = new OperationContextScope(dsClient.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = DSServiceClientFactory.GetAuthHeaderRequestProperty(creds);

                var documentsPDFs = dsClient.RequestCertificate(envelopeId);

                if (documentsPDFs == null || documentsPDFs.DocumentPDF == null || documentsPDFs.DocumentPDF.Length == 0)
                {
                    return(null);
                }

                return(new FileData($"{documentsPDFs.DocumentPDF[0].Name}.pdf", documentsPDFs.DocumentPDF[0].PDFBytes));
            }
        }
        public ResultData Run(StepStartData data)
        {
            IDocusignCreds creds;

            if (data.Data.ContainsKey(INPUT_CREDS) && data.Data[INPUT_CREDS] != null)
            {
                creds = data.Data[INPUT_CREDS] as IDocusignCreds;
            }
            else
            {
                creds = DSServiceClientFactory.DsSettings;
            }

            var dsClient = DSServiceClientFactory.GetDsClient(creds);

            var document   = (FileData[])data.Data[INPUT_DOCUMENT];
            var recipients = (RecipientTabMapping[])data.Data[INPUT_RECIPIENTS];
            var subject    = (string)data.Data[INPUT_SUBJECT];
            var emailBlurb = (string)data.Data[INPUT_EMAILBLURB];

            Dictionary <string, object> resultData = new Dictionary <string, object>();

            try
            {
                using (var scope = new System.ServiceModel.OperationContextScope(dsClient.InnerChannel))
                {
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = DSServiceClientFactory.GetAuthHeaderRequestProperty(creds);

                    var dsRecipients   = new List <Recipient>();
                    var tabs           = new List <Tab>();
                    var recipientsList = recipients.ToList();

                    List <Document> documents = new List <Document>();
                    foreach (FileData doc in document)
                    {
                        documents.Add(new Document
                        {
                            PDFBytes = doc.Contents,
                            ID       = new Guid().ToString(),
                            Name     = doc.FileName
                        });
                    }

                    //each recipient has a list of tabs; this is represented by the RecipientTabMapping type
                    var recipientIndex = 1; //RecipientID must be a non-negative integer; using the index of each Recipient in the list for simplicity
                    foreach (var rtm in recipientsList)
                    {
                        dsRecipients.Add(new Recipient
                        {
                            Email                 = rtm.EmailAddress,
                            UserName              = rtm.EmailAddress,
                            Type                  = RecipientTypeCode.Signer,
                            RoutingOrder          = (ushort)rtm.RoutingOrder,
                            RoutingOrderSpecified = rtm.RoutingOrder > 0,
                            ID         = recipientIndex.ToString(),
                            SignerName = rtm.SignerNameField
                        });

                        //add a Tab to the list for each of the RTM's simplified tab objects, setting the RecipientID and DocumentID to match current recipient and document
                        //first do absolutely positioned tabs (normal Tab)
                        if (rtm.AbsolutePositionTabs != null)
                        {
                            foreach (var apt in rtm.AbsolutePositionTabs)
                            {
                                tabs.Add(new Tab
                                {
                                    PageNumber  = apt.PageNumber.ToString(),
                                    XPosition   = apt.XPosition.ToString(),
                                    YPosition   = apt.YPosition.ToString(),
                                    Type        = apt.TabType,
                                    RecipientID = recipientIndex.ToString(),
                                    Name        = apt.TabType == TabTypeCode.SignHere ? rtm.SignerNameField : rtm.UserNameField,
                                    DocumentID  = "1"
                                });
                            }
                        }
                        ;
                        //then do AnchorTabs
                        if (rtm.AnchorStringTabs != null)
                        {
                            foreach (var ast in rtm.AnchorStringTabs)
                            {
                                tabs.Add(new Tab
                                {
                                    PageNumber    = ast.PageNumber.ToString(),
                                    AnchorTabItem = new AnchorTab {
                                        AnchorTabString = ast.AnchorTabString, XOffset = ast.XOffset, YOffset = ast.YOffset
                                    },
                                    Type        = ast.TabType,
                                    RecipientID = recipientIndex.ToString(),
                                    DocumentID  = "1"
                                });
                            }
                        }
                        ;
                        recipientIndex++;
                    }
                    ;

                    //construct the envelope and send; return EnvelopeID
                    var envelopeID = dsClient.CreateAndSendEnvelope(new Envelope
                    {
                        Subject    = subject,
                        EmailBlurb = emailBlurb,
                        Recipients = dsRecipients.ToArray <Recipient>(),
                        AccountId  = creds.AccountId,
                        Documents  = documents.ToArray(),
                        Tabs       = tabs.ToArray()
                    }).EnvelopeID;


                    resultData.Add(OUTPUT_ENVELOPEID, envelopeID);
                    return(new ResultData(OUTCOME_SENT, resultData));
                }
            }
            catch (Exception ex)
            {
                resultData.Add(OUTPUT_ERRORMESSAGE, ex.Message);
                return(new ResultData(OUTCOME_ERROR, resultData));
            }
        }