Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DocuSign1 {
- public String sendEnvelope(String email, String name){
- String accountID = '2e415cc6-****-45c0-****-396d6b465b47';
- String userName = 'b43dbb12-****-****-****-a83b9b70087b';
- String passWord = '*********';
- String integratorKey = '78cbd017-****-4d3d-****-a12656f122bf';
- String templateID = '82dfbae3-****-4a6a-****-4c6145ca39d3';
- //This Endpoint supports creating an envelope with the templateId.
- String endPoint = 'https://demo.docusign.net/restapi/v2/accounts/'+accountID+'/envelopes';
- //Apex HTTP Method Initialization
- HttpRequest req = new HttpRequest();
- req.setEndpoint(endPoint);
- req.setMethod('POST');
- //req.setMethod('POST');
- //Authorization header generating using DocuSign credentials.
- String authorizationHeader = '<DocuSignCredentials><Username>'+userName+'</Username><Password>'+Password+'</Password><IntegratorKey>'+integratorKey+'</IntegratorKey></DocuSignCredentials>';
- req.setHeader('X-DocuSign-Authentication', authorizationHeader);
- req.setHeader('Accept','application/json');
- req.setHeader('Content-Length','162100');
- req.setHeader('Content-Type','application/json');
- req.setHeader('Content-Disposition','form-data');
- //JSON Request which contains template id and receivers email and name.
- String json='{'+
- ' '+
- ' "emailSubject": "Agreement",'+
- ' "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. ",'+
- ' "templateId": "'+templateID+'",'+
- ' "envelopeIdStamping": "false",'+
- ' "templateRoles": ['+
- ' {'+
- ' "roleName": "Signer 1",'+
- ' "name": "'+name+'",'+
- ' "email": "'+email+'",'+
- ' "recipientId": "1"'+
- ' }'+
- ' ],'+
- ' "status": "sent"'+
- '}';
- req.setBody(json);
- Http http = new Http();
- HTTPResponse res;
- try{
- //Docusign Request Callout.
- res = http.send(req);
- system.debug('DocuSign Response'+ res.getBody());
- }
- catch(Exception e){
- ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.FATAL, e.getMessage()));
- }
- return json;
- }
- }
- <aura:component controller="DocuSign1" implements="force:hasRecordId,force:lightningQuickAction,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes" access="global">
- <aura:attribute name="tokenvalue" type="string"/>
- <lightning:button variant="brand" label="SignHere" onclick="{!c.handleNext}"/>
- <iframe id="abc" src="{!v.tokenvalue}" />
- </aura:component>
- ({
- handleNext : function(component, event, helper) {
- console.log(component.get("v.recordId"));
- var action2 = component.get("c.sendEnvelope");
- action2.setParams({ "recordId" : component.get("v.recordId") });
- action2.setCallback(this, function(response1) {
- var state1 = response1.getState();
- alert(state1);
- if(state1 === "SUCCESS") {
- component.set("v.tokenvalue",response1.getReturnValue());
- //alert(response1.getReturnValue());
- //window.open(response1.getReturnValue());
- }
- });
- $A.enqueueAction(action2);
- }
- })
Add Comment
Please, Sign In to add comment