Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions app/controllers/e_sign/eeg046_multiple_delivery_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

class ESign::Eeg046MultipleDeliveryController < EgController
before_action -> { check_auth('eSignature') }
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 46, 'eSignature') }

def create
envelope_args = {
delivery_method: param_gsub(params['delivery_method']),
signer_name: param_gsub(params['signer_name']),
signer_email: param_gsub(params['signer_email']),
cc_name: param_gsub(params['cc_name']),
cc_email: param_gsub(params['cc_email']),
cc_phone_number: param_gsub(params['cc_phone_number']),
cc_country_code: param_gsub(params['cc_country_code']),
phone_number: param_gsub(params['phone_number']),
country_code: param_gsub(params['country_code']),
status: 'sent'
}
args = {
account_id: session['ds_account_id'],
base_path: session['ds_base_path'],
access_token: session['ds_access_token'],
envelope_args: envelope_args
}

results = ESign::Eg046MultipleDeliveryService.new(args).worker
session[:envelope_id] = results['envelope_id']
@title = @example['ExampleName']
@message = format_string(@example['ResultsPageText'], results['envelope_id'])
render 'ds_common/example_done'
rescue DocuSign_eSign::ApiError => e
error = JSON.parse e.response_body
error_message = error['error_description'] || error['message'] || error['error']

if error_message.include?('ACCOUNT_LACKS_PERMISSIONS')
@error_code = 'ACCOUNT_LACKS_PERMISSIONS'
@error_message = @example['CustomErrorTexts'][0]['ErrorMessage']
return render 'ds_common/error'
end

handle_error(e)
end

def get
enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
if enableCFR == 'enabled'
session[:status_cfr] = 'enabled'
@title = 'Not CFR Part 11 compatible'
@error_information = @manifest['SupportingTexts']['CFRError']
render 'ds_common/error'
end
super
end
end
192 changes: 192 additions & 0 deletions app/services/e_sign/eg046_multiple_delivery_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
# frozen_string_literal: true

class ESign::Eg046MultipleDeliveryService
attr_reader :args

include ApiCreator

def initialize(args)
@args = args
end

def worker
# Create the envelope request object
envelope_definition = make_envelope(args[:envelope_args])

# Create and send the envelope
# Call Envelopes::create API method
# Exceptions will be caught by the calling function
envelope_api = create_envelope_api(args)
#ds-snippet-start:eSign46Step3
results, _status, headers = envelope_api.create_envelope_with_http_info args[:account_id], envelope_definition

remaining = headers['X-RateLimit-Remaining']
reset = headers['X-RateLimit-Reset']

if remaining && reset
reset_date = Time.at(reset.to_i).utc
puts "API calls remaining: #{remaining}"
puts "Next Reset: #{reset_date}"
end
envelope_id = results.envelope_id
#ds-snippet-end:eSign46Step3
{ 'envelope_id' => envelope_id }
end

private

#ds-snippet-start:eSign46Step2
def make_envelope(envelope_args)
# document 1 (HTML) has tag **signature_1**
# document 2 (DOCX) has tag /sn1/
# document 3 (PDF) has tag /sn1/
#
# The envelope has two recipients:
# recipient 1 - signer
# recipient 2 - cc
# The envelope will be sent first to the signer via SMS
# After it is signed, a copy is sent to the cc person via SMS

# Create the envelope definition
envelope_definition = DocuSign_eSign::EnvelopeDefinition.new

envelope_definition.email_subject = 'Please sign this document set'

# Add the documents
doc1_b64 = Base64.encode64(create_document1(envelope_args))
# Read files 2 and 3 from a local directory
# The reads could raise an exception if the file is not available!
doc_docx = Rails.application.config.doc_docx
doc2_b64 = Base64.encode64(File.binread(File.join('data', doc_docx)))
doc_pdf = Rails.application.config.doc_pdf
doc3_b64 = Base64.encode64(File.binread(File.join('data', doc_pdf)))

# Create the document models
document1 = DocuSign_eSign::Document.new(
# Create the Docusign document object
documentBase64: doc1_b64,
name: 'Order acknowledgement', # Can be different from actual file name
fileExtension: 'html', # Many different document types are accepted
documentId: '1' # A label used to reference the doc
)
document2 = DocuSign_eSign::Document.new(
# Create the Docusign document object
documentBase64: doc2_b64,
name: 'Battle Plan', # Can be different from actual file name
fileExtension: 'docx', # Many different document types are accepted
documentId: '2' # A label used to reference the do
)
document3 = DocuSign_eSign::Document.new(
# Create the Docusign document object
documentBase64: doc3_b64,
name: 'Lorem Ipsum', # Can be different from actual file name
fileExtension: 'pdf', # Many different document types are accepted
documentId: '3' # A label used to reference the doc
)

# The order in the docs array determines the order in the envelope
envelope_definition.documents = [document1, document2, document3]

signer_phone_number = DocuSign_eSign::RecipientPhoneNumber.new
signer_phone_number.country_code = envelope_args[:country_code]
signer_phone_number.number = envelope_args[:phone_number]

signer_additional_notification = DocuSign_eSign::RecipientAdditionalNotification.new
signer_additional_notification.phone_number = signer_phone_number
signer_additional_notification.secondary_delivery_method = envelope_args[:delivery_method]

# Create the signer recipient model
signer1 = DocuSign_eSign::Signer.new
signer1.name = envelope_args[:signer_name]
signer1.email = envelope_args[:signer_email]
signer1.recipient_id = '1'
signer1.routing_order = '1'
signer1.delivery_method = 'Email'
signer1.additional_notifications = [signer_additional_notification]

## routingOrder (lower means earlier) determines the order of deliveries
# to the recipients. Parallel routing order is supported by using the
# same integer as the order for two or more recipients

cc_phone_number = DocuSign_eSign::RecipientPhoneNumber.new
cc_phone_number.country_code = envelope_args[:cc_country_code]
cc_phone_number.number = envelope_args[:cc_phone_number]

cc_additional_notification = DocuSign_eSign::RecipientAdditionalNotification.new
cc_additional_notification.phone_number = cc_phone_number
cc_additional_notification.secondary_delivery_method = envelope_args[:delivery_method]

# Create a cc recipient to receive a copy of the documents
cc1 = DocuSign_eSign::CarbonCopy.new
cc1.name = envelope_args[:cc_name]
cc1.email = envelope_args[:cc_email]
cc1.routing_order = '2'
cc1.recipient_id = '2'
cc1.delivery_method = 'Email'
cc1.additional_notifications = [cc_additional_notification]

# Create signHere fields (also known as tabs) on the documents
# We're using anchor (autoPlace) positioning
#
# The Docusign platform searches throughout your envelope's documents for matching
# anchor strings. So the sign_here_2 tab will be used in both document 2 and 3
# since they use the same anchor string for their "signer 1" tabs.
sign_here1 = DocuSign_eSign::SignHere.new(
anchorString: '**signature_1**',
anchorYOffset: '10',
anchorUnits: 'pixels',
anchorXOffset: '20'
)

sign_here2 = DocuSign_eSign::SignHere.new(
anchorString: '/sn1/',
anchorYOffset: '10',
anchorUnits: 'pixels',
anchorXOffset: '20'
)
# Add the tabs model (including the sign_here tabs) to the signer
# The Tabs object takes arrays of the different field/tab types
signer1_tabs = DocuSign_eSign::Tabs.new({
signHereTabs: [sign_here1, sign_here2]
})

signer1.tabs = signer1_tabs

# Add the recipients to the envelope object
recipients = DocuSign_eSign::Recipients.new(
signers: [signer1],
carbonCopies: [cc1]
)
# Request that the envelope be sent by setting status to "sent".
# To request that the envelope be created as a draft, set status to "created"
envelope_definition.recipients = recipients
envelope_definition.status = envelope_args[:status]
envelope_definition
end

def create_document1(args)
"
<!DOCTYPE html>
<html>
<head>
<meta charset=\"UTF-8\">
</head>
<body style=\"font-family:sans-serif;margin-left:2em;\">
<h1 style=\"font-family: 'Trebuchet MS', Helvetica, sans-serif;
color: darkblue;margin-bottom: 0;\">World Wide Corp</h1>
<h2 style=\"font-family: 'Trebuchet MS', Helvetica, sans-serif;
margin-top: 0px;margin-bottom: 3.5em;font-size: 1em;
color: darkblue;\">Order Processing Division</h2>
<h4>Ordered by #{args[:signer_name]}</h4>
<p style=\"margin-top:0em; margin-bottom:0em;\">Phone number: #{args[:phone_number]}</p>
<p style=\"margin-top:0em; margin-bottom:0em;\">Copy to: #{args[:cc_name]}, #{args[:cc_phone_number]}</p>
<p style=\"margin-top:3em;\">
Candy bonbon pastry jujubes lollipop wafer biscuit biscuit. Topping brownie sesame snaps sweet roll pie. Croissant danish biscuit soufflé caramels jujubes jelly. Dragée danish caramels lemon drops dragée. Gummi bears cupcake biscuit tiramisu sugar plum pastry. Dragée gummies applicake pudding liquorice. Donut jujubes oat cake jelly-o. Dessert bear claw chocolate cake gummies lollipop sugar plum ice cream gummies cheesecake.
</p>
<!-- Note the anchor tag for the signature field is in white. -->
<h3 style=\"margin-top:3em;\">Agreed: <span style=\"color:white;\">**signature_1**/</span></h3>
</body>
</html>"
end
#ds-snippet-end:eSign46Step2
end
90 changes: 90 additions & 0 deletions app/views/e_sign/eeg046_multiple_delivery/get.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<%= render('partials/example_info') %>

<% form_index = 0 %>
<% delivery_method_index = 0 %>
<% sms_delivery_method_index = 1 %>
<% whatsapp_delivery_method_index = 2 %>
<% signer_name_index = 3 %>
<% signer_email_index = 4 %>
<% signer_code_index = 5 %>
<% signer_phone_index = 6 %>
<% cc_name_index = 7 %>
<% cc_email_index = 8 %>
<% cc_code_index = 9 %>
<% cc_phone_index = 10 %>

<form class="eg" id="data_form" action="" method="post" data-busy="form">
<% if @example["Forms"][form_index]["FormName"] %>
<%= sanitize @example["Forms"][form_index]["FormName"] %>
<% end %>

<div class="form-group">
<label for="delivery_method"><%= @example["Forms"][form_index]["Inputs"][delivery_method_index]["InputName"] %></label><br>

<label for="sms_delivery"><%= @example["Forms"][form_index]["Inputs"][sms_delivery_method_index]["InputName"] %></label>
<input type="radio" name="delivery_method" value="SMS" checked/>

<label for="whatsapp_delivery"><%= @example["Forms"][form_index]["Inputs"][whatsapp_delivery_method_index]["InputName"] %></label>
<input type="radio" name="delivery_method" value="WhatsApp"/>
</div>

<div class="form-group">
<label for="signer_name"><%= @example["Forms"][form_index]["Inputs"][signer_name_index]["InputName"] %></label>
<input type="text" class="form-control" id="signer_name"
placeholder="<%= @example["Forms"][form_index]["Inputs"][signer_name_index]["InputPlaceholder"] %>" name="signer_name"
value="<%= @config.signer_name %>" required />
</div>
<div class="form-group">
<label for="signer_email"><%= @example["Forms"][form_index]["Inputs"][signer_email_index]["InputName"] %></label>
<input type="email" class="form-control" id="signer_email"
placeholder="<%= @example["Forms"][form_index]["Inputs"][signer_email_index]["InputPlaceholder"] %>" name="signer_email"
value="<%= @config.signer_email %>" required />
<%= render('partials/email_will_not_be_shared') %>
</div>

<div class="form-group">
<label for="country_code"><%= @example["Forms"][form_index]["Inputs"][signer_code_index]["InputName"] %></label>
<input type="tel" class="form-control" id="country_code" name="country_code"
aria-describedby="accessHelp"
placeholder="<%= @example["Forms"][form_index]["Inputs"][signer_code_index]["InputPlaceholder"] %>" required />
<%= render('partials/country_code_text') %>
</div>
<div class="form-group">
<label for="phone_number"><%= @example["Forms"][form_index]["Inputs"][signer_phone_index]["InputName"] %></label>
<input type="tel" class="form-control" id="phone_number" name="phone_number"
aria-describedby="accessHelp"
placeholder="<%= @example["Forms"][form_index]["Inputs"][signer_phone_index]["InputPlaceholder"] %>" required />
<%= render('partials/phone_will_not_be_shared') %>
</div>

<div class="form-group">
<label for="cc_name"><%= @example["Forms"][form_index]["Inputs"][cc_name_index]["InputName"] %></label>
<input type="text" class="form-control" id="cc_name"
placeholder="<%= @example["Forms"][form_index]["Inputs"][cc_name_index]["InputPlaceholder"] %>" name="cc_name"
required />
</div>
<div class="form-group">
<label for="cc_email"><%= @example["Forms"][form_index]["Inputs"][cc_email_index]["InputName"] %></label>
<input type="email" class="form-control" id="cc_email"
placeholder="<%= @example["Forms"][form_index]["Inputs"][signer_email_index]["InputPlaceholder"] %>" name="cc_email"
required />
<%= render('partials/email_will_not_be_shared') %>
</div>

<div class="form-group">
<label for="cc_country_code"><%= @example["Forms"][form_index]["Inputs"][cc_code_index]["InputName"] %></label>
<input type="tel" class="form-control" id="cc_country_code" name="cc_country_code"
aria-describedby="accessHelp"
placeholder="<%= @example["Forms"][form_index]["Inputs"][cc_code_index]["InputPlaceholder"] %>" required />
<%= render('partials/country_code_text') %>
</div>
<div class="form-group">
<label for="cc_phone_number"><%= @example["Forms"][form_index]["Inputs"][cc_phone_index]["InputName"] %></label>
<input type="tel" class="form-control" id="cc_phone_number" name="cc_phone_number"
aria-describedby="accessHelp"
placeholder="<%= @example["Forms"][form_index]["Inputs"][cc_phone_index]["InputPlaceholder"] %>" required />
<%= render('partials/phone_will_not_be_shared') %>
</div>

<%= render('partials/submit_button') %>
</form>
1 change: 1 addition & 0 deletions app/views/partials/_country_code_text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<small id="accessHelp" class="form-text text-muted"><%= @manifest["SupportingTexts"]["HelpingTexts"]["CountryCodeText"] %></small>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@
post 'eeg045' => 'eeg045_delete_restore_envelope#delete_envelope'
get 'eeg045restore' => 'eeg045_delete_restore_envelope#get_restore_envelope'
post 'eeg045restore' => 'eeg045_delete_restore_envelope#restore_envelope'

get 'eeg046' => 'eeg046_multiple_delivery#get'
post 'eeg046' => 'eeg046_multiple_delivery#create'
end

scope module: 'connect' do
Expand Down