付款领域不工作

时间:2017-07-05 15:45:03

标签: docusignapi

我使用SOAP API创建嵌入式签名。我正在使用模板(CreateEnvelopeFromTemplates)来创建信封。我在模板上添加了一个付款字段,如果我从docusign网站发送信封请求,则可以正常工作。我得到一个弹出窗口输入付款信息。但是当我从API发送相同的模板时,付款功能无效。付款字段显示为数字。

screenshot

这是我的代码



public class DS_Recipe_Signer_View_Controller {
    // Embedded signing of an envelope
    // Copyright (c) 2016 DocuSign, Inc. 
    // LICENSE: The MIT License, see https://opensource.org/licenses/MIT

    // SETTINGS
//    Private static string integration_key = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
//    Private static string account_id =      'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; 
    Private static string integration_key = 'XXXXXXXXXX-98333677e8bd';
    Private static string account_id =      'XXXXXXXXXXX-5f66c17b7f9f'; 
        // NOTE: You MUST use the long form of the account id. It's has 32 digits 
        // with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). 
        // This version of the account id is shown in the APIs and Connects section
        // of your DocuSign Administration tool

    Public string signer_email {get;set;}   // Required
    Public string signer_name {get;set;}    // Required 
    Public string email_message {get;set;}  // Required
    Public string signer_user_id {get;set;}    // Required for embedded signing
    Public string signer_return_url {get;set;} // Required. Where DS redirects to after the signing ceremony  

    Public string output {get;set;}
    Public string envelope_id {get;set;}
    Public string signer_view_url {get;set;} // Redirect to this url  
    Public string error_code {get;set;} // Null means no error
    Public string error_message {get;set;}

    // Using Legacy authentication via an SFDC Named Credential
    Private static string ds_server = 'callout:DocuSign_Legacy_Demo/api/3.0/dsapi.asmx'; 
    // If you choose to not use a named credential:
     //Private static string ds_server = 'https://requestb.in/119qunn1';
    //Private static string ds_server ='https://demo.docusign.net/api/3.0/dsapi.asmx';
    
    Private static string trace_value = 'SFDC_002_SOAP_embedded_signing'; // Used for tracing API calls
    Private static string trace_key = 'X-ray';
    Private DocuSignTK.APIServiceSoap api_sender = new DocuSignTK.APIServiceSoap();

    Public DS_Recipe_Signer_View_Controller(){}
    
    Public void send(){
        configure_sender();
        send_envelope();
        embedded_signing();

        if (no_error()) {
            output = '<p>The envelope was sent, Envelope ID: ' + envelope_id + '</p>';
            output += '<p></p><p>Signer: ' + signer_name + ' &lt;' + signer_email + '&gt;</p>';
            output += '<p><b>To sign the envelope, redirect the user to the <a href = "' + 
                      signer_view_url + '" target="_blank">DocuSign Signing Ceremony</a></b></p>';
            output += '<p>The redirect address is ' + signer_view_url + '</p>';
            output += '<p><b>Note:</b> the Signing Ceremony url can only be used for a couple of minutes after ' +
                      'it has been created. Do NOT store the url for later use. Instead, ' +
                      'generate the URL immediately before you redirect the user\'s browser.</p>';
            output += '<p>After the signer has completed the signing ceremony, his ' +
                      'browser will be redirected back to your app with some query fields added. Example: </p>' +
                      '<p>http://www.foo.com/?event=signing_complete</p>';
        } else {
            output = '<h3>Problem</h3><p>' + error_message + '</p>';
        }
    }

    Private void configure_sender(){
        api_sender.endpoint_x = ds_server;
        api_sender.inputHttpHeaders_x = new Map<String, String>();
        String auth =   '<DocuSignCredentials><Username>{!$Credential.Username}</Username>' 
                      + '<Password>{!$Credential.Password}</Password>' 
                      + '<IntegratorKey>' + integration_key + '</IntegratorKey></DocuSignCredentials>';

        api_sender.inputHttpHeaders_x.put('X-DocuSign-Authentication', auth);
        api_sender.inputHttpHeaders_x.put(trace_key, trace_value);
    }

    Private void embedded_signing() {
        // Obtains the embedded Signing Ceremony URL for an envelope's recipient (the signer).
        // To use embedded signing:
        // 1. The signer must have been added to the envelope as a "captive signer"
        // 2. You need the following values:
        //    1. EnvelopeID
        //    2. Signer's Email that was provided when the signer was added to the envelope.
        //    3. Signer's name (UserName field)
        //    4. The Signer's User ID (client id) within your app. Must uniquely identify the signer. 
        // 3. You also need to create an "Assertion" object where you provide information on how
        //    your app authenticated the signer. This information is stored by DocuSign so you can
        //    later use the data in case of a dispute.

        // Incoming variables used:
        // envelope_id, signer_user_id, signer_email, signer_name

        // Maintaining state: when DocuSign redirects back to your app after the signing ceremony
        // ended, how does your app know what is going on? You can include additional query parameters
        // in the signer_return_url that you supply. Eg the recipient ID, envelope ID, etc.
        // You can include your app's sessionID. You can use the cookie system to store either
        // specific information or your stack's session id for your app.

        // Step 1. Create the assertion
        DocuSignTK.RequestRecipientTokenAuthenticationAssertion assertion = 
            new DocuSignTK.RequestRecipientTokenAuthenticationAssertion();
        assertion.AssertionID = '1'; // A unique identifier of the authentication 
            // event executed by your application.
        assertion.AuthenticationInstant = Datetime.now(); // The date/time that the end-user was authenticated.
        assertion.AuthenticationMethod = 'Password';      // How did your app authenticate the signer?
        // Options: Password, Email, PaperDocuments, HTTPBasicAuth, SSLMutualAuth, X509Certificate, Kerberos, 
        // SingleSignOn_CASiteminder, SingleSignOn_InfoCard, SingleSignOn_MicrosoftActiveDirectory, SingleSignOn_Passport, 
        // SingleSignOn_SAML, SingleSignOn_Other, Smartcard, RSASecureID, Biometric, None, KnowledgeBasedAuth
        assertion.SecurityDomain = 'DS_Recipe_Signer_View_Controller'; // The "domain" (app, sso system, etc) 
            // to which the user authenticated

        // Step 2. Create the redirect URLs for the different outcomes of the Signing Ceremony
        DocuSignTK.RequestRecipientTokenClientURLs urls = new DocuSignTK.RequestRecipientTokenClientURLs();
        String return_url_base = signer_return_url;
        // The supplied url may already include one or more query parameters. In that case, we're appending 
        // one more query parameters. Otherwiser, we're adding the first set of query parameters.
        // Look for a ? to see if the url already includes query parameters
        If (return_url_base.contains('?')) {
            return_url_base += '&event=';
        } Else {
            return_url_base += '?event=';
        }
        urls.OnSigningComplete  = return_url_base + 'signing_complete';
        urls.OnViewingComplete  = return_url_base + 'viewing_complete';
        urls.OnCancel           = return_url_base + 'cancel';
        urls.OnDecline          = return_url_base + 'decline';
        urls.OnSessionTimeout   = return_url_base + 'session_timeout';
        urls.OnTTLExpired       = return_url_base + 'ttl_expired';
        urls.OnException        = return_url_base + 'exception';
        urls.OnAccessCodeFailed = return_url_base + 'failed_access_code';
        urls.OnIdCheckFailed    = return_url_base + 'failed_id_check';
        urls.OnFaxPending       = return_url_base + 'fax_pending';

        // Step 3. Make the call
        try {
            signer_view_url = api_sender.RequestRecipientToken(
                envelope_id, signer_user_id, signer_name, signer_email, assertion, urls);
            System.debug('Received signer_view_url: = ' + signer_view_url);
        } catch ( CalloutException e) {
            System.debug('Exception - ' + e );
            error_code = 'Problem: ' + e;
            error_message = error_code;
        }      
    }


    Private void send_envelope() {
        // Sends an envelope. The first signer is "captive," so he can sign embedded

        // Check input
        if (String.isBlank(signer_email) || String.isBlank(signer_name) || !signer_email.contains('@')) {
            error_message = 'Please fill in the email and name fields';
            error_code = 'INPUT_PROBLEM';
            return;
        }

        // Check configuration
        if (integration_key == 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' ||
            account_id == 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') { 
            error_message = 'Please configure the Apex class DS_Recipe_Send_Env_Email_Controller with your integration key and account id.';
            error_code = 'CONFIGURATION_PROBLEM';
            return;
        }

        DocuSignTK.Recipient recipient = new DocuSignTK.Recipient();
        recipient.Email = signer_email; 
            
        recipient.UserName = signer_name;
        recipient.ID = 1;
        recipient.Type_x = 'Signer';
        recipient.RoutingOrder = 1;
        recipient.RoleName = 'Signer'; 
        // We want this signer to be "captive" so we can use embedded signing with him
        recipient.CaptiveInfo = new DocuSignTK.RecipientCaptiveInfo();
        recipient.CaptiveInfo.ClientUserID = signer_user_id; // Must uniquely identify the 

        DocuSignTK.ArrayOfRecipient1 recipients = new DocuSignTK.ArrayOfRecipient1();
        recipients.Recipient = new DocuSignTK.Recipient[1];
        recipients.Recipient[0] = recipient;
         
        // Create the template reference from a server-side template ID
        DocuSignTK.TemplateReference templateReference = new DocuSignTK.TemplateReference();
        templateReference.Template =  '37041580-9d59-4b41-a7c4-7c9bfa3b26c8';//'d0d80082-612b-4a04-b2a1-0672eb720491'; 
        templateReference.TemplateLocation = 'Server';
        //templateReference.Sequence = 1; 
        
        DocuSignTK.ArrayOfTemplateReferenceRoleAssignment Roles = new DocuSignTK.ArrayOfTemplateReferenceRoleAssignment();
        Roles.RoleAssignment = new DocuSignTK.TemplateReferenceRoleAssignment[1];
        
        DocuSignTK.TemplateReferenceRoleAssignment role = new DocuSignTK.TemplateReferenceRoleAssignment();
        role.RoleName = 'Signer';
        role.RecipientID = 1;
        Roles.RoleAssignment[0] = role;
        templateReference.RoleAssignments = Roles; 
        
        // Construct the envelope information
        DocuSignTK.EnvelopeInformation envelopeInfo = new DocuSignTK.EnvelopeInformation();
        envelopeInfo.AccountId = account_Id;
        envelopeInfo.Subject = 'Subject';
        envelopeInfo.EmailBlurb = 'Email content';


        DocuSignTK.TemplateReferenceFieldDataDataValue fd2 = new
        DocuSignTK.TemplateReferenceFieldDataDataValue();
        fd2.TabLabel = 'name';
        fd2.Value = 'recipient.UserName';
        
        DocuSignTK.TemplateReferenceFieldDataDataValue fd3 = new
        DocuSignTK.TemplateReferenceFieldDataDataValue();
        fd3.TabLabel = 'company';
        fd3.Value = 'company';


        templateReference.FieldData = new DocuSignTK.TemplateReferenceFieldData();
        templateReference.FieldData.DataValues = new
        DocuSignTK.ArrayOfTemplateReferenceFieldDataDataValue();
        templateReference.FieldData.DataValues.DataValue = new
        DocuSignTK.TemplateReferenceFieldDataDataValue[2];
        templateReference.FieldData.DataValues.DataValue[0] = fd2;
        templateReference.FieldData.DataValues.DataValue[1] = fd3;
        
        // Make the call
        try {
            //DocuSignTK.EnvelopeStatus result = api_sender.CreateAndSendEnvelope(envelope);
            // Create draft with all the template information
            DocuSignTK.ArrayOfTemplateReference TemplateReferenceArray = new DocuSignTK.ArrayOfTemplateReference();
            TemplateReferenceArray.TemplateReference = new DocuSignTK.TemplateReference[1];
            TemplateReferenceArray.TemplateReference[0] = templateReference;
            DocuSignTK.EnvelopeStatus result = api_sender.CreateEnvelopeFromTemplates( TemplateReferenceArray, recipients, envelopeInfo, true);
            envelope_id = result.EnvelopeID;
            System.debug('Returned successfully, envelope_id = ' + envelope_id );
        } catch ( CalloutException e) {
            System.debug('Exception - ' + e );
            error_code = 'Problem: ' + e;
            error_message = error_code;
        }      
    }

    Private Boolean no_error() {
        return (String.isEmpty(error_code));
    }

}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

DocuSign网站使用RESTAPI在信封中发送付款详细信息。 SOAP调用中不支持与支付相关的API,请尝试使用REST API进行与支付相关的调用。