Skip to content

Commit

Permalink
DEVDOCS-13760 codeDepot markers
Browse files Browse the repository at this point in the history
  • Loading branch information
karissarjacobsen committed Feb 13, 2024
1 parent 7a989bb commit 0936c5e
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions app/services/e_sign/eg042_document_generation_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,52 @@ def worker
account_id = args[:account_id]
envelope_args = args[:envelope_args]

# Step 1. Create the template
#ds-snippet-start:eSign42Step2
template = template_api.create_template(account_id, template_data)
template_id = template.template_id
#ds-snippet-end:eSign42Step2

# Step 2. Update template document
#ds-snippet-start:eSign42Step3
document_id = '1'
template_api.update_document(account_id, document_id, template_id, template_document(envelope_args))
#ds-snippet-end:eSign42Step3

# Step 3. Update recipient tabs
#ds-snippet-start:eSign42Step4
recipient_id = '1'
template_api.create_tabs(account_id, recipient_id, template_id, recipient_tabs)
#ds-snippet-end:eSign42Step4

# Step 4. Create draft envelope
#ds-snippet-start:eSign42Step5
envelope_definition = make_envelope(template_id, envelope_args)
envelope = envelope_api.create_envelope(account_id, envelope_definition)
envelope_id = envelope.envelope_id
#ds-snippet-end:eSign42Step5

# Step 5: Get the document id
#ds-snippet-start:eSign42Step6
doc_gen_form_fields_response = envelope_api.get_envelope_doc_gen_form_fields(account_id, envelope_id)
document_id_guid = doc_gen_form_fields_response.doc_gen_form_fields[0].document_id
#ds-snippet-end:eSign42Step6

# Step 6: Merge the data fields
#ds-snippet-start:eSign42Step7
form_fields_request = form_fields(envelope_args, document_id_guid)
envelope_api.update_envelope_doc_gen_form_fields(
account_id,
envelope_id,
form_fields_request
)
#ds-snippet-end:eSign42Step7

# Step 7. Send the envelope
#ds-snippet-start:eSign42Step8
send_envelope_req = DocuSign_eSign::Envelope.new(status: 'sent')
envelope = envelope_api.update(account_id, envelope_id, send_envelope_req)
#ds-snippet-end:eSign42Step8

{ 'envelope_id' => envelope.envelope_id }
end

private

#ds-snippet-start:eSign42Step2
def template_data
# Create recipients
signer = DocuSign_eSign::Signer.new(
Expand All @@ -74,7 +83,9 @@ def template_data
status: 'created'
)
end
#ds-snippet-end:eSign42Step2

#ds-snippet-start:eSign42Step3
def template_document(args)
# Create the document model
document = DocuSign_eSign::Document.new(
Expand All @@ -90,7 +101,9 @@ def template_document(args)
documents: [document]
)
end
#ds-snippet-end:eSign42Step3

#ds-snippet-start:eSign42Step4
def recipient_tabs
# Create tabs
sign_here = DocuSign_eSign::SignHere.new(
Expand All @@ -109,7 +122,9 @@ def recipient_tabs
dateSignedTabs: [date_signed]
)
end
#ds-snippet-end:eSign42Step4

#ds-snippet-start:eSign42Step5
def make_envelope(template_id, args)
# Create the signer model
signer = DocuSign_eSign::TemplateRole.new(
Expand All @@ -125,7 +140,9 @@ def make_envelope(template_id, args)
templateId: template_id
)
end
#ds-snippet-end:eSign42Step5

#ds-snippet-start:eSign42Step7
def form_fields(args, document_id_guid)
candidate_name_field = DocuSign_eSign::DocGenFormField.new(
name: 'Candidate_Name',
Expand Down Expand Up @@ -160,4 +177,5 @@ def form_fields(args, document_id_guid)
docGenFormFields: [doc_gen_form_fields]
)
end
#ds-snippet-end:eSign42Step7
end

0 comments on commit 0936c5e

Please sign in to comment.