示例#1
0
        public async Task <APIGatewayProxyResponse> FunctionHandler(System.IO.Stream apiProxyEvent, ILambdaContext context)
        {
            var secretManager = new SecretManager();
            var secret        = secretManager.GetSecret();

            SecretManager secretsKeys = JsonConvert.DeserializeObject <SecretManager>(secret);
            AppSettings   appSettings = AppSettings.GetAppSettings(secretsKeys.accountId, secretsKeys.integratorKey, secretsKeys.docuSignAuthEmail, secretsKeys.docuSignAuthPass);

            Console.WriteLine("The secretsKeys: " + secretsKeys.integratorKey);

            string strBodyRequest;
            string response        = "Invalid Request";
            string validateEnvelop = "No se pudo envíar el correo";
            int    IntStatusCode   = 400;

            using (var reader = new StreamReader(apiProxyEvent, Encoding.UTF8))
            {
                strBodyRequest = reader.ReadToEnd();
            }

            var         dicBody       = JsonConvert.DeserializeObject <Dictionary <string, string> >(strBodyRequest);
            RequestData ClientRequest = JsonConvert.DeserializeObject <RequestData>(dicBody["ClientRequest"]);
            Dictionary <string, string> dataPdfValues = JsonConvert.DeserializeObject <Dictionary <string, string> >(ClientRequest.pdfValues);

            string ds_signer1_name  = ClientRequest.signerName ?? signerName;
            string ds_signer1_email = ClientRequest.signerEmail ?? signerEmail;
            string webhook_url      = Environment.GetEnvironmentVariable("urlReturn") ?? returnUrl;
            string authHeader       = "{\"Username\":\"" + secretsKeys.docuSignAuthEmail + "\", \"Password\":\"" + secretsKeys.docuSignAuthPass + "\", \"IntegratorKey\":\"" + secretsKeys.integratorKey + "\"}";

            Task <List <string> > readS3TXT           = S3Data.ReadS3TXT("eSignature/FieldMapping/" + ClientRequest.fileName + ".txt");
            List <string>         mappingFileVarsList = await readS3TXT;

            Dictionary <string, SymitarVars> symitarVars = SymitarVars.getSymitarVars(mappingFileVarsList, dataPdfValues);

            if (!String.IsNullOrWhiteSpace(ds_signer1_email) && symitarVars.Count > 0 && !String.IsNullOrWhiteSpace(ClientRequest.fileName))
            {
                Task <Boolean> dateRequest      = sendRequestSign(ds_signer1_name, ds_signer1_email, secretsKeys.accountId, webhook_url, authHeader, symitarVars, ClientRequest.fileName);
                Boolean        activateFunction = await dateRequest;
                validateEnvelop = "Se envío el documento a " + ds_signer1_name + " " + ds_signer1_email;
            }

            switch (ClientRequest.requestEP)
            {
            //{'requestEP':'TEST'}
            case "TEST":
                response      = validateEnvelop;
                IntStatusCode = 200;
                break;

            case "ARRAY":
                response      = ClientRequest.requestData;
                IntStatusCode = 200;
                break;

            default:
                break;
            }

            if (IntStatusCode == 400)
            {
                response = "Error";
            }
            return(SendResponseToClient(response, IntStatusCode));
        }
示例#2
0
        public async Task <Boolean> sendRequestSign(string signerName, string signerEmail, string accountId, string returnUrl, string authHeader, Dictionary <string, SymitarVars> symitarVars, string fileName)
        {
            List <EnvelopeEvent> envelope_events = new List <EnvelopeEvent>();

            EnvelopeEvent envelope_event1 = new EnvelopeEvent();

            envelope_event1.EnvelopeEventStatusCode = "sent";
            envelope_events.Add(envelope_event1);
            EnvelopeEvent envelope_event2 = new EnvelopeEvent();

            envelope_event2.EnvelopeEventStatusCode = "delivered";
            envelope_events.Add(envelope_event2);
            EnvelopeEvent envelope_event3 = new EnvelopeEvent();

            envelope_event3.EnvelopeEventStatusCode = "completed";

            List <RecipientEvent> recipient_events = new List <RecipientEvent>();
            RecipientEvent        recipient_event1 = new RecipientEvent();

            recipient_event1.RecipientEventStatusCode = "Sent";
            recipient_events.Add(recipient_event1);
            RecipientEvent recipient_event2 = new RecipientEvent();

            recipient_event2.RecipientEventStatusCode = "Delivered";
            recipient_events.Add(recipient_event2);
            RecipientEvent recipient_event3 = new RecipientEvent();

            recipient_event3.RecipientEventStatusCode = "Completed";

            EventNotification event_notification = new EventNotification();

            event_notification.Url                               = returnUrl;
            event_notification.LoggingEnabled                    = "true";
            event_notification.RequireAcknowledgment             = "true";
            event_notification.UseSoapInterface                  = "false";
            event_notification.IncludeCertificateWithSoap        = "false";
            event_notification.SignMessageWithX509Cert           = "false";
            event_notification.IncludeDocuments                  = "true";
            event_notification.IncludeEnvelopeVoidReason         = "true";
            event_notification.IncludeTimeZone                   = "true";
            event_notification.IncludeSenderAccountAsCustomField = "true";
            event_notification.IncludeDocumentFields             = "true";
            event_notification.IncludeCertificateOfCompletion    = "true";
            event_notification.EnvelopeEvents                    = envelope_events;
            event_notification.RecipientEvents                   = recipient_events;


            Tabs tabs = new Tabs();

            tabs.TextTabs       = new List <Text>();
            tabs.SignHereTabs   = new List <SignHere>();
            tabs.DateSignedTabs = new List <DateSigned>();
            int index = 1;

            foreach (KeyValuePair <string, SymitarVars> data in symitarVars)
            {
                System.Console.WriteLine(data.Value.FieldLabel);
                System.Console.WriteLine(data.Value.FieldValue);
                if (data.Value.FieldType.ToUpper() != "SETTING" && (data.Value.FieldType != "DocuSignField" || (data.Value.FieldType == "DocuSignField" && !String.IsNullOrWhiteSpace(data.Value.FieldValue))))
                {
                    switch (data.Value.FieldType)
                    {
                    case "DocuSignField":
                        Text text_tab = new Text();
                        text_tab.AnchorString  = "/*" + data.Value.FieldLabel + "*/";
                        text_tab.AnchorYOffset = "-8";
                        text_tab.AnchorXOffset = "0";
                        text_tab.RecipientId   = string.Concat("", index);
                        text_tab.TabLabel      = data.Value.FieldLabel;
                        text_tab.Name          = data.Value.FieldValue;
                        text_tab.Value         = data.Value.FieldValue;
                        // text_tab.Required = data.Value.Required;

                        tabs.TextTabs.Add(text_tab);
                        break;

                    case "SignatureField":
                        SignHere sign_here_tab = new SignHere();
                        sign_here_tab.AnchorString  = "/*" + data.Value.FieldLabel + "*/";
                        sign_here_tab.AnchorXOffset = "0";
                        sign_here_tab.AnchorYOffset = "0";
                        sign_here_tab.Name          = "";
                        sign_here_tab.Optional      = data.Value.Required;
                        sign_here_tab.ScaleValue    = "1";
                        sign_here_tab.TabLabel      = data.Value.FieldLabel;

                        tabs.SignHereTabs.Add(sign_here_tab);
                        break;

                    case "DateSigned":
                        DateSigned date_signed_tab = new DateSigned();
                        date_signed_tab.AnchorString  = "/*" + data.Value.FieldLabel + "*/";
                        date_signed_tab.AnchorYOffset = "-6";
                        date_signed_tab.RecipientId   = string.Concat("", index);
                        date_signed_tab.Name          = "";
                        date_signed_tab.TabLabel      = data.Value.FieldLabel;
                        // date_signed_tab.Required = data.Value.Required;

                        tabs.DateSignedTabs.Add(date_signed_tab);
                        break;

                    default:
                        break;
                        index++;
                    }
                }
            }

            Signer signer = new Signer();

            signer.Email        = signerEmail;
            signer.Name         = signerName;
            signer.RecipientId  = "1";
            signer.RoutingOrder = "1";
            signer.Tabs         = tabs;


            Task <Stream> getS3PDF = S3Data.ReadS3PDF("eSignature/PDFTemplate/" + fileName + ".pdf");
            Stream        newPdf   = await getS3PDF;
            var           bytes    = S3Data.ReadByteStream(newPdf);

            Document document = new Document();

            document.DocumentId = "1";
            document.Name       = fileName;

            // byte[] buffer = System.IO.File.ReadAllBytes("AUTOPYMT2.pdf");
            document.DocumentBase64 = Convert.ToBase64String(bytes);

            Recipients recipients = new Recipients();

            recipients.Signers = new List <Signer>();
            recipients.Signers.Add(signer);

            EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();

            envelopeDefinition.EmailSubject = "Please sign the " + "AUTOPYMT.pdf" + " document";
            envelopeDefinition.Documents    = new List <Document>();
            envelopeDefinition.Documents.Add(document);
            envelopeDefinition.Recipients        = recipients;
            envelopeDefinition.EventNotification = event_notification;
            envelopeDefinition.Status            = "sent";

            ApiClient apiClient = new ApiClient(basePath);

            apiClient.Configuration.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
            EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration);

            EnvelopeSummary envelope_summary = envelopesApi.CreateEnvelope(accountId, envelopeDefinition);

            if (envelope_summary == null || envelope_summary.EnvelopeId == null)
            {
                return(false);
            }

            // apiClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken);
            // EnvelopesApi envelopesApi = new EnvelopesApi(WebhookLibrary.Configuration);
            // EnvelopeSummary envelope_summary = envelopesApi.CreateEnvelope(WebhookLibrary.AccountId, envelope_definition, null);

            // string envelope_id = envelope_summary.EnvelopeId;
            Console.WriteLine(envelope_summary);
            return(true);
        }