示例#1
0
 public void AddDefaultHeader(string key, string value)
 {
     Configuration.AddDefaultHeader(key, value);
 }
示例#2
0
        public IActionResult Create(PermissionProfileModel permissionProfileModel)
        {
            // Check the token with minimal buffer time.
            bool tokenOk = CheckToken(3);

            if (!tokenOk)
            {
                // We could store the parameters of the requested operation so it could be
                // restarted automatically. But since it should be rare to have a token issue
                // here, we'll make the user re-enter the form data after authentication.
                RequestItemsService.EgName = EgName;
                return(Redirect("/ds/mustAuthenticate"));
            }

            // Data for this method
            // signerEmail
            // signerName
            var basePath = RequestItemsService.Session.BasePath + "/restapi";

            // Step 1. Obtain your OAuth token
            var accessToken = RequestItemsService.User.AccessToken;            // Represents your {ACCESS_TOKEN}
            var accountId   = RequestItemsService.Session.AccountId;           // Represents your {ACCOUNT_ID}

            // Step 2. Construct your API headers
            var config = new Configuration(new ApiClient(basePath));

            config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
            AccountsApi accountsApi = new AccountsApi(config);



            // Step 3. Construct your request
            var accountRoleSettings = new AccountRoleSettingsExtension();

            accountRoleSettings.UseNewDocuSignExperienceInterface = "1";
            accountRoleSettings.EnableSequentialSigningInterface  = true.ToString();
            accountRoleSettings.PowerFormRole = "admin";
            accountRoleSettings.VaultingMode  = "none";
            accountRoleSettings.AllowTaggingInSendAndCorrect = true.ToString();
            accountRoleSettings.AllowedAddressBookAccess     = "personalAndShared";
            accountRoleSettings.AllowedTemplateAccess        = "share";
            accountRoleSettings.SigningUiVersion             = "2";

            // Present on PermissionProfileView.
            accountRoleSettings.AllowBulkSending                                = permissionProfileModel.AccountRoleSettingsModel.AllowBulkSending.ToString();
            accountRoleSettings.AllowEnvelopeSending                            = permissionProfileModel.AccountRoleSettingsModel.AllowEnvelopeSending.ToString();
            accountRoleSettings.AllowSignerAttachments                          = permissionProfileModel.AccountRoleSettingsModel.AllowSignerAttachments.ToString();
            accountRoleSettings.AllowApiAccess                                  = permissionProfileModel.AccountRoleSettingsModel.AllowApiAccess.ToString();
            accountRoleSettings.AllowApiAccessToAccount                         = permissionProfileModel.AccountRoleSettingsModel.AllowApiAccessToAccount.ToString();
            accountRoleSettings.AllowApiSequentialSigning                       = permissionProfileModel.AccountRoleSettingsModel.AllowApiSequentialSigning.ToString();
            accountRoleSettings.EnableApiRequestLogging                         = permissionProfileModel.AccountRoleSettingsModel.EnableApiRequestLogging.ToString();
            accountRoleSettings.AllowApiSendingOnBehalfOfOthers                 = permissionProfileModel.AccountRoleSettingsModel.AllowApiSendingOnBehalfOfOthers.ToString();
            accountRoleSettings.AllowWetSigningOverride                         = permissionProfileModel.AccountRoleSettingsModel.AllowWetSigningOverride.ToString();
            accountRoleSettings.EnableRecipientViewingNotifications             = permissionProfileModel.AccountRoleSettingsModel.EnableRecipientViewingNotifications.ToString();
            accountRoleSettings.ReceiveCompletedSelfSignedDocumentsAsEmailLinks = permissionProfileModel.AccountRoleSettingsModel.ReceiveCompletedSelfSignedDocumentsAsEmailLinks.ToString();
            accountRoleSettings.UseNewSendingInterface                          = permissionProfileModel.AccountRoleSettingsModel.UseNewSendingInterface.ToString();
            accountRoleSettings.AllowDocuSignDesktopClient                      = permissionProfileModel.AccountRoleSettingsModel.AllowDocuSignDesktopClient.ToString();
            accountRoleSettings.AllowSendersToSetRecipientEmailLanguage         = permissionProfileModel.AccountRoleSettingsModel.AllowSendersToSetRecipientEmailLanguage.ToString();
            accountRoleSettings.AllowVaulting = permissionProfileModel.AccountRoleSettingsModel.AllowVaulting.ToString();
            accountRoleSettings.AllowedToBeEnvelopeTransferRecipient = permissionProfileModel.AccountRoleSettingsModel.AllowedToBeEnvelopeTransferRecipient.ToString();
            accountRoleSettings.EnableTransactionPointIntegration    = permissionProfileModel.AccountRoleSettingsModel.EnableTransactionPointIntegration.ToString();

            var newPermimssionProfile = new PermissionProfile(PermissionProfileName: permissionProfileModel.ProfileName, Settings: accountRoleSettings);

            try
            {
                // Step 4. Call the eSignature REST API
                var result = accountsApi.CreatePermissionProfile(accountId, newPermimssionProfile);

                ViewBag.h1      = "The permission profile was updated";
                ViewBag.message = $"The permission profile was created!<br />Permission profile ID: {result.PermissionProfileId}, name:{result.PermissionProfileName}.";
                return(View("example_done"));
            }
            catch (ApiException apiException)
            {
                ViewBag.errorCode    = apiException.ErrorCode;
                ViewBag.errorMessage = apiException.Message;
                return(View("Error"));
            }
        }
示例#3
0
        public IActionResult Create(string signerEmail, string signerName, string ccEmail, string ccName)
        {
            // Check the token with minimal buffer time
            bool tokenOk = CheckToken(3);

            if (!tokenOk)
            {
                // We could store the parameters of the requested operation so it could be
                // restarted automatically. But since it should be rare to have a token issue
                // here, we'll make the user re-enter the form data after authentication
                RequestItemsService.EgName = EgName;
                return(Redirect("/ds/mustAuthenticate"));
            }

            // The envelope will be sent first to the signer; after it is signed,
            // a copy is sent to the cc person
            //
            // Read files from a local directory
            // The reads could raise an exception if the file is not available!
            var basePath = RequestItemsService.Session.BasePath + "/restapi";

            // Step 1: Obtain your OAuth token
            var accessToken = RequestItemsService.User.AccessToken;  // Represents your {ACCESS_TOKEN}
            var accountId   = RequestItemsService.Session.AccountId; // Represents your {ACCOUNT_ID}

            // Step 2: Construct your API headers
            var config = new Configuration(new ApiClient(basePath));

            config.AddDefaultHeader("Authorization", "Bearer " + accessToken);

            // Step 3: Create Tabs and CustomFields
            // Set the values for the fields in the template
            // List item
            List colorPicker = new List
            {
                Value      = "green",
                DocumentId = "1",
                PageNumber = "1",
                TabLabel   = "list"
            };

            // Checkboxes
            Checkbox ckAuthorization = new Checkbox
            {
                TabLabel = "ckAuthorization",
                Selected = "true"
            };
            Checkbox ckAgreement = new Checkbox
            {
                TabLabel = "ckAgreement",
                Selected = "true"
            };

            RadioGroup radioGroup = new RadioGroup
            {
                GroupName = "radio1",
                // You only need to provide the readio entry for the entry you're selecting
                Radios = new List <Radio> {
                    new Radio {
                        Value = "white", Selected = "true"
                    }
                }
            };

            Text includedOnTemplate = new Text
            {
                TabLabel = "text",
                Value    = "Jabberywocky!"
            };

            // We can also add a new tab (field) to the ones already in the template
            Text addedField = new Text
            {
                DocumentId = "1",
                PageNumber = "1",
                XPosition  = "280",
                YPosition  = "172",
                Font       = "helvetica",
                FontSize   = "size14",
                TabLabel   = "added text field",
                Height     = "23",
                Width      = "84",
                Required   = "false",
                Bold       = "true",
                Value      = signerName,
                Locked     = "false",
                TabId      = "name"
            };

            // Add the tabs model (including the SignHere tab) to the signer.
            // The Tabs object wants arrays of the different field/tab types
            // Tabs are set per recipient/signer
            Tabs tabs = new Tabs
            {
                CheckboxTabs = new List <Checkbox> {
                    ckAuthorization, ckAgreement
                },
                RadioGroupTabs = new List <RadioGroup> {
                    radioGroup
                },
                TextTabs = new List <Text> {
                    includedOnTemplate, addedField
                },
                ListTabs = new List <List> {
                    colorPicker
                }
            };

            // Create a signer recipient to sign the document, identified by name and email
            // We're setting the parameters via the object creation
            TemplateRole signer = new TemplateRole
            {
                Email        = signerEmail,
                Name         = signerName,
                RoleName     = "signer",
                ClientUserId = signerClientId, // Change the signer to be embedded
                Tabs         = tabs            //Set tab values
            };

            TemplateRole cc = new TemplateRole
            {
                Email    = ccEmail,
                Name     = ccName,
                RoleName = "cc"
            };

            // Create an envelope custom field to save our application's
            // data about the envelope
            TextCustomField customField = new TextCustomField
            {
                Name     = "app metadata item",
                Required = "false",
                Show     = "true", // Yes, include in the CoC
                Value    = "1234567"
            };

            CustomFields cf = new CustomFields
            {
                TextCustomFields = new List <TextCustomField> {
                    customField
                }
            };

            // Step 4: Create the envelope definition
            EnvelopeDefinition envelopeAttributes = new EnvelopeDefinition
            {
                // Uses the template ID received from example 08
                TemplateId = RequestItemsService.TemplateId,
                Status     = "Sent",
                // Add the TemplateRole objects to utilize a pre-defined
                // document and signing/routing order on an envelope.
                // Template role names need to match what is available on
                // the correlated templateID or else an error will occur
                TemplateRoles = new List <TemplateRole> {
                    signer, cc
                },
                CustomFields = cf
            };

            // Step 5: Call the eSignature REST API
            EnvelopesApi    envelopesApi = new EnvelopesApi(config);
            EnvelopeSummary results      = envelopesApi.CreateEnvelope(accountId, envelopeAttributes);

            // Step 6: Create the View Request
            RequestItemsService.EnvelopeId = results.EnvelopeId;
            RecipientViewRequest viewRequest = new RecipientViewRequest();

            // Set the URL where you want the recipient to go once they are done signing;
            // this should typically be a callback route somewhere in your app.
            // The query parameter is included as an example of how
            // to save/recover state information during the redirect to
            // the DocuSign signing ceremony. It's usually better to use
            // the session mechanism of your web framework. Query parameters
            // can be changed/spoofed very easily
            viewRequest.ReturnUrl = dsReturnUrl + "?state=123";

            // How has your app authenticated the user? In addition to your app's authentication,
            // you can include authentication steps from DocuSign; e.g., SMS authentication
            viewRequest.AuthenticationMethod = "none";

            // Recipient information must match the embedded recipient info
            // that we used to create the envelope
            viewRequest.Email        = signerEmail;
            viewRequest.UserName     = signerName;
            viewRequest.ClientUserId = signerClientId;

            // DocuSign recommends that you redirect to DocuSign for the
            // signing ceremony. There are multiple ways to save state.
            // To maintain your application's session, use the PingUrl
            // parameter. It causes the DocuSign Signing Ceremony web page
            // (not the DocuSign server) to send pings via AJAX to your app
            viewRequest.PingFrequency = "600"; // seconds
                                               // NOTE: The pings will only be sent if the pingUrl is an HTTPS address
            viewRequest.PingUrl = dsPingUrl;   // Optional setting

            ViewUrl results1 = envelopesApi.CreateRecipientView(accountId, results.EnvelopeId, viewRequest);
            //***********
            // Don't use an iframe with embedded signing requests!
            //***********
            // State can be stored/recovered using the framework's session or a
            // query parameter on the return URL (see the makeRecipientViewRequest method)
            string redirectUrl = results1.Url;

            return(Redirect(redirectUrl));
        }