|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +class Notary::Eg004SendWithThirdPartyNotaryService |
| 4 | + attr_reader :args |
| 5 | + |
| 6 | + include ApiCreator |
| 7 | + |
| 8 | + def initialize(args) |
| 9 | + @args = args |
| 10 | + end |
| 11 | + |
| 12 | + #ds-snippet-start:Notary4Step3 |
| 13 | + def worker |
| 14 | + # Create the envelope request object |
| 15 | + envelope_definition = make_envelope args[:envelope_args] |
| 16 | + # Call Envelopes::create API method |
| 17 | + # Exceptions will be caught by the calling function |
| 18 | + envelope_api = create_envelope_api(args) |
| 19 | + |
| 20 | + results = envelope_api.create_envelope args[:account_id], envelope_definition |
| 21 | + envelope_id = results.envelope_id |
| 22 | + { 'envelope_id' => envelope_id } |
| 23 | + end |
| 24 | + #ds-snippet-end:Notary4Step3 |
| 25 | + |
| 26 | + private |
| 27 | + |
| 28 | + #ds-snippet-start:Notary4Step2 |
| 29 | + def make_envelope(envelope_args) |
| 30 | + # document 1 (HTML) has tag **signature_1** |
| 31 | + # document 2 (DOCX) has tag /sn1/ |
| 32 | + # document 3 (PDF) has tag /sn1/ |
| 33 | + # |
| 34 | + # The envelope has two recipients: |
| 35 | + # recipient 1 - signer |
| 36 | + # recipient 2 - cc |
| 37 | + # The envelope will be sent first to the signer. |
| 38 | + # After it is signed, a copy is sent to the cc person |
| 39 | + |
| 40 | + # Create the envelope definition |
| 41 | + envelope_definition = DocuSign_eSign::EnvelopeDefinition.new |
| 42 | + |
| 43 | + envelope_definition.email_subject = 'Please sign this document set' |
| 44 | + |
| 45 | + # Add the document |
| 46 | + doc_b64 = Base64.encode64(File.binread(envelope_args[:doc_pdf])) |
| 47 | + |
| 48 | + # Create the document model |
| 49 | + document = DocuSign_eSign::Document.new( |
| 50 | + # Create the Docusign document object |
| 51 | + documentBase64: doc_b64, |
| 52 | + name: 'Order acknowledgement', # Can be different from actual file name |
| 53 | + fileExtension: 'html', # Many different document types are accepted |
| 54 | + documentId: '1' # A label used to reference the doc |
| 55 | + ) |
| 56 | + |
| 57 | + # The order in the docs array determines the order in the envelope |
| 58 | + envelope_definition.documents = [document] |
| 59 | + |
| 60 | + # Create the signer recipient model |
| 61 | + signer = DocuSign_eSign::Signer.new |
| 62 | + signer.email = envelope_args[:signer_email] |
| 63 | + signer.name = envelope_args[:signer_name] |
| 64 | + signer.recipient_id = '1' |
| 65 | + signer.routing_order = '1' |
| 66 | + ## routingOrder (lower means earlier) determines the order of deliveries |
| 67 | + # to the recipients. Parallel routing order is supported by using the |
| 68 | + # same integer as the order for two or more recipients |
| 69 | + |
| 70 | + # Create signHere fields (also known as tabs) on the documents |
| 71 | + # We're using anchor (autoPlace) positioning |
| 72 | + # |
| 73 | + # The Docusign platform searches throughout your envelope's documents for matching |
| 74 | + # anchor strings. So the sign_here_2 tab will be used in both document 2 and 3 |
| 75 | + # since they use the same anchor string for their "signer 1" tabs. |
| 76 | + sign_here = DocuSign_eSign::SignHere.new( |
| 77 | + anchorString: '/sn1/', |
| 78 | + anchorYOffset: '10', |
| 79 | + anchorUnits: 'pixels', |
| 80 | + anchorXOffset: '20' |
| 81 | + ) |
| 82 | + |
| 83 | + # Add the tabs model (including the sign_here tabs) to the signer |
| 84 | + # The Tabs object takes arrays of the different field/tab types |
| 85 | + signer_tab = DocuSign_eSign::Tabs.new({ |
| 86 | + signHereTabs: [sign_here] |
| 87 | + }) |
| 88 | + |
| 89 | + signer.tabs = signer_tab |
| 90 | + |
| 91 | + notary_seal = DocuSign_eSign::NotarySeal.new( |
| 92 | + xPosition: '300', |
| 93 | + yPosition: '235', |
| 94 | + documentId: '1', |
| 95 | + pageNumber: '1', |
| 96 | + ) |
| 97 | + |
| 98 | + notary_sign_here = DocuSign_eSign::SignHere.new( |
| 99 | + xPosition: '300', |
| 100 | + yPosition: '150', |
| 101 | + documentId: '1', |
| 102 | + pageNumber: '1', |
| 103 | + ) |
| 104 | + |
| 105 | + notary_tabs = DocuSign_eSign::Tabs.new( |
| 106 | + signHereTabs: [notary_sign_here], |
| 107 | + notarySealTabs: [notary_seal] |
| 108 | + ) |
| 109 | + |
| 110 | + notary_recipient = DocuSign_eSign::NotaryRecipient.new( |
| 111 | + email: '', |
| 112 | + name: 'Notary', |
| 113 | + recipientId: '1', |
| 114 | + routingOrder: '1', |
| 115 | + tabs: notary_tabs, |
| 116 | + notaryType: 'remote', |
| 117 | + notarySourceType: 'thirdparty', |
| 118 | + notaryThirdPartyPartner: 'onenotary', |
| 119 | + recipientSignatureProviders: [ |
| 120 | + { |
| 121 | + sealDocumentsWithTabsOnly: 'false', |
| 122 | + signatureProviderName: 'ds_authority_idv', |
| 123 | + signatureProviderOptions: {} |
| 124 | + } |
| 125 | + ] |
| 126 | + ) |
| 127 | + |
| 128 | + # Add the recipients to the envelope object |
| 129 | + recipients = DocuSign_eSign::Recipients.new( |
| 130 | + signers: [signer], |
| 131 | + notary: [notary_recipient] |
| 132 | + ) |
| 133 | + # Request that the envelope be sent by setting status to "sent". |
| 134 | + # To request that the envelope be created as a draft, set status to "created" |
| 135 | + envelope_definition.recipients = recipients |
| 136 | + envelope_definition.status = 'sent' |
| 137 | + envelope_definition |
| 138 | + end |
| 139 | + #ds-snippet-end:Notary4Step2 |
| 140 | +end |
0 commit comments