我目前正在开发一个使用代码授权身份验证与 Docusign 集成的 Ruby on Rails 应用程序。我的目标是发送 Docusign 信封而不附加 Rails 应用程序中的任何文档。相反,我的目标是利用 Docusign 上已包含文档的现有模板。此外,我想预填充这些模板的值并将其发送给用户进行签名。最后,一旦用户签署了文档,我需要以 PDF 形式将签名的文档检索回我的 Rails 应用程序。
以下是我迄今为止所取得的成就以及面临的挑战的详细说明:
目前进展:
使用代码授权身份验证成功将 Docusign 与我的 Rails 应用程序集成。
能够创建信封并使用现有模板发送。
接收未签名的 PDF 回复。
遇到的挑战:
无法发送未附加文件的信封。如果我尝试发送没有文档的信封,我会收到“文档丢失”错误,从而导致请求失败。
不确定如何在现有模板中预填充值,然后再将其发送给用户进行签名。
需要有关如何以 PDF 形式将签名文档检索回我的 Rails 应用程序的指导。
这是我当前的代码
def send_data_using_template(access_token)
template_id = "8f33b649-****-4aa2-804a-01f2*****5e3"
recipient_name = "ali676750"
recipient_email = "[email protected]"
document_file_path = "config/Software licensing agreement.pdf"
fields_to_prefill = {
"name" => "ahmad",
"title" => "software engineer"
}
signer1 = DocuSign_eSign::Signer.new(
email: recipient_email,
name: recipient_name,
recipientId: '11',
routing_order: '11'
)
document_base64 = Base64.strict_encode64(File.read(document_file_path))
document = {
documentBase64: document_base64,
name: File.basename(document_file_path),
fileExtension: File.extname(document_file_path).delete('.'),
documentId: '1'
}
tabs = DocuSign_eSign::Tabs.new
recipients = DocuSign_eSign::Recipients.new(
signers: [signer1],
)
envelope_definition = DocuSign_eSign::EnvelopeDefinition.new(
emailSubject: "Your subject line here",
status: "sent",
template_id: template_id,
documents: [document],
tabs: tabs
)
envelope_definition.recipients = recipients
response = HTTParty.post("https://demo.docusign.net/restapi/v2.1/accounts/#{ENV['DOCUSIGN_ACCOUNT_ID']}/envelopes",
headers: { "Authorization" => "Bearer #{access_token}", "Content-Type" => "application/json" },
body: envelope_definition.to_json)
if response.code == 201
puts "Envelope created successfully "
envelope_id = response.parsed_response["envelopeId"]
response = HTTParty.get(
"https://demo.docusign.net/restapi/v2.1/accounts/#{ENV['DOCUSIGN_ACCOUNT_ID']}/envelopes/#{envelope_id}/documents/combined",
headers: { "Authorization" => "Bearer #{access_token}" }
)
decoded_content = Base64.decode64(response.body)
file_path = "config/signed_document.pdf"
File.open(file_path, "wb") { |file| file.write(decoded_content) }
puts "PDF file saved successfully at #{file_path}"
else
puts "Error creating envelope: #{response.body}"
end
end
这是我寻求帮助的内容:
发送信封而不附加文档:有没有办法使用已包含文档的现有模板发送信封,而无需从我的 Rails 应用程序附加其他文档?
在模板中预填充值:如何在发送现有模板以供签名之前预填充现有模板中的值?
检索签名文档:在用户签名后,将签名文档以 PDF 形式检索回我的 Rails 应用程序的过程是什么?
我将非常感谢任何可以帮助我克服这些挑战的见解、建议或代码片段。预先感谢您的协助!
1+2 的完成方式与您编写的代码类似。您可以找到完全可以使用的代码示例 - https://github.com/docusign/code-examples-ruby/blob/master/app/services/e_sign/eg017_set_template_tab_values_service.rb,它展示了如何使用模板而不是添加文档并设置选项卡值。
一些注意事项:
template_id
中放置正确的 envelope_definition
,则无需添加文档,它们将来自模板。