Ejemplo n.º 1
0
    def get(self, request, *args, **kwargs):
        api_client = get_api_client()
        bulk_envelopes_api = BulkEnvelopesApi(api_client)
        recipient_1 = BulkSendingCopyRecipient(role_name='signer', name='Aaqib 1', email='*****@*****.**')
        recipient_2 = BulkSendingCopyRecipient(role_name='signer', name='Aaqib 2', email='*****@*****.**')
        bulk_copies = [
            BulkSendingCopy(recipients=[recipient_1], custom_fields=[]),
            BulkSendingCopy(recipients=[recipient_2], custom_fields=[]),
        ]
        bulk_sending_list = BulkSendingList(name='employee_contract', bulk_copies=bulk_copies)
        bulk_list = bulk_envelopes_api.create_bulk_send_list(ACCOUNT_ID, bulk_sending_list=bulk_sending_list)
        bulk_list_id = bulk_list.list_id

        envelopes_api = EnvelopesApi(api_client)
        with open(f'{BASE_DIR}/document.pdf', 'rb') as pdf_file:
            content_bytes = pdf_file.read()
        base64_file_content = base64.b64encode(content_bytes).decode('ascii')
        document = Document(document_base64=base64_file_content, name='Employee Contract',
                            file_extension='pdf', document_id='1')
        envelope_definition = EnvelopeDefinition(email_subject='Please sign this document set', documents=[document],
                                                 recipients={}, status='created', envelope_id_stamping='true')
        envelope = envelopes_api.create_envelope(account_id=ACCOUNT_ID, envelope_definition=envelope_definition)
        envelope_id = envelope.envelope_id

        text_custom_fields = TextCustomField(name='mailingListId', required='false', show='false', value=bulk_list_id)
        custom_fields = CustomFields(list_custom_fields=[], text_custom_fields=[text_custom_fields])
        envelopes_api.create_custom_fields(account_id=ACCOUNT_ID, envelope_id=envelope_id, custom_fields=custom_fields)

        signer = Signer(name='Multi Bulk Recipient::signer', email='*****@*****.**',
                        role_name='signer', note='', routing_order='1', status='created', delivery_method='email',
                        recipient_id='13', recipient_type='signer')
        envelopes_api.create_recipient(ACCOUNT_ID, envelope_id, recipients=Recipients(signers=[signer]))
        bulk_send_request = BulkSendRequest(envelope_or_template_id=envelope_id)
        batch = bulk_envelopes_api.create_bulk_send_request(ACCOUNT_ID, bulk_list_id,
                                                            bulk_send_request=bulk_send_request)

        time.sleep(10)
        from_date = (datetime.utcnow() - timedelta(seconds=60)).isoformat()
        envelopes = envelopes_api.list_status_changes(ACCOUNT_ID, status='sent', from_date=from_date).envelopes
        for envelope in envelopes:
            env, created = SigEnvelope.objects.get_or_create(envelope_id=envelope.envelope_id)
            if created:
                sign_request = SignRequest.objects.create(envelope=env, status_date_time=envelope.status_date_time)
                recipients = envelopes_api.list_recipients(ACCOUNT_ID, envelope.envelope_id)
                Recipient.objects.create(sign_request=sign_request, email=recipients.signers[0].email,
                                         recipient_id=recipients.signers[0].recipient_id)
        return redirect('esign:envelope_list')
Ejemplo n.º 2
0
    def worker(cls, args):
        """
        1. Create an api client and construct API clients
        2. Create and submit a bulk sending list
        3. Create a draft envelope
        4. Add custom fields to the envelope
        5. Add recipients to the envelope
        6. Initiate bulk envelope sending
        7. Confirm sending success
        """

        # Step 2. Construct your API headers
        api_client = create_api_client(base_path=args["base_path"],
                                       access_token=args["access_token"])

        # Step 3. Submit a bulk list
        bulk_envelopes_api = BulkEnvelopesApi(api_client)
        bulk_sending_list = cls.create_bulk_sending_list(args["signers"])
        bulk_list = bulk_envelopes_api.create_bulk_send_list(
            account_id=args["account_id"], bulk_sending_list=bulk_sending_list)
        bulk_list_id = bulk_list.list_id

        # Step 4. Create an envelope
        envelope_api = EnvelopesApi(api_client)
        envelope_definition = cls.make_draft_envelope()
        envelope = envelope_api.create_envelope(
            account_id=args["account_id"],
            envelope_definition=envelope_definition)
        envelope_id = envelope.envelope_id

        # Step 5. Attach your bulk list id to the envelope
        text_custom_fields = TextCustomField(name="mailingListId",
                                             required="false",
                                             show="false",
                                             value=bulk_list_id)
        custom_fields = CustomFields(list_custom_fields=[],
                                     text_custom_fields=[text_custom_fields])
        envelope_api.create_custom_fields(account_id=args["account_id"],
                                          envelope_id=envelope_id,
                                          custom_fields=custom_fields)

        # Step 6. Add placeholder recipients
        cc = Signer(name="Multi Bulk Recipient::cc",
                    email="*****@*****.**",
                    role_name="cc",
                    note="",
                    routing_order="1",
                    status="created",
                    delivery_method="email",
                    recipient_id="12",
                    recipient_type="signer")

        signer = Signer(name="Multi Bulk Recipient::signer",
                        email="*****@*****.**",
                        role_name="signer",
                        note="",
                        routing_order="1",
                        status="created",
                        delivery_method="email",
                        recipient_id="13",
                        recipient_type="signer")

        envelope_api.create_recipient(
            account_id=args["account_id"],
            envelope_id=envelope_id,
            recipients=Recipients(signers=[signer, cc]))

        # Step 7. Initiate bulk send
        bulk_send_request = BulkSendRequest(
            envelope_or_template_id=envelope_id)
        batch = bulk_envelopes_api.create_bulk_send_request(
            account_id=args["account_id"],
            bulk_send_list_id=bulk_list_id,
            bulk_send_request=bulk_send_request)
        batch_id = batch.batch_id

        # Step 8. Confirm successful batch send
        response = bulk_envelopes_api.get(account_id=args["account_id"],
                                          batch_id=batch_id)

        return response