是否可以在使用PHP发送DocuSign信封时使用静态模板ID?

huangapple go评论83阅读模式
英文:

Is it possible to use a static template ID to send envelopes in DocuSign using PHP?

问题

您想要避免每次都创建模板。

英文:

My requirement is once admin set template and their variable to send that template to recipient to sign the envelop. Currently I have follow to create template each time using https://developers.docusign.com/docs/esign-rest-api/how-to/create-template/

Conclusion : How can I avoid to create template and send envelop using my static template id

public function sendEngagementLetter(Request $request)
{
// dd($request->all());
$businessCityStateZip = $request->businessCity . ' ' . $request->State . ' ' . $request->Zip;
$token = TokenModel::first();
$config = new Configuration();
$config->setHost(env('DOCUSIGN_BASE_URL'));
$config->addDefaultHeader('Authorization', 'Bearer ' . $token['access_token']);
//dd($config);
$apiClient = new ApiClient($config);
$templateApi = new TemplatesApi($apiClient);
$envelopeApi = new EnvelopesApi($apiClient);
$filepath = chunk_split(base64_encode(file_get_contents(public_path('uploads/Engagement letter.pdf'))));
$doc_file = 'Engagement letter.pdf';
$content_bytes = file_get_contents(public_path('uploads/Engagement letter.pdf'));
$base64_file_content = base64_encode($content_bytes);
# Create the document model
$document = new Document([  # create the DocuSign document object
'document_base64' => $base64_file_content,
'name' => 'Engagement letter',  # can be different from actual file name
'file_extension' => 'pdf',  # many different document types are accepted
'document_id' => '1'  # a label used to reference the doc
]);
# Create the signer recipient model
# Since these are role definitions, no name/email:
$signer = new Signer([
'role_name' => 'signer',
'recipient_id' => $request->recipient_email,
'routing_order' => "1"
]);
# create a cc recipient to receive a copy of the documents
/*$cc = new CarbonCopy([
'role_name' => 'cc',
'recipient_id' =>  $request->cc_email,
'routing_order' => "2"
]);*/
# Create fields using absolute positioning
# Create a sign_here tab (field on the document)
$sign_here = new SignHere([
'document_id' => '1',
'page_number' => '3',
'x_position' => '163',
'y_position' => '272'
]);
$date1 = new Text([
'document_id' => "1",
'page_number' => "1",
'x_position' => "263",
'y_position' => "154",
'font' => "helvetica",
'font_size' => "size7",
'tab_label' => "text",
'value' => $request->send_date,
'height' => "20",
'width' => "150",
'locked' => 'true',
'required' => "false"
]);
$text1 = new Text([
'document_id' => "1",
'page_number' => "1",
'x_position' => "71",
'y_position' => "194",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "authorizedSignerName",
'value' => $request->authorizedSignerName,
'height' => "10",
'width' => "150",
'locked' => 'true',
'required' => "false"
]);
$text2 = new Text([
'document_id' => "1",
'page_number' => "1",
'x_position' => "71",
'y_position' => "206",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "businessName",
'value' => $request->businessName,
'height' => "00",
'width' => "150",
'locked' => 'true',
'required' => "false"
]);
$text3 = new Text([
'document_id' => "1",
'page_number' => "1",
'x_position' => "71",
'y_position' => "219",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "text",
'value' => $request->businessAddress,
'height' => "10",
'width' => "150",
'locked' => 'true',
'required' => "false"
]);
$text4 = new Text([
'document_id' => "1",
'page_number' => "1",
'x_position' => "71",
'y_position' => "231",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "text",
'value' => $businessCityStateZip,
'height' => "10",
'width' => "150",
'locked' => 'true',
'required' => "false"
]);
$text5 = new Text([
'document_id' => "1",
'page_number' => "1",
'x_position' => "99",
'y_position' => "281",
'font' => "helvetica",
'font_size' => "size10",
'tab_label' => "text",
'value' => $request->authorizedSignerName . ',',
'height' => "10",
'width' => "150",
'locked' => 'true',
'required' => "false"
]);
$text6 = new Text([
'document_id' => "1",
'page_number' => "1",
'x_position' => "215",
'y_position' => "321",
'font' => "helvetica",
'font_size' => "size10",
'tab_label' => "text",
'value' => $request->businessName,
'height' => "20",
'width' => "200",
'locked' => 'true',
'required' => "false"
]);
$signDate = new DateSigned([
'document_id' => "1",
'page_number' => "3",
'x_position' => "338",
'y_position' => "288",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "Date Signed 9ac30e67-7a0d-4028-9251-f80a0d947dde",
'height' => "10",
'width' => "150",
'required' => "true"
]);
$signDate2 = new DateSigned([
'document_id' => "1",
'page_number' => "3",
'x_position' => "338",
'y_position' => "387",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "Date Signed 9ac30e67-7a0d-4028-9251-f80a0d947dde",
'height' => "10",
'width' => "150",
'required' => "true"
]);
$date2 = new Text([
'document_id' => "1",
'page_number' => "2",
'x_position' => "70",
'y_position' => "35",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "date2",
'value' => $request->send_date,
'height' => "10",
'width' => "150",
'locked' => 'true',
'required' => "false"
]);
$date3 = new Text([
'document_id' => "1",
'page_number' => "3",
'x_position' => "70",
'y_position' => "35",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "date3",
'value' => $request->send_date,
'height' => "10",
'width' => "150",
'locked' => 'true',
'required' => "false"
]);
$Page2 = new Text([
'document_id' => "1",
'page_number' => "2",
'x_position' => "70",
'y_position' => "47",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "Page2",
'value' => 'Page 2 of 3 ',
'height' => "10",
'width' => "160",
'locked' => 'true',
'required' => "false"
]);
$Page3 = new Text([
'document_id' => "1",
'page_number' => "3",
'x_position' => "70",
'y_position' => "50",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "Page3",
'value' => 'Page 3 of 3 ',
'height' => "20",
'width' => "160",
'locked' => 'true',
'required' => "false"
]);
$businessName2 = new Text([
'document_id' => "1",
'page_number' => "2",
'x_position' => "70",
'y_position' => "15",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "businessName2",
'value' => $request->businessName,
'height' => "20",
'width' => "160",
'locked' => 'true',
'required' => "false"
]);
$businessName3 = new Text([
'document_id' => "1",
'page_number' => "3",
'x_position' => "70",
'y_position' => "14",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "businessName3",
'value' => $request->businessName,
'height' => "20",
'width' => "160",
'locked' => 'true',
'required' => "false"
]);
$businessTitle = new Text([
'document_id' => "1",
'page_number' => "3",
'x_position' => "160",
'y_position' => "309",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "businessTitle",
'value' => $request->authorizedSignerName . ',' . $request->business_title,
'height' => "20",
'width' => "160",
'locked' => 'true',
'required' => "false"
]);
$businessTitleSub = new Text([
'document_id' => "1",
'page_number' => "3",
'x_position' => "160",
'y_position' => "321",
'font' => "helvetica",
'font_size' => "size9",
'tab_label' => "businessTitleSub",
'value' => $request->businessName . '.',
'height' => "20",
'width' => "160",
'locked' => 'true',
'required' => "false"
]);
# Add the tabs model to the signer
# The Tabs object wants arrays of the different field/tab types
$signer->setTabs(new Tabs([
'sign_here_tabs' => [
$sign_here
],
'date_signed_tabs' => [
$signDate, $signDate2
],
'text_tabs' => [
$date1,
$date2,
$date3,
$businessName2,
$businessName3,
$Page2,
$Page3,
$text1,
$text2,
$text3,
$text4,
$text5,
$text6,
$businessTitle,
$businessTitleSub
]
]));
# Template object:
$template_request = new EnvelopeTemplate([
'description' => "Hi Kindly sign the Engagement Letter Regards, ",
'name' => 'Engagement Letter',
'shared' => "false",
'documents' => [$document],
'email_blurb' => "Greetings " . $request->recipient_name . ",<br/><br/><br/>Hi Kindly sign the Engagement Letter for your  opinion <br/><br/>Regards,<br/> Hi",
'email_subject' => $request->recipient_name . " - Option",
'recipients' => new Recipients([
'signers' => [$signer]
/*'carbon_copies' => [$cc]*/
]),
'status' => "created"
]);
$template = $templateApi->createTemplate(env('DOCUSIGN_ACCOUNT_ID'), $template_request);
$template_id = $template->getTemplateId();
//dd($template_id);
/**
* 
*/
$token = TokenModel::first();
// dd($request->all());
# Create the envelope definition with the template_id
$envelope_definition = new EnvelopeDefinition([
'status' => 'sent',
"emailBlurb" => "Hi Kindly sign the Engagement Letter for your opinion Regards, ",
'template_id' => $template_id
]);
# Create the template role elements to connect the signer and cc recipients
# to the template
$signer = new TemplateRole([
'email' => $request->recipient_email,
'name' => $request->recipient_name,
'role_name' => 'signer'
]);
# Create a cc template role.
$cc = new TemplateRole([
'email' => $request->cc_email,
'name' => $request->cc_name,
'role_name' => 'Developer'
]);
# Add the TemplateRole objects to the envelope object
$envelope_definition->setTemplateRoles([$signer]);
//dd($envData);
$config = new Configuration();
$config->setHost(env('DOCUSIGN_BASE_URL'));
$config->addDefaultHeader('Authorization', 'Bearer ' . $token['access_token']);
$api_client = new ApiClient($config);
$envelope_api = new EnvelopesApi($api_client);
$results = $envelope_api->createEnvelope(env('DOCUSIGN_ACCOUNT_ID'), $envelope_definition);
$envelope_id = $results->getEnvelopeId();
/**
* for delete templete from dashboard start
*/
$result = (new DeleteTempleteController)->deleteTemplete($template_id);
/**
* for delete templete from dashboard start
* */
$success_msg = 'Envelopes created successfully';
$result = array(
"response" => array(
'code' => '201',
'message' => $success_msg,
'envelope_id' => $envelope_id
)
);
return json_encode($result);
}

I want to avoid create template each time

答案1

得分: 1

这段代码是关于使用DocuSign eSignature REST API创建并发送签名请求的PHP示例代码。它包括创建信封定义以及连接签署者和抄送接收者到模板的模板角色元素的部分。

如果您有任何关于此代码的具体问题或需要进一步的帮助,请随时提出。

英文:

https://developers.docusign.com/docs/esign-rest-api/how-to/request-signature-template-remote/ shows what you are asking and here is the PHP code which can also be found here - https://github.com/docusign/code-examples-php/blob/master/src/Services/Examples/eSignature/UseTemplateService.php

private function make_envelope($args)
{
# Create the envelope definition with the template_id
$envelope_definition = new \DocuSign\eSign\Model\EnvelopeDefinition([
'status' => 'sent', 'template_id' => $args['template_id']
]);
# Create the template role elements to connect the signer and cc recipients
# to the template
$signer = new \DocuSign\eSign\Model\TemplateRole([
'email' => $args['signer_email'], 'name' => $args['signer_name'],
'role_name' => 'signer'
]);
# Create a cc template role.
$cc = new \DocuSign\eSign\Model\TemplateRole([
'email' => $args['cc_email'], 'name' => $args['cc_name'],
'role_name' => 'cc'
]);
# Add the TemplateRole objects to the envelope object
$envelope_definition->setTemplateRoles([$signer, $cc]);
return $envelope_definition;
}

huangapple
  • 本文由 发表于 2023年5月24日 20:01:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76323305.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定