|
| 1 | +package com.docusign.controller.eSignature.services; |
| 2 | + |
| 3 | +import com.docusign.controller.eSignature.examples.EnvelopeHelpers; |
| 4 | +import com.docusign.esign.api.EnvelopesApi; |
| 5 | +import com.docusign.esign.client.ApiException; |
| 6 | +import com.docusign.esign.model.*; |
| 7 | + |
| 8 | +import java.io.IOException; |
| 9 | +import java.time.Instant; |
| 10 | +import java.util.Arrays; |
| 11 | +import java.util.List; |
| 12 | +import java.util.Map; |
| 13 | + |
| 14 | +public final class MultipleDeliveryService { |
| 15 | + private static final String EMAIL_DELIVERY = "Email"; |
| 16 | + |
| 17 | + private static final String PDF_DOCUMENT_FILE_NAME = "World_Wide_Corp_lorem.pdf"; |
| 18 | + |
| 19 | + private static final String PDF_DOCUMENT_NAME = "Lorem Ipsum"; |
| 20 | + |
| 21 | + private static final String DOCX_DOCUMENT_FILE_NAME = "World_Wide_Corp_Battle_Plan_Trafalgar.docx"; |
| 22 | + |
| 23 | + private static final String DOCX_DOCUMENT_NAME = "Battle Plan"; |
| 24 | + |
| 25 | + private static final int ANCHOR_OFFSET_Y = 10; |
| 26 | + |
| 27 | + private static final int ANCHOR_OFFSET_X = 20; |
| 28 | + |
| 29 | + private static final String SIGNER_ID = "1"; |
| 30 | + |
| 31 | + private static final String CC_ID = "2"; |
| 32 | + |
| 33 | + public static EnvelopeSummary smsDelivery( |
| 34 | + EnvelopesApi envelopesApi, |
| 35 | + String accountId, |
| 36 | + EnvelopeDefinition envelope) throws ApiException { |
| 37 | + var createEnvelopeResponse = envelopesApi.createEnvelopeWithHttpInfo( |
| 38 | + accountId, |
| 39 | + envelope, |
| 40 | + envelopesApi.new CreateEnvelopeOptions() |
| 41 | + ); |
| 42 | + |
| 43 | + Map<String, List<String>> headers = createEnvelopeResponse.getHeaders(); |
| 44 | + java.util.List<String> remaining = headers.get("X-RateLimit-Remaining"); |
| 45 | + java.util.List<String> reset = headers.get("X-RateLimit-Reset"); |
| 46 | + |
| 47 | + if (remaining != null & reset != null) { |
| 48 | + Instant resetInstant = Instant.ofEpochSecond(Long.parseLong(reset.get(0))); |
| 49 | + System.out.println("API calls remaining: " + remaining); |
| 50 | + System.out.println("Next Reset: " + resetInstant); |
| 51 | + } |
| 52 | + |
| 53 | + return createEnvelopeResponse.getData(); |
| 54 | + } |
| 55 | + |
| 56 | + //ds-snippet-start:eSign46Step2 |
| 57 | + public static EnvelopeDefinition makeEnvelope( |
| 58 | + String signerName, |
| 59 | + String signerEmail, |
| 60 | + String countryCode, |
| 61 | + String signersPhoneNumber, |
| 62 | + String ccName, |
| 63 | + String ccEmail, |
| 64 | + String ccCountryCode, |
| 65 | + String carbonCopyPhoneNumber, |
| 66 | + String deliveryMethod, |
| 67 | + String status) throws IOException { |
| 68 | + |
| 69 | + Tabs signerTabs = EnvelopeHelpers.createSignerTabs( |
| 70 | + EnvelopeHelpers.createSignHere( |
| 71 | + "/sn1/", |
| 72 | + ANCHOR_OFFSET_Y, |
| 73 | + ANCHOR_OFFSET_X |
| 74 | + )); |
| 75 | + |
| 76 | + Signer signer = new Signer(); |
| 77 | + signer.setName(signerName); |
| 78 | + signer.setEmail(signerEmail); |
| 79 | + signer.setRecipientId(SIGNER_ID); |
| 80 | + signer.setRoutingOrder("1"); |
| 81 | + signer.setTabs(signerTabs); |
| 82 | + signer.setDeliveryMethod(EMAIL_DELIVERY); |
| 83 | + signer.setAdditionalNotifications(Arrays.asList( |
| 84 | + createAdditionalNotification(countryCode, signersPhoneNumber, deliveryMethod) |
| 85 | + )); |
| 86 | + |
| 87 | + CarbonCopy cc = new CarbonCopy(); |
| 88 | + cc.setName(ccName); |
| 89 | + cc.setEmail(ccEmail); |
| 90 | + cc.setRecipientId(CC_ID); |
| 91 | + cc.setRoutingOrder("2"); |
| 92 | + cc.setDeliveryMethod(EMAIL_DELIVERY); |
| 93 | + cc.setAdditionalNotifications(Arrays.asList( |
| 94 | + createAdditionalNotification(ccCountryCode, carbonCopyPhoneNumber, deliveryMethod) |
| 95 | + )); |
| 96 | + |
| 97 | + EnvelopeDefinition envelope = new EnvelopeDefinition(); |
| 98 | + envelope.setEmailSubject("Please sign this document set"); |
| 99 | + envelope.setDocuments( |
| 100 | + Arrays.asList( |
| 101 | + EnvelopeHelpers.createDocumentFromFile( |
| 102 | + DOCX_DOCUMENT_FILE_NAME, |
| 103 | + DOCX_DOCUMENT_NAME, |
| 104 | + "2" |
| 105 | + ), |
| 106 | + EnvelopeHelpers.createDocumentFromFile( |
| 107 | + PDF_DOCUMENT_FILE_NAME, |
| 108 | + PDF_DOCUMENT_NAME, |
| 109 | + "3" |
| 110 | + ) |
| 111 | + ) |
| 112 | + ); |
| 113 | + envelope.setRecipients(EnvelopeHelpers.createRecipients(signer, cc)); |
| 114 | + envelope.setStatus(status); |
| 115 | + |
| 116 | + return envelope; |
| 117 | + } |
| 118 | + |
| 119 | + private static RecipientAdditionalNotification createAdditionalNotification( |
| 120 | + String countryCode, |
| 121 | + String phoneNumber, |
| 122 | + String deliveryMethod) { |
| 123 | + |
| 124 | + RecipientPhoneNumber phone = new RecipientPhoneNumber(); |
| 125 | + phone.setCountryCode(countryCode); |
| 126 | + phone.setNumber(phoneNumber); |
| 127 | + |
| 128 | + RecipientAdditionalNotification notification = new RecipientAdditionalNotification(); |
| 129 | + notification.setSecondaryDeliveryMethod(deliveryMethod); |
| 130 | + notification.setPhoneNumber(phone); |
| 131 | + |
| 132 | + return notification; |
| 133 | + } |
| 134 | + //ds-snippet-end:eSign46Step2 |
| 135 | +} |
0 commit comments