如何使用PHP SDK创建包含多个文档的信封?
我是否在我的Envelopes :: create调用中仅使用多个\DocuSign\eSign\Model\Document
对象?
答案 0 :(得分:0)
此示例PHP代码创建了一个包含3个文档的信封。
/**
* Creates envelope definition
* Document 1: An HTML document.
* Document 2: A Word .docx document.
* Document 3: A PDF document.
* DocuSign will convert all of the documents to the PDF format.
* The recipients' field tags are placed using <b>anchor</b> strings.
* @param $args parameters for the envelope:
* signer_email, signer_name, signer_client_id
* @return mixed -- returns an envelope definition
*/
private function make_envelope($args)
{
# document 1 (html) has sign here anchor tag **signature_1**
# document 2 (docx) has sign here anchor tag /sn1/
# document 3 (pdf) has sign here anchor tag /sn1/
#
# The envelope has two recipients.
# recipient 1 - signer
# recipient 2 - cc
# The envelope will be sent first to the signer.
# After it is signed, a copy is sent to the cc person.
#
# create the envelope definition
$envelope_definition = new \DocuSign\eSign\Model\EnvelopeDefinition([
'email_subject' => 'Please sign this document set'
]);
$doc1_b64 = base64_encode($this->create_document1($args));
# read files 2 and 3 from a local directory
# The reads could raise an exception if the file is not available!
$demo_docs_path = __DIR__ . '/../public/demo_documents/';
$content_bytes = file_get_contents($demo_docs_path . $GLOBALS['DS_CONFIG']['doc_docx']);
$doc2_b64 = base64_encode($content_bytes);
$content_bytes = file_get_contents($demo_docs_path . $GLOBALS['DS_CONFIG']['doc_pdf']);
$doc3_b64 = base64_encode($content_bytes);
# Create the document models
$document1 = new \DocuSign\eSign\Model\Document([ # create the DocuSign document object
'document_base64' => $doc1_b64,
'name' => 'Order acknowledgement', # can be different from actual file name
'file_extension' => 'html', # many different document types are accepted
'document_id' => '1' # a label used to reference the doc
]);
$document2 = new \DocuSign\eSign\Model\Document([ # create the DocuSign document object
'document_base64' => $doc2_b64,
'name' => 'Battle Plan', # can be different from actual file name
'file_extension' => 'docx', # many different document types are accepted
'document_id' => '2' # a label used to reference the doc
]);
$document3 = new \DocuSign\eSign\Model\Document([ # create the DocuSign document object
'document_base64' => $doc3_b64,
'name' => 'Lorem Ipsum', # can be different from actual file name
'file_extension' => 'pdf', # many different document types are accepted
'document_id' => '3' # a label used to reference the doc
]);
# The order in the docs array determines the order in the envelope
$envelope_definition->setDocuments([$document1, $document2, $document3]);
# Create the signer recipient model
$signer1 = new \DocuSign\eSign\Model\Signer([
'email' => $args['signer_email'], 'name' => $args['signer_name'],
'recipient_id' => "1", 'routing_order' => "1"]);
# 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.
# create a cc recipient to receive a copy of the documents
$cc1 = new \DocuSign\eSign\Model\CarbonCopy([
'email' => $args['cc_email'], 'name' => $args['cc_name'],
'recipient_id' => "2", 'routing_order' => "2"]);
# 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
# signHere2 tab will be used in both document 2 and 3 since they
# use the same anchor string for their "signer 1" tabs.
$sign_here1 = new \DocuSign\eSign\Model\SignHere([
'anchor_string' => '**signature_1**', 'anchor_units' => 'pixels',
'anchor_y_offset' => '10', 'anchor_x_offset' => '20']);
$sign_here2 = new \DocuSign\eSign\Model\SignHere([
'anchor_string' => '/sn1/', 'anchor_units' => 'pixels',
'anchor_y_offset' => '10', 'anchor_x_offset' => '20']);
# Add the tabs model (including the sign_here tabs) to the signer
# The Tabs object wants arrays of the different field/tab types
$signer1->setTabs(new \DocuSign\eSign\Model\Tabs([
'sign_here_tabs' => [$sign_here1, $sign_here2]]));
# Add the recipients to the envelope object
$recipients = new \DocuSign\eSign\Model\Recipients([
'signers' => [$signer1], 'carbon_copies' => [$cc1]]);
$envelope_definition->setRecipients($recipients);
# Request that the envelope be sent by setting |status| to "sent".
# To request that the envelope be created as a draft, set to "created"
$envelope_definition->setStatus($args["status"]);
return $envelope_definition;
}