2014-09-24 104 views
0

我正在使用Docusign SOAP API與多個收件人親自簽名。一切正常,直到我想將OpenTrust證書集成到我的身份驗證中。這裏是矛盾:Docusign SOAP API InPerson使用多個收件人和OpenTrust簽名

  • 爲了親自簽署工作,收件人的RoutingOrder必須是相同的。否則,您將收到以下肥皂錯誤: 無法生成無序序列收件人的標記。

  • 要使OpenTrust證書起作用,RoutingOrder必須不同。否則,您將收到以下錯誤: 當指定RequireSignerCertificate時,不得有另一個收件人使用相同的路由順序。

如果我能找到的人在與多個接收者和不同的路由命令簽署的解決方案,也許會解決這個問題。這裏是一個我的代碼:

Map<string, Docusign_API__c> mcs = Docusign_API__c.getAll(); 
    String accountId = mcs.get('accountId').Value__c; 
    String userId = '[' + UserInfo.getUserEmail() + ';' + UserInfo.getName() + ']' + mcs.get('userId').Value__c; 
    String password = mcs.get('password').Value__c; 
    String integratorsKey = mcs.get('integratorsKey').Value__c; 
    String webServiceUrl = mcs.get('webServiceUrl').Value__c; 
    string CarbonCopyEmail = mcs.get('bcc').Value__c; 

    string RecordId = 'a0411000006Ijy1'; 

    string envelopeId = null; 

    DocuSignAPI.APIServiceSoap dsApiSend = new DocuSignAPI.APIServiceSoap(); 
    dsApiSend.endpoint_x = webServiceUrl; 

    //Set Authentication 
    system.debug(userId); 
    String auth = '<DocuSignCredentials><Username>'+ userId 
     +'</Username><Password>' + password 
     + '</Password><IntegratorKey>' + integratorsKey 
     + '</IntegratorKey></DocuSignCredentials>'; 
    System.debug('Setting authentication to: ' + auth); 

    dsApiSend.inputHttpHeaders_x = new Map<String, String>(); 
    dsApiSend.inputHttpHeaders_x.put('X-DocuSign-Authentication', auth); 

    DocuSignAPI.Envelope envelope = new DocuSignAPI.Envelope(); 
    envelope.Subject = 'Please Sign this Contract: ' + contract.ContractNumber; 
    envelope.EmailBlurb = 'This is my new eSignature service, it allows me to get your signoff without having to fax, scan, retype, refile and wait forever'; 
    envelope.AccountId = accountId; 

    envelope.CustomFields = new DocuSignAPI.ArrayOfCustomField(); 
    envelope.CustomFields.CustomField = new DocuSignAPI.CustomField[1]; 

    DocuSignAPI.CustomField env_customfield = new DocuSignAPI.CustomField(); 
    env_customfield.Name = 'DSFSSourceObjectId'; 
    env_customfield.Show = 'false'; 
    env_customfield.Required = 'true'; 
    env_customfield.Value = RecordId +'~object__c'; 
    env_customfield.CustomFieldType = 'Text'; 
    env_customfield.ListItems = '';  
    envelope.CustomFields.CustomField[0] = env_customfield;     

    // Document 
    //Add Attachments 
    list<Attachment> listAttachments = [SELECT Id, Name, Body FROM Attachment WHERE ParentId = :RecordId]; 

    envelope.Documents = new DocuSignAPI.ArrayOfDocument();  
    envelope.Documents.Document = new DocuSignAPI.Document[listAttachments.size()]; 

    integer attCounter = 0; 
    for(Attachment att : listAttachments){   
     DocuSignAPI.Document document2 = new DocuSignAPI.Document(); 
     document2.ID = attCounter; 
     document2.pdfBytes = EncodingUtil.base64Encode(att.Body); 
     document2.Name = att.Name; 
     if(att.Name.contains('.')){ 
      document2.FileExtension = att.Name.split('\\.')[1]; 
     } 

     envelope.Documents.Document[attCounter] = document2; 
     attCounter++; 
    } 


    envelope.Recipients = new DocuSignAPI.ArrayOfRecipient(); 
    envelope.Recipients.Recipient = new DocuSignAPI.Recipient[2];      

    // Recipient 1 
    DocuSignAPI.Recipient recipient = new DocuSignAPI.Recipient(); 
    recipient.ID = 1; 
    //recipient.RequireSignerCertificate = 'OpenTrust'; 
    recipient.Type_x = 'InPersonSigner'; 
    recipient.CaptiveInfo = new DocuSignAPI.RecipientCaptiveInfo(); 
    recipient.CaptiveInfo.ClientUserId = '1';      
    recipient.RoleName = 'Signer 1'; 
    recipient.RoutingOrder = 1; 
    recipient.Email = '[email protected]'; 
    recipient.UserName = 'recipient1 test'; 
    recipient.SignerName = 'recipient1 test'; 
    recipient.RequireIDLookup = false;        
    envelope.Recipients.Recipient[0] = recipient; 

    //Recipient2 
    DocuSignAPI.Recipient recipient2 = new DocuSignAPI.Recipient(); 
    recipient2.ID = 2; 
    //recipient2.RequireSignerCertificate = 'OpenTrust';  
    recipient2.Type_x = 'InPersonSigner'; 
    recipient2.Email = '[email protected]'; 
    recipient2.UserName = 'recipient1 test';      
    recipient2.SignerName = 'Person 2'; 
    recipient2.CaptiveInfo = new DocuSignAPI.RecipientCaptiveInfo(); 
    recipient2.CaptiveInfo.ClientUserId = '2';     
    recipient2.RoleName = 'Signer 2'; 
    recipient2.RoutingOrder = 2;  
    envelope.Recipients.Recipient[1] = recipient2;    

    envelope.Tabs = new DocuSignAPI.ArrayOfTab(); 
    envelope.Tabs.Tab = new DocuSignAPI.Tab[2]; 

    // Tab - Apporteur 
    DocuSignAPI.Tab tab1 = new DocuSignAPI.Tab(); 
    tab1.Type_x = 'SignHere'; 
    tab1.RecipientID = 1; 
    tab1.DocumentID = 1; 
    tab1.AnchorTabItem = new DocuSignAPI.AnchorTab(); 
    tab1.AnchorTabItem.AnchorTabString = 's1'; 
    envelope.Tabs.Tab[0] = tab1; 

    // Tab - Souscripteur 
    DocuSignAPI.Tab tab2 = new DocuSignAPI.Tab(); 
    tab2.Type_x = 'SignHere'; 
    tab2.RecipientID = 2; 
    tab2.DocumentID = 1; 
    tab2.AnchorTabItem = new DocuSignAPI.AnchorTab(); 
    tab2.AnchorTabItem.AnchorTabString = 's2'; 
    envelope.Tabs.Tab[1] = tab2; 

    //I - Send Enveloppe 
    DocuSignAPI.EnvelopeStatus es = dsApiSend.CreateAndSendEnvelope(envelope); 
    envelopeId = es.EnvelopeID; 


    //II - Get Signing Toekn 
    Blob b = Crypto.GenerateAESKey(128); 
    String h = EncodingUtil.ConvertTohex(b); 
    String guid = h.SubString(0,8)+ '-' + h.SubString(8,12) + '-' + h.SubString(12,16) + '-' + h.SubString(16,20) + '-' + h.substring(20); 

    DocuSignAPI.RequestRecipientTokenAuthenticationAssertion assertion = new DocuSignAPI.RequestRecipientTokenAuthenticationAssertion(); 
    assertion.AssertionID = guid; 
    assertion.AuthenticationInstant = DateTime.Now(); 
    assertion.AuthenticationMethod = 'Email'; 
    assertion.SecurityDomain = 'force.com'; 

    // Construct the URLs based on username 
    DocuSignAPI.RequestRecipientTokenClientURLs urls = new DocuSignAPI.RequestRecipientTokenClientURLs(); 
    String urlBase = URL.getSalesforceBaseUrl().toExternalForm()+'/'+RecordId; 
    urls.OnSigningComplete = urlBase + '?event=SignComplete&uname=' + recipient.UserName; 
    urls.OnViewingComplete = urlBase + '?event=ViewComplete&uname=' + recipient.UserName; 
    urls.OnCancel = urlBase + '?event=Cancel&uname=' + recipient.UserName; 
    urls.OnDecline = urlBase + '?event=Decline&uname=' + recipient.UserName; 
    urls.OnSessionTimeout = urlBase + '?event=Timeout&uname=' + recipient.UserName; 
    urls.OnTTLExpired = urlBase + '?event=TTLExpired&uname=' + recipient.UserName; 
    urls.OnIdCheckFailed = urlBase + '?event=IDCheck&uname=' + recipient.UserName; 
    urls.OnAccessCodeFailed = urlBase + '?event=AccessCode&uname=' + recipient.UserName; 
    urls.OnException = urlBase + '?event=Exception&uname=' + recipient.UserName; 

    //Request second person token 
    string RecipientToken = dsApiSend.RequestRecipientToken(
     es.EnvelopeID, 
     recipient.CaptiveInfo.ClientUserId, 
     recipient.UserName, 
     recipient.Email, 
     assertion, 
     urls); 

    //Request second person token 
    string RecipientToken2 = dsApiSend.RequestRecipientToken(
     es.EnvelopeID, 
     recipient2.CaptiveInfo.ClientUserId, 
     recipient2.UserName, 
     recipient2.Email, 
     assertion, 
     urls); 

    //Add the token of the second recipient in the Signing complete of the first 
    //urls.OnSigningComplete = RecipientToken2; 



    Pagereference tokenpage = new Pagereference(RecipientToken); 
    return tokenpage.setRedirect(true); 
+0

爲什麼你不創建信封,爲收件人#1(應該工作)生成收件人標記,當該人完成了他們的部分時,就會爲收件人#2生成收件人標記。 – Andrew 2014-09-24 20:43:01

回答

1

的核心要求(對於OpenTrust簽名)是收件人必須被設置爲連續的路由(例如RoutingOrder 1和2的每個接收方)。在順序路由中,一次只有一個收件人處於活動狀態。一旦簽名者1簽名,他們被標記爲完成並且簽名者2然後變成活動的。

收件人只能在它們處於活動狀態時進行簽名。這也適用於獲取收件人令牌。您只能爲活躍的簽名者獲取令牌。

請注意,人員簽名實際上並不要求收件人處於相同的路由順序。

解決方案的關鍵是僅在第一個收件人簽名後請求第二個收件人令牌。第一個會話的着陸URL應指向一個音頻頁面 - 例如,可能會將信封ID作爲參數(或記錄的對象ID)。該VF頁面的控制器將請求第二個簽名者的收件人令牌,並重定向到該URL或將其作爲IFrame中的源URL返回。

+0

謝謝。有效。我有OpenTrust的另一個問題,但是我可以用不同的路由指令來做一個inperson簽名。 – Serouj 2014-09-30 18:01:25

相關問題