示例#1
0
    def create_signature_from_document(self,
                                       signature,
                                       subject=u'',
                                       blurb=u'',
                                       sobo_email=None,
                                       **env_params):
        """Register ``signature`` in DocuSign service, for a signature from
        document.

        """
        # Prepare signers.
        signers = self.get_docusign_signers(signature)

        # Prepare documents.
        documents = []
        i = 1
        for document in signature.signature_documents():
            documents.append(
                pydocusign.Document(
                    name=document.name,
                    documentId=i,
                    data=document.bytes,
                ))
            i += 1
        # Create envelope with embedded signing.
        envelope = pydocusign.Envelope(emailSubject=subject,
                                       emailBlurb=blurb,
                                       status=pydocusign.Envelope.STATUS_SENT,
                                       documents=documents,
                                       recipients=signers,
                                       sobo_email=sobo_email,
                                       **env_params)
        envelope.envelopeId = self.docusign_client \
                                  .create_envelope_from_documents(envelope)
        return envelope
示例#2
0
 def test_create_envelope_from_document_request(self):
     """Request for creating envelope for document has expected format."""
     docusign = pydocusign.DocuSignClient()
     docusign.login_information()
     with open(os.path.join(pydocusign.test.fixtures_dir(), 'test.pdf'),
               'rb') as pdf_file:
         envelope = pydocusign.Envelope(emailSubject='This is the subject',
                                        emailBlurb='This is the body',
                                        status=models.ENVELOPE_STATUS_SENT,
                                        documents=[
                                            pydocusign.Document(
                                                name='document.pdf',
                                                documentId=1,
                                                data=pdf_file,
                                            ),
                                        ],
                                        recipients=[
                                            pydocusign.Signer(
                                                email='*****@*****.**',
                                                name='Zorro',
                                                recipientId=1,
                                                tabs=[
                                                    pydocusign.SignHereTab(
                                                        documentId=1,
                                                        pageNumber=1,
                                                        xPosition=100,
                                                        yPosition=100,
                                                    ),
                                                    pydocusign.ApproveTab(
                                                        documentId=1,
                                                        pageNumber=1,
                                                        xPosition=100,
                                                        yPosition=200,
                                                    ),
                                                ],
                                                accessCode='0000',
                                            ),
                                        ])
         parts = docusign._create_envelope_from_document_request(envelope)
     self.assertTrue(parts['url'].startswith(docusign.account_url))
     self.assertTrue(parts['url'].endswith('/envelopes'))
     self.assertEqual(parts['headers']['Content-Type'],
                      'multipart/form-data; boundary=myboundary')
     self.assertTrue(parts['body'].strip().startswith(
         '--myboundary\r\n'
         'Content-Type: application/json; charset=UTF-8\r\n'
         'Content-Disposition: form-data\r\n'
         '\r\n'))
示例#3
0
 def post_recipient_view(self, signer, signer_return_url=None):
     # Prepare signers.
     docusign_signers = self.get_docusign_signers(signer.signature)
     # Create envelope with embedded signing.
     envelope = pydocusign.Envelope(
         envelopeId=signer.signature.signature_backend_id,
         recipients=docusign_signers,
     )
     docusign_signer = [
         ds for ds in docusign_signers if ds.clientUserId == signer.pk
     ][0]
     if signer_return_url is None:
         signer_return_url = self.get_signer_return_url(signer)
     envelope.get_recipients(client=self.docusign_client)
     return envelope.post_recipient_view(client=self.docusign_client,
                                         recipient=docusign_signer,
                                         returnUrl=signer_return_url)
示例#4
0
    def create_and_send_envelope(self):
        from debra.models import Contract
        assert type(self.contract) == Contract

        self.contract.status = self.contract.STATUS_NON_SENT
        self.contract.save()

        event_notification = pydocusign.EventNotification(
            url=self.callback_url)

        if self.contract.info_json.get('agent_name'):
            signer_name = self.contract.info_json.get('agent_name')
        else:
            signer_name = self.contract.blogger.name or 'No blogger name'

        signer = pydocusign.Signer(
            email=self.blogger.emails[0],
            name=signer_name,
            recipientId=1,
            clientUserId=str(self.contract.id),
            tabs=self.tabs,
            emailSubject=Truncator(u'{} campaign contract for {}'.format(
                self.campaign.title, self.blogger.name
                or 'No blogger name')).chars(50),
            emailBody=Truncator(u'Thanks for participating in the {}.'.format(
                self.campaign.title)).chars(50),
        )

        envelope = pydocusign.Envelope(
            documents=self.docusign_documents,
            emailSubject=Truncator(u'{} campaign contract for {}'.format(
                self.campaign.title, self.blogger.name
                or 'No blogger name')).chars(50),
            emailBlurb=Truncator(u'Thanks for participating in the {}.'.format(
                self.campaign.title, )).chars(50),
            eventNotification=event_notification,
            status=pydocusign.Envelope.STATUS_SENT,
            recipients=[signer])
        client.create_envelope_from_document(envelope)

        self.contract.envelope = envelope.envelopeId
        self.contract.save()
示例#5
0
    def create_signature_from_template(self, signature, subject='', blurb='',
                                       sobo_email=None, **env_params):
        """Register ``signature`` in DocuSign service, for a signature from
        document.

        """
        # Prepare roles.
        roles = self.get_docusign_roles(signature)
        # Create envelope with embedded signing.
        envelope = pydocusign.Envelope(
            emailSubject=subject,
            emailBlurb=blurb,
            status=pydocusign.Envelope.STATUS_SENT,
            templateId=signature.signature_type.docusign_template_id,
            templateRoles=roles,
            sobo_email=sobo_email,
            **env_params
        )
        envelope.envelopeId = self.docusign_client \
                                  .create_envelope_from_template(envelope)
        return envelope
示例#6
0
]

# Create envelope with embedded signing.
print("2. POST {account}/envelopes")
document_path = os.path.join(fixtures_dir(), 'test.pdf')
document_2_path = os.path.join(fixtures_dir(), 'test2.pdf')
with open(document_path, 'rb') as pdf, open(document_2_path, 'rb') as pdf_2:
    envelope = pydocusign.Envelope(
        documents=[
            pydocusign.Document(
                name='document.pdf',
                documentId=1,
                data=pdf,
            ),
            pydocusign.Document(
                name='document_2.pdf',
                documentId=2,
                data=pdf_2,
            ),
        ],
        emailSubject='This is the subject',
        emailBlurb='This is the body',
        status=pydocusign.Envelope.STATUS_SENT,
        recipients=signers,
    )
    client.create_envelope_from_documents(envelope)
print("   Received envelopeId {id}".format(id=envelope.envelopeId))

# Update recipient list of envelope: fetch envelope's ``UserId`` from DocuSign.
print("3. GET {account}/envelopes/{envelopeId}/recipients")
envelope.get_recipients()
print("   Received UserId for recipient 0: {0}".format(
示例#7
0
def getLinkFromPDF():
    try:
        raw_input
    except NameError:
        raw_input = input

    def prompt(environ_key, description, default):
        try:
            return os.environ[environ_key]
        except KeyError:
            value = raw_input('{description} (default: "{default}"): '.format(
                default=default, description=description))
            if not value:
                return default
            else:
                return value

    # Get configuration from environment or prompt the user...
    root_url = 'https://demo.docusign.net/restapi/v2'
    username = '******'
    password = '******'
    integrator_key = '886c800a-506f-45c7-8db2-a19ab7d4b0a6'
    callback_url = 'www.google.com'
    signer_return_url = 'www.google.com'

    # Create a client.
    client = pydocusign.DocuSignClient(
        root_url=root_url,
        username=username,
        password=password,
        integrator_key=integrator_key,
    )

    # Login. Updates API URLs in client.
    print("1. GET /login_information")
    login_information = client.login_information()
    print("   Received data: {data}".format(data=login_information))

    #Prepare list of signers. Ordering matters.
    signers = [
        pydocusign.Signer(
            email='*****@*****.**',
            name=u'Spencer King',
            recipientId=1,
            clientUserId=str(
                uuid.uuid4()),  # Something unique in your database.
            tabs=[
                pydocusign.SignHereTab(
                    documentId=1,
                    pageNumber=1,
                    xPosition=100,
                    yPosition=200,
                ),
            ],
            emailSubject='Test PDF Docusign Script',
            emailBody='I am testing the docusign script',
            supportedLanguage='en',
        ),
        pydocusign.Signer(
            email='*****@*****.**',
            name=u'Eduardo Lopez',
            recipientId=2,
            clientUserId=str(
                uuid.uuid4()),  # Something unique in your database.
            # tabs=[],  # No tabs means user places tabs himself in DocuSign UI.
            tabs=[
                pydocusign.SignHereTab(
                    documentId=1,
                    pageNumber=1,
                    xPosition=100,
                    yPosition=400,
                ),
            ],
            emailSubject='Well docusign is working',
            emailBody=
            'Figured out how to take a text doc, pdf it, and create and send the signing request, woohoo',
            supportedLanguage='en',
        ),
    ]

    # Create envelope with embedded signing.
    print("2. POST {account}/envelopes")
    event_notification = pydocusign.EventNotification(url=callback_url, )
    document_path = "./Client_Contracts/Final.pdf"  # os.path.join(fixtures_dir(), 'test.pdf')
    #document_2_path = "./test2.pdf"      # os.path.join(fixtures_dir(), 'test2.pdf')
    with open(document_path,
              'rb') as pdf:  #, open(document_2_path, 'rb') as pdf_2:
        envelope = pydocusign.Envelope(
            documents=[
                pydocusign.Document(
                    name='HelloWorldTest.pdf',
                    documentId=1,
                    data=pdf,
                )
            ],
            emailSubject=
            'What does this do - 1',  # Title in docusign demo/sent view
            emailBlurb='What does this do - 2',
            eventNotification=event_notification,
            status=pydocusign.Envelope.STATUS_SENT,
            recipients=signers,
        )
        client.create_envelope_from_documents(envelope)
    print("   Received envelopeId {id}".format(id=envelope.envelopeId))

    # Update recipient list of envelope: fetch envelope's ``UserId`` from DocuSign.
    print("3. GET {account}/envelopes/{envelopeId}/recipients")
    envelope.get_recipients()
    print("   Received UserId for recipient 0: {0}".format(
        envelope.recipients[0].userId))
    print("   Received UserId for recipient 1: {0}".format(
        envelope.recipients[1].userId))

    # Retrieve embedded signing for first recipient.
    print("4. Get DocuSign Recipient View")
    signing_url = envelope.post_recipient_view(envelope.recipients[0],
                                               returnUrl=signer_return_url)
    print("   Received signing URL for recipient 0: {0}".format(signing_url))
    signing_url = envelope.post_recipient_view(envelope.recipients[1],
                                               returnUrl=signer_return_url)
    print("   Received signing URL for recipient 1: {0}".format(signing_url))

    # Download signature documents.
    print("5. List signature documents.")
    document_list = envelope.get_document_list()
    print("   Received document list: {0}".format(document_list))
    print("6. Download documents from DocuSign.")
    for signed_document in document_list:
        document = envelope.get_document(signed_document['documentId'])
        document_sha = hashlib.sha1(document.read()).hexdigest()
        print("   Document SHA1: {0}".format(document_sha))
    print("7. Download signature certificate from DocuSign.")
    document = envelope.get_certificate()
    document_sha = hashlib.sha1(document.read()).hexdigest()
    print("   Certificate SHA1: {0}".format(document_sha))

    URLS = [
        envelope.post_recipient_view(  # Recipient URL 1
            envelope.recipients[0],
            returnUrl=signer_return_url),
        envelope.post_recipient_view(  # Recipient URL 2
            envelope.recipients[1],
            returnUrl=signer_return_url)
    ]

    return URLS
示例#8
0
        name=u'Paul English',
        roleName='employee',
        clientUserId=str(uuid.uuid4()),  # Something unique in your database.
    ),
]


# Create envelope with embedded signing.
print("3. POST {account}/envelopes")
event_notification = pydocusign.EventNotification(
    url=callback_url,
)
envelope = pydocusign.Envelope(
    emailSubject='This is the subject',
    emailBlurb='This is the body',
    eventNotification=event_notification,
    status=pydocusign.Envelope.STATUS_SENT,
    templateId=template_id,
    templateRoles=roles,
)
client.create_envelope_from_template(envelope)
print("   Received envelopeId {id}".format(id=envelope.envelopeId))


# Update recipient list of envelope: fetch envelope's ``UserId`` from DocuSign.
print("4. GET {account}/envelopes/{envelopeId}/recipients")
envelope.get_recipients()
print("   Received UserId for recipient 0: {0}".format(
    envelope.recipients[0].userId))
print("   Received UserId for recipient 1: {0}".format(
    envelope.recipients[1].userId))
# Create envelope with embedded signing.
print("2. POST {account}/envelopes")
event_notification = pydocusign.EventNotification(
    url=callback_url,
)
document_path = "./hw.pdf"        # os.path.join(fixtures_dir(), 'test.pdf')
#document_2_path = "./test2.pdf"      # os.path.join(fixtures_dir(), 'test2.pdf')
with open(document_path, 'rb') as pdf: #, open(document_2_path, 'rb') as pdf_2:
    envelope = pydocusign.Envelope(
        documents=[
            pydocusign.Document(
                name='HelloWorldTest.pdf',
                documentId=1,
                data=pdf,
            )
        ],
        emailSubject='What does this do - 1',  # Title in docusign demo/sent view
        emailBlurb='What does this do - 2',
        eventNotification=event_notification,
        status=pydocusign.Envelope.STATUS_SENT,
        recipients=signers,
    )
    client.create_envelope_from_documents(envelope)
print("   Received envelopeId {id}".format(id=envelope.envelopeId))


# Update recipient list of envelope: fetch envelope's ``UserId`` from DocuSign.
print("3. GET {account}/envelopes/{envelopeId}/recipients")
envelope.get_recipients()
print("   Received UserId for recipient 0: {0}".format(
    envelope.recipients[0].userId))
示例#10
0

# Create envelope with embedded signing.
print("2. POST {account}/envelopes")
event_notification = pydocusign.EventNotification(
    url=callback_url,
)
input_document_path = os.path.join(fixtures_dir(), 'test.pdf')
with open(input_document_path, 'rb') as pdf_file:
    envelope = pydocusign.Envelope(
        documents=[
            pydocusign.Document(
                name='document.pdf',
                documentId=1,
                data=pdf_file,
            ),
        ],
        emailSubject='This is the subject',
        emailBlurb='This is the body',
        eventNotification=event_notification,
        status=pydocusign.Envelope.STATUS_SENT,
        recipients=signers,
    )
    client.create_envelope_from_document(envelope)
print("   Received envelopeId {id}".format(id=envelope.envelopeId))


# Update recipient list of envelope: fetch envelope's ``UserId`` from DocuSign.
print("3. GET {account}/envelopes/{envelopeId}/recipients")
envelope.get_recipients()
print("   Received UserId for recipient 0: {0}".format(
    envelope.recipients[0].userId))