protected override void Execute(CodeActivityContext context) { Initialize(context); FormulaTab formulaTab; formula = Formula.Get(context); if (anchorText != null) { formulaTab = new FormulaTab(anchorText, offsetX + 12, offsetY, doc.documentId, pageNumber, toolTip, tabLabel, bold, italic, underline, font, fontColor, fontSize, width, value, formula, Shared); } else { formulaTab = new FormulaTab(sigX + 12, sigY, doc.documentId, pageNumber, toolTip, tabLabel, bold, italic, underline, font, fontColor, fontSize, width, value, formula, Shared); } AddTabToRecipient(formulaTab); }
private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, string ccEmail, string ccName) { // Data for this method // signerEmail // signerName // ccEmail // ccName // document 1 (html) has multiple tags: // /l1q/ and /l2q/ -- quantities: drop down // /l1e/ and /l2e/ -- extended: payment lines // /l3t/ -- total -- formula // // The envelope has two recipients. // recipient 1 - signer // recipient 2 - cc // The envelope will be sent first to the signer. // After it is signed, a copy is sent to the cc person. /////////////////////////////////////////////////////////////////// // // // NOTA BENA: This method programmatically constructs the // // order form. For many use cases, it would be // // better to create the order form as a template // // using the DocuSign web tool as a WYSIWYG // // form designer. // // // /////////////////////////////////////////////////////////////////// // Order form constants string l1Name = "Harmonica"; int l1Price = 5; string l1Description = $"${l1Price} each" , l2Name = "Xylophone"; int l2Price = 150; string l2Description = $"${l2Price} each"; int currencyMultiplier = 100; // read file from a local directory // The read could raise an exception if the file is not available! string doc1HTML1 = System.IO.File.ReadAllText("order_form.html"); // Substitute values into the HTML // Substitute for: {signerName}, {signerEmail}, {ccName}, {ccEmail} var doc1HTML2 = doc1HTML1.Replace("{signerName}", signerName) .Replace("{signerEmail}", signerEmail) .Replace("{ccName}", ccName) .Replace("{ccEmail}", ccEmail); // create the envelope definition EnvelopeDefinition env = new EnvelopeDefinition { EmailSubject = "Please complete your order" }; // add the documents string doc1b64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(doc1HTML2)); Document doc1 = new Document { DocumentBase64 = doc1b64, Name = "Order form", // can be different from actual file name FileExtension = "html", // Source data format. Signed docs are always pdf. DocumentId = "1" // a label used to reference the doc }; env.Documents = new List <Document> { doc1 }; // create a signer recipient to sign the document, identified by name and email // We're setting the parameters via the object creation Signer signer1 = new Signer { Email = signerEmail, Name = signerName, RecipientId = "1", RoutingOrder = "1" }; // routingOrder (lower means earlier) determines the order of deliveries // to the recipients. Parallel routing order is supported by using the // same integer as the order for two or more recipients. // create a cc recipient to receive a copy of the documents, identified by name and email // We're setting the parameters via setters CarbonCopy cc1 = new CarbonCopy { Email = ccEmail, Name = ccName, RoutingOrder = "2", RecipientId = "2" }; // Create signHere fields (also known as tabs) on the documents, // We're using anchor (autoPlace) positioning SignHere signHere1 = new SignHere { AnchorString = "/sn1/", AnchorYOffset = "10", AnchorUnits = "pixels", AnchorXOffset = "20" }; ListItem listItem0 = new ListItem { Text = "none", Value = "0" } , listItem1 = new ListItem { Text = "1", Value = "1" } , listItem2 = new ListItem { Text = "2", Value = "2" } , listItem3 = new ListItem { Text = "3", Value = "3" } , listItem4 = new ListItem { Text = "4", Value = "4" } , listItem5 = new ListItem { Text = "5", Value = "5" } , listItem6 = new ListItem { Text = "6", Value = "6" } , listItem7 = new ListItem { Text = "7", Value = "7" } , listItem8 = new ListItem { Text = "8", Value = "8" } , listItem9 = new ListItem { Text = "9", Value = "9" } , listItem10 = new ListItem { Text = "10", Value = "10" } ; List listl1q = new List { Font = "helvetica", FontSize = "size11", AnchorString = "/l1q/", AnchorYOffset = "-10", AnchorUnits = "pixels", AnchorXOffset = "0", ListItems = new List <ListItem> { listItem0, listItem1, listItem2, listItem3, listItem4, listItem5, listItem6, listItem7, listItem8, listItem9, listItem10 }, Required = "true", TabLabel = "l1q" }, listl2q = new List { Font = "helvetica", FontSize = "size11", AnchorString = "/l2q/", AnchorYOffset = "-10", AnchorUnits = "pixels", AnchorXOffset = "0", ListItems = new List <ListItem> { listItem0, listItem1, listItem2, listItem3, listItem4, listItem5, listItem6, listItem7, listItem8, listItem9, listItem10 }, Required = "true", TabLabel = "l2q" }; // create two formula tabs for the extended price on the line items FormulaTab formulal1e = new FormulaTab { Font = "helvetica", FontSize = "size11", AnchorString = "/l1e/", AnchorYOffset = "-8", AnchorUnits = "pixels", AnchorXOffset = "105", TabLabel = "l1e", Formula = $"[l1q] * {l1Price}", RoundDecimalPlaces = "0", Required = "true", Locked = "true", DisableAutoSize = "false", }, formulal2e = new FormulaTab { Font = "helvetica", FontSize = "size11", AnchorString = "/l2e/", AnchorYOffset = "-8", AnchorUnits = "pixels", AnchorXOffset = "105", TabLabel = "l2e", Formula = $"[l2q] * {l2Price}", RoundDecimalPlaces = "0", Required = "true", Locked = "true", DisableAutoSize = "false", }, // Formula for the total formulal3t = new FormulaTab { Font = "helvetica", Bold = "true", FontSize = "size12", AnchorString = "/l3t/", AnchorYOffset = "-8", AnchorUnits = "pixels", AnchorXOffset = "50", TabLabel = "l3t", Formula = $"[l1e] + [l2e]", RoundDecimalPlaces = "0", Required = "true", Locked = "true", DisableAutoSize = "false", }; // Payment line items PaymentLineItem paymentLineIteml1 = new PaymentLineItem { Name = l1Name, Description = l1Description, AmountReference = "l1e" }, paymentLineIteml2 = new PaymentLineItem { Name = l2Name, Description = l2Description, AmountReference = "l2e" }; PaymentDetails paymentDetails = new PaymentDetails { GatewayAccountId = Config.GatewayAccountId, CurrencyCode = "USD", GatewayName = Config.GatewayName, GatewayDisplayName = Config.GatewayDisplayName, LineItems = new List <PaymentLineItem> { paymentLineIteml1, paymentLineIteml2 } }; // Hidden formula for the payment itself FormulaTab formulaPayment = new FormulaTab { TabLabel = "payment", Formula = $"([l1e] + [l2e]) * {currencyMultiplier}", RoundDecimalPlaces = "0", PaymentDetails = paymentDetails, Hidden = "true", Required = "true", Locked = "true", DocumentId = "1", PageNumber = "1", XPosition = "0", YPosition = "0" }; // Tabs are set per recipient / signer Tabs signer1Tabs = new Tabs { SignHereTabs = new List <SignHere> { signHere1 }, ListTabs = new List <List> { listl1q, listl2q }, FormulaTabs = new List <FormulaTab> { formulal1e, formulal2e, formulal3t, formulaPayment } }; signer1.Tabs = signer1Tabs; // Add the recipients to the envelope object Recipients recipients = new Recipients { Signers = new List <Signer> { signer1 }, CarbonCopies = new List <CarbonCopy> { cc1 } }; env.Recipients = recipients; // Request that the envelope be sent by setting |status| to "sent". // To request that the envelope be created as a draft, set to "created" env.Status = RequestItemsService.Status; return(env); }
public static object CreateEnvelope_PersonalLoan(object[] reqArray, string accountId) { try { //list to store all objects that will be returned to Node.js List <object> rtn = new List <object>(); object nodeReqBody = reqArray[0]; //extract req.body from array passed in object nodeReqSession = reqArray[1]; //extract req.session from array passed in string nodeCurrentPath = reqArray[2].ToString(); //extract current path from array passed in //create dictionary from Node object and extract object values from request body var bodyDictionary = (IDictionary <string, object>)nodeReqBody; var body = new Body() { inputSigningLocation = (string)bodyDictionary["inputSigningLocation"], inputEmail = (string)bodyDictionary["inputEmail"], inputFirstName = (string)bodyDictionary["inputFirstName"], inputLastName = (string)bodyDictionary["inputLastName"], inputPhone = (string)bodyDictionary["inputPhone"], inputAddress1 = (string)bodyDictionary["inputAddress1"], inputAddress2 = (string)bodyDictionary["inputAddress2"], inputCity = (string)bodyDictionary["inputCity"], inputState = (string)bodyDictionary["inputState"], inputZip = (string)bodyDictionary["inputZip"], //the fields below may not exist (depending on the UI options selected, so test to see if they are in the dictionary first inputLoanAmount = bodyDictionary.ContainsKey("inputLoanAmount") ? (string)bodyDictionary["inputLoanAmount"] : "", inputLoanLength = bodyDictionary.ContainsKey("inputLoanLength") ? (string)bodyDictionary["inputLoanLength"] : "", inputAccessCode = bodyDictionary.ContainsKey("inputAccessCode") ? (string)bodyDictionary["inputAccessCode"] : "", inputAuthentication = bodyDictionary.ContainsKey("inputAuthentication") ? (string)bodyDictionary["inputAuthentication"] : "" }; // create a new envelope which we will use to send the signature request EnvelopeDefinition envDef = new EnvelopeDefinition(); envDef.EmailSubject = "Personal Loan Application"; envDef.EmailBlurb = "Please sign the Loan application to start the application process."; // add a document to the envelope var doc = new Document(); byte[] fileBytes = File.ReadAllBytes(nodeCurrentPath + "/pdfs/LoanPersonal.docx"); doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes); doc.Name = "Document"; // can be different from actual file name doc.FileExtension = "docx"; doc.DocumentId = "1"; // hardcode so we can easily refer to this document later //add document to envelope envDef.Documents = new List <Document>(); envDef.Documents.Add(doc); // Recipient Signer signer = new Signer(); signer.Email = body.inputEmail; signer.Name = body.inputFirstName + " " + body.inputLastName; signer.RecipientId = "1"; if (body.inputSigningLocation == "embedded") { signer.ClientUserId = "1001"; } // Note: using anchorStrings (in tabs below) makes documentId and pageNumber irrelevant (they affect all documents and pages) signer.Tabs = new Tabs(); // FullName signer.Tabs.FullNameTabs = new List <FullName>(); FullName fullName = new FullName(); fullName.RecipientId = "1"; fullName.AnchorString = "Name"; fullName.AnchorXOffset = "58"; fullName.AnchorYOffset = "-2"; fullName.TemplateLocked = "false"; signer.Tabs.FullNameTabs.Add(fullName); // Email signer.Tabs.EmailTabs = new List <Email>(); Email eMail = new Email(); eMail.RecipientId = "1"; eMail.Name = "Email"; eMail.TabLabel = "Email"; eMail.AnchorString = "Email"; eMail.AnchorXOffset = "55"; eMail.AnchorYOffset = "-2"; eMail.Value = body.inputEmail; signer.Tabs.EmailTabs.Add(eMail); // Phone signer.Tabs.TextTabs = new List <Text>(); Text text1 = new Text(); text1.RecipientId = "1"; text1.Name = "Phone"; text1.TabLabel = "Phone"; text1.AnchorString = "Phone"; text1.AnchorXOffset = "65"; text1.AnchorYOffset = "-2"; text1.Value = body.inputPhone; text1.Locked = "false"; signer.Tabs.TextTabs.Add(text1); // Address Line 1 //signer.Tabs.TextTabs = new List<Text>(); Text text2 = new Text(); text2.RecipientId = "1"; text2.Name = "AddressLine1"; text2.TabLabel = "AddressLine1"; text2.AnchorString = "Address"; text2.AnchorXOffset = "80"; text2.AnchorYOffset = "-2"; text2.Value = body.inputAddress1; text2.Locked = "false"; signer.Tabs.TextTabs.Add(text2); // Address Line 2 //signer.Tabs.TextTabs = new List<Text>(); Text text3 = new Text(); text3.RecipientId = "1"; text3.Name = "AddressLine2"; text3.TabLabel = "AddressLine2"; text3.AnchorString = "Address"; text3.AnchorXOffset = "80"; text3.AnchorYOffset = "20"; text3.Value = body.inputAddress2; text3.Required = "false"; text3.Locked = "false"; signer.Tabs.TextTabs.Add(text3); // Address city/state/zip //signer.Tabs.TextTabs = new List<Text>(); Text text4 = new Text(); text4.RecipientId = "1"; text4.Name = "AddressCityStateZip"; text4.TabLabel = "AddressCityStateZip"; text4.AnchorString = "Address"; text4.AnchorXOffset = "80"; text4.AnchorYOffset = "40"; text4.Value = body.inputCity + ", " + body.inputState + " " + body.inputZip; text4.Locked = "false"; signer.Tabs.TextTabs.Add(text4); // Amount signer.Tabs.NumberTabs = new List <Number>(); Number number1 = new Number(); number1.RecipientId = "1"; number1.Name = "Amount"; number1.TabLabel = "Amount"; number1.AnchorString = "Amount"; number1.AnchorXOffset = "75"; number1.AnchorYOffset = "-2"; number1.Locked = "false"; number1.Value = body.inputLoanAmount; signer.Tabs.NumberTabs.Add(number1); // Payment payback period (months) // signer.Tabs.NumberTabs = new List<Number>(); Number number2 = new Number(); number2.RecipientId = "1"; number2.Name = "PaymentDuration"; number2.TabLabel = "PaymentDuration"; number2.AnchorString = "Payment Duration"; number2.AnchorXOffset = "150"; number2.AnchorYOffset = "-2"; number2.Locked = "false"; number2.Value = body.inputLoanLength; signer.Tabs.NumberTabs.Add(number2); // Monthly payments (calculated field) signer.Tabs.FormulaTabs = new List <FormulaTab>(); FormulaTab formula = new FormulaTab(); formula.RecipientId = "1"; formula.Name = "MonthlyPayment"; formula.TabLabel = "MonthlyPayment"; formula.AnchorString = "Monthly Payment"; formula.AnchorXOffset = "180"; formula.AnchorYOffset = "-2"; formula.Formula = "[Amount]/[PaymentDuration]"; signer.Tabs.FormulaTabs.Add(formula); // SignHere signer.Tabs.SignHereTabs = new List <SignHere>(); SignHere signHere = new SignHere(); signHere.RecipientId = "1"; signHere.AnchorString = "DocuSign API rocks"; signHere.AnchorXOffset = "10"; signHere.AnchorYOffset = "60"; signer.Tabs.SignHereTabs.Add(signHere); // add recipients (in this case a single signer) to the envelope envDef.Recipients = new Recipients(); envDef.Recipients.Signers = new List <Signer>(); envDef.Recipients.Signers.Add(signer); if (body.inputSigningLocation == "embedded") { signer.ClientUserId = "1001"; } if (body.inputAuthentication == "phone") { Helper.addPhoneAuthToRecipient(signer, body.inputPhone); } if (body.inputAccessCode != "" && body.inputAccessCode.Length > 0) { signer.AccessCode = body.inputAccessCode; } // set envelope status to "sent" to immediately send the signature request envDef.Status = "sent"; EnvelopesApi envelopesApi = new EnvelopesApi(); EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef); rtn.Add(envelopeSummary); //Index 0: add envelopeSummary to the return object if (body.inputSigningLocation == "embedded") { ViewUrl viewUrl = Helper.getRecipientUrl(envelopesApi, accountId, envDef, envelopeSummary.EnvelopeId.ToString(), signer); rtn.Add(viewUrl); //Index 1: add viewURL to the return object } return(rtn); } catch (Exception ex) { MessageBox.Show(ex.Message); throw ex; } }
} // end createEmbeddedConsoleViewTest() //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public EnvelopeSummary requestPaymentOnDocumentTest() { // Enter your DocuSign credentials below. Note: You only need a DocuSign account to SEND documents, // signing is always free and signers do not need an account. string username = "******"; string password = "******"; // Enter recipient (signer) name and email address string recipientName = "[RECIPIENT_NAME]"; string recipientEmail = "[RECIPIENT_EMAIL]"; string paymentGatewayId = "[PAYMENT_GATEWAY_ID]"; // the document (file) we want signed const string SignTest1File = @"[PATH/TO/DOCUMENT/TEST.PDF]"; // instantiate api client with appropriate environment (for production change to www.docusign.net/restapi) configureApiClient("https://demo.docusign.net/restapi"); //=========================================================== // Step 1: Login() //=========================================================== // call the Login() API which sets the user's baseUrl and returns their accountId string accountId = loginApi(username, password); //=========================================================== // Step 2: Payment Request (AKA create & send Envelope) //=========================================================== // Read a file from disk to use as a document. byte[] fileBytes = File.ReadAllBytes(SignTest1File); EnvelopeDefinition envDef = new EnvelopeDefinition(); envDef.EmailSubject = "[DocuSign C# SDK] - Please Pay on this doc"; // Add a document to the envelope Document doc = new Document(); doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes); doc.Name = "TestFile.pdf"; doc.DocumentId = "1"; envDef.Documents = new List <Document>(); envDef.Documents.Add(doc); // Add a recipient to sign the documeent Signer signer = new Signer(); signer.Email = recipientEmail; signer.Name = recipientName; signer.RecipientId = "1"; // Create a NumberTab to hold payment information signer.Tabs = new Tabs(); signer.Tabs.NumberTabs = new List <Number>(); Number numberTab = new Number(); numberTab.DocumentId = "1"; numberTab.PageNumber = "1"; numberTab.RecipientId = "1"; numberTab.XPosition = "100"; numberTab.YPosition = "100"; numberTab.TabLabel = "tabvalue1"; numberTab.Value = "10.00"; numberTab.Locked = "true"; signer.Tabs.NumberTabs.Add(numberTab); // Create a FormulaTab to hold the payment, references NumberTab for amounts of lineItems signer.Tabs = new Tabs(); signer.Tabs.FormulaTabs = new List <FormulaTab>(); FormulaTab formulaTab = new FormulaTab(); formulaTab.Required = "true"; formulaTab.DocumentId = "1"; formulaTab.PageNumber = "1"; formulaTab.RecipientId = "1"; formulaTab.XPosition = "1"; // placement doesnt really matter, it doesnt show up formulaTab.YPosition = "1"; // placement doesnt really matter, it doesnt show up formulaTab.TabLabel = "tabpayment1"; formulaTab.Formula = "[tabvalue1] * 100"; formulaTab.RoundDecimalPlaces = "2"; // Create LineItems // - this is what will show up on receipts, credit card statements, and in your Payment Gateway PaymentLineItem lineItem = new PaymentLineItem(); lineItem.Name = 'Name1'; lineItem.Description = 'description1'; lineItem.ItemCode = 'ITEM1'; lineItem.AmountReference = 'tabvalue1'; PaymentDetails paymentDetails = new PaymentDetails(); paymentDetails.CurrencyCode = 'USD'; paymentDetails.GatewayAccountId = paymentGatewayId; paymentDetails.LineItems = new List <PaymentLineItem>(); paymentDetails.LineItems.Add(lineItem); formulaTab.PaymentDetails = paymentDetails; signer.Tabs.FormulaTabs.Add(formulaTab); envDef.Recipients = new Recipients(); envDef.Recipients.Signers = new List <Signer>(); envDef.Recipients.Signers.Add(signer); // set envelope status to "sent" to immediately send the signature request envDef.Status = "sent"; // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests) EnvelopesApi envelopesApi = new EnvelopesApi(); EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef); // print the JSON response Console.WriteLine("EnvelopeSummary:\n{0}", JsonConvert.SerializeObject(envelopeSummary)); return(envelopeSummary); } // end requestPaymentOnDocumentTest()