|
| 1 | +import base64 |
| 2 | +from os import path |
| 3 | + |
| 4 | +from docusign_esign import EnvelopesApi, EnvelopeDefinition, Document, Signer, Notary, SignHere, Tabs, Recipients, \ |
| 5 | + NotarySeal, NotaryRecipient, RecipientSignatureProvider, RecipientSignatureProviderOptions |
| 6 | + |
| 7 | +from ...consts import demo_docs_path, pattern |
| 8 | +from ...jwt_helpers import create_api_client |
| 9 | + |
| 10 | + |
| 11 | +class Eg004SendWithThirdPartyNotary: |
| 12 | + |
| 13 | + @classmethod |
| 14 | + def worker(cls, args): |
| 15 | + """ |
| 16 | + 1. Create the envelope request object |
| 17 | + 2. Send the envelope |
| 18 | + """ |
| 19 | + |
| 20 | + envelope_args = args["envelope_args"] |
| 21 | + # Create the envelope request object |
| 22 | + envelope_definition = cls.make_envelope(envelope_args) |
| 23 | + #ds-snippet-start:Notary4Step2 |
| 24 | + api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"]) |
| 25 | + envelopes_api = EnvelopesApi(api_client) |
| 26 | + #ds-snippet-end:Notary4Step2 |
| 27 | + |
| 28 | + #ds-snippet-start:Notary4Step4 |
| 29 | + results = envelopes_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition) |
| 30 | + #ds-snippet-end:Notary4Step4 |
| 31 | + |
| 32 | + envelope_id = results.envelope_id |
| 33 | + |
| 34 | + return {"envelope_id": envelope_id} |
| 35 | + |
| 36 | + #ds-snippet-start:Notary4Step3 |
| 37 | + @classmethod |
| 38 | + def make_envelope(cls, args): |
| 39 | + """ |
| 40 | + Creates envelope |
| 41 | + Document 1: An HTML document. |
| 42 | + DocuSign will convert all of the documents to the PDF format. |
| 43 | + The recipients" field tags are placed using <b>anchor</b> strings. |
| 44 | + """ |
| 45 | + |
| 46 | + # document 1 (html) has sign here anchor tag **signature_1** |
| 47 | + # |
| 48 | + # The envelope has two recipients. |
| 49 | + # recipient 1 - signer |
| 50 | + # The envelope will be sent first to the signer. |
| 51 | + |
| 52 | + # create the envelope definition |
| 53 | + env = EnvelopeDefinition( |
| 54 | + email_subject="Please sign this document set" |
| 55 | + ) |
| 56 | + doc1_b64 = base64.b64encode(bytes(cls.create_document1(args), "utf-8")).decode("ascii") |
| 57 | + |
| 58 | + # Create the document models |
| 59 | + document1 = Document( # create the DocuSign document object |
| 60 | + document_base64=doc1_b64, |
| 61 | + name="Order acknowledgement", # can be different from actual file name |
| 62 | + file_extension="html", # many different document types are accepted |
| 63 | + document_id="1" # a label used to reference the doc |
| 64 | + ) |
| 65 | + # The order in the docs array determines the order in the envelope |
| 66 | + env.documents = [document1] |
| 67 | + |
| 68 | + # Create the signer recipient model |
| 69 | + signer1 = Signer( |
| 70 | + email=args["signer_email"], |
| 71 | + name=args["signer_name"], |
| 72 | + recipient_id="2", |
| 73 | + routing_order="1", |
| 74 | + client_user_id="1000", |
| 75 | + notary_id="1" |
| 76 | + ) |
| 77 | + # routingOrder (lower means earlier) determines the order of deliveries |
| 78 | + # to the recipients. Parallel routing order is supported by using the |
| 79 | + # same integer as the order for two or more recipients. |
| 80 | + |
| 81 | + # Create signHere fields (also known as tabs) on the documents, |
| 82 | + # We"re using anchor (autoPlace) positioning |
| 83 | + # |
| 84 | + # The DocuSign platform searches throughout your envelope"s |
| 85 | + # documents for matching anchor strings. So the |
| 86 | + # signHere2 tab will be used in both document 2 and 3 since they |
| 87 | + # use the same anchor string for their "signer 1" tabs. |
| 88 | + sign_here1 = SignHere( |
| 89 | + document_id="1", |
| 90 | + x_position="200", |
| 91 | + y_position="235", |
| 92 | + page_number="1" |
| 93 | + ) |
| 94 | + |
| 95 | + sign_here2 = SignHere( |
| 96 | + stamp_type="stamp", |
| 97 | + document_id="1", |
| 98 | + x_position="200", |
| 99 | + y_position="150", |
| 100 | + page_number="1" |
| 101 | + |
| 102 | + ) |
| 103 | + |
| 104 | + # Add the tabs model (including the sign_here tabs) to the signer |
| 105 | + # The Tabs object wants arrays of the different field/tab types |
| 106 | + signer1.tabs = Tabs(sign_here_tabs=[sign_here1, sign_here2]) |
| 107 | + |
| 108 | + notary_seal_tab = NotarySeal( |
| 109 | + x_position = "300", |
| 110 | + y_position = "235", |
| 111 | + document_id = "1", |
| 112 | + page_number = "1", |
| 113 | + ) |
| 114 | + |
| 115 | + notary_sign_here = SignHere( |
| 116 | + x_position = "300", |
| 117 | + y_position = "150", |
| 118 | + document_id = "1", |
| 119 | + page_number = "1", |
| 120 | + ) |
| 121 | + |
| 122 | + notary_tabs = Tabs( |
| 123 | + sign_here_tabs = [notary_sign_here], |
| 124 | + notary_seal_tabs = [ notary_seal_tab ], |
| 125 | + ) |
| 126 | + |
| 127 | + recipient_signature_provider = RecipientSignatureProvider( |
| 128 | + seal_documents_with_tabs_only = "false", |
| 129 | + signature_provider_name = "ds_authority_idv", |
| 130 | + signature_provider_options = RecipientSignatureProviderOptions() |
| 131 | + ) |
| 132 | + |
| 133 | + notary_recipient = NotaryRecipient( |
| 134 | + name = "Notary", |
| 135 | + recipient_id = "1", |
| 136 | + routing_order = "1", |
| 137 | + tabs = notary_tabs, |
| 138 | + notary_type = "remote", |
| 139 | + notary_source_type = "thirdparty", |
| 140 | + notary_third_party_partner = "onenotary", |
| 141 | + recipient_signature_providers = [recipient_signature_provider] |
| 142 | + ) |
| 143 | + |
| 144 | + # Add the recipients to the envelope object |
| 145 | + recipients = Recipients(signers=[signer1], notaries= [notary_recipient]) |
| 146 | + env.recipients = recipients |
| 147 | + |
| 148 | + # Request that the envelope be sent by setting |status| to "sent". |
| 149 | + # To request that the envelope be created as a draft, set to "created" |
| 150 | + env.status = args["status"] |
| 151 | + |
| 152 | + return env |
| 153 | + |
| 154 | + @classmethod |
| 155 | + def create_document1(cls, args): |
| 156 | + """ Creates document 1 -- an html document""" |
| 157 | + |
| 158 | + return f""" |
| 159 | + <!DOCTYPE html> |
| 160 | + <html> |
| 161 | + <head> |
| 162 | + <meta charset="UTF-8"> |
| 163 | + </head> |
| 164 | + <body style="font-family:sans-serif;margin-left:2em;"> |
| 165 | + <h1 style="font-family: "Trebuchet MS", Helvetica, sans-serif; |
| 166 | + color: darkblue;margin-bottom: 0;">World Wide Corp</h1> |
| 167 | + <h2 style="font-family: "Trebuchet MS", Helvetica, sans-serif; |
| 168 | + margin-top: 0px;margin-bottom: 3.5em;font-size: 1em; |
| 169 | + color: darkblue;">Order Processing Division</h2> |
| 170 | + <h4>Ordered by {args["signer_name"]}</h4> |
| 171 | + <p style="margin-top:0em; margin-bottom:0em;">Email: {args["signer_email"]}</p> |
| 172 | + <p style="margin-top:3em;"> |
| 173 | + Candy bonbon pastry jujubes lollipop wafer biscuit biscuit. Topping brownie sesame snaps sweet roll pie. |
| 174 | + Croissant danish biscuit soufflé caramels jujubes jelly. Dragée danish caramels lemon drops dragée. |
| 175 | + Gummi bears cupcake biscuit tiramisu sugar plum pastry. Dragée gummies applicake pudding liquorice. |
| 176 | + Donut jujubes oat cake jelly-o. |
| 177 | + Dessert bear claw chocolate cake gummies lollipop sugar plum ice cream gummies cheesecake. |
| 178 | + </p> |
| 179 | + <!-- Note the anchor tag for the signature field is in white. --> |
| 180 | + <h3 style="margin-top:3em;">Agreed: <span style="color:white;">**signature_1**/</span></h3> |
| 181 | + </body> |
| 182 | + </html> |
| 183 | + """ |
| 184 | + #ds-snippet-end:Notary4Step3 |
0 commit comments