Guest User

Untitled

a guest
Dec 31st, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. public class DocuSign1 {
  2. public String sendEnvelope(String email, String name){
  3. String accountID = '2e415cc6-****-45c0-****-396d6b465b47';
  4. String userName = 'b43dbb12-****-****-****-a83b9b70087b';
  5. String passWord = '*********';
  6. String integratorKey = '78cbd017-****-4d3d-****-a12656f122bf';
  7. String templateID = '82dfbae3-****-4a6a-****-4c6145ca39d3';
  8. //This Endpoint supports creating an envelope with the templateId.
  9. String endPoint = 'https://demo.docusign.net/restapi/v2/accounts/'+accountID+'/envelopes';
  10. //Apex HTTP Method Initialization
  11. HttpRequest req = new HttpRequest();
  12. req.setEndpoint(endPoint);
  13. req.setMethod('POST');
  14. //req.setMethod('POST');    
  15. //Authorization header generating using DocuSign credentials.
  16. String authorizationHeader = '<DocuSignCredentials><Username>'+userName+'</Username><Password>'+Password+'</Password><IntegratorKey>'+integratorKey+'</IntegratorKey></DocuSignCredentials>';
  17. req.setHeader('X-DocuSign-Authentication', authorizationHeader);
  18. req.setHeader('Accept','application/json');
  19. req.setHeader('Content-Length','162100');
  20. req.setHeader('Content-Type','application/json');
  21. req.setHeader('Content-Disposition','form-data');
  22. //JSON Request which contains template id and receivers email and name.
  23. String json='{'+
  24. ' '+
  25. ' "emailSubject": "Agreement",'+
  26. ' "emailBlurb": "I am sending you this request for your electronic signature and enter or update confidential payment information.nnPlease review and electronically sign by following the link below. ",'+
  27. ' "templateId": "'+templateID+'",'+
  28. ' "envelopeIdStamping": "false",'+
  29. ' "templateRoles": ['+
  30. '  {'+
  31. '    "roleName": "Signer 1",'+
  32. '    "name": "'+name+'",'+
  33. '    "email": "'+email+'",'+
  34. '    "recipientId": "1"'+
  35. '   }'+
  36. ' ],'+
  37. ' "status": "sent"'+
  38. '}';
  39. req.setBody(json);
  40. Http http = new Http();
  41. HTTPResponse res;
  42. try{
  43. //Docusign Request Callout.
  44. res = http.send(req);
  45. system.debug('DocuSign Response'+ res.getBody());
  46. }
  47. catch(Exception e){
  48. ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.FATAL, e.getMessage()));
  49. }
  50. return json;
  51. }
  52. }
  53.  
  54. <aura:component controller="DocuSign1" implements="force:hasRecordId,force:lightningQuickAction,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes" access="global">
  55. <aura:attribute name="tokenvalue" type="string"/>
  56. <lightning:button variant="brand" label="SignHere" onclick="{!c.handleNext}"/>
  57. <iframe id="abc" src="{!v.tokenvalue}" />
  58. </aura:component>
  59.  
  60. ({
  61. handleNext : function(component, event, helper) {
  62. console.log(component.get("v.recordId"));
  63.  
  64. var action2 = component.get("c.sendEnvelope");
  65. action2.setParams({ "recordId" : component.get("v.recordId") });
  66. action2.setCallback(this, function(response1) {
  67. var state1 = response1.getState();
  68. alert(state1);
  69. if(state1 === "SUCCESS") {
  70. component.set("v.tokenvalue",response1.getReturnValue());
  71. //alert(response1.getReturnValue());
  72. //window.open(response1.getReturnValue());
  73. }
  74. });
  75. $A.enqueueAction(action2);
  76. }
  77. })
Add Comment
Please, Sign In to add comment