【问题标题】:Docusign: How do I redirect a user after remote signing (email) to my site using PHP?Docusign:如何在使用 PHP 远程签名(电子邮件)后将用户重定向到我的站点?
【发布时间】:2019-01-02 18:01:45
【问题描述】:

我正在使用 Laravel 5.4 和 docusign/esign-client 3 包。在我的网站上,我将用户重定向到 Docusign 中的文档,然后在他们签署后将他们重定向回我的网站以下载和更新我的数据库。同时我给他们发了一封电子邮件。我的问题是,如果他们点击电子邮件而不是直接从我的网站登陆文档,我该如何将他们重定向回我的网站?

我尝试使用TemplateRole.setEmbeddedRecipientStartUrl 方法,它会在将它们发送到文档之前重定向我,但我没有得到任何关于信封的信息。理想情况下,我希望将它们直接发送到docusign,然后在单击电子邮件后签名后将它们重定向回我的站点。我该怎么做呢?或者让这个工作的正确代码是什么?

      <?php
 //fill in document fields
        $text_tabs = [];
        foreach($custom_fields as $custom_field_name=>$custom_field_value){
            $text_tabs[] = (new \DocuSign\eSign\Model\Text())
                            ->setTabLabel($custom_field_name)
                            ->setValue($custom_field_value);
        }

        $tabs = (new \DocuSign\eSign\Model\Tabs())
                ->setTextTabs($text_tabs);
        //end fill in document fields


        // assign recipient to template role by setting name, email, and role name.  Note that the
        // template role name must match the placeholder role name saved in your account template.
        $templateRole = (new \DocuSign\eSign\Model\TemplateRole())
                        ->setEmail($email)
                        ->setName($name)
                        //->setEmbeddedRecipientStartUrl(route("test1"))
                        ->setEmbeddedRecipientStartUrl("SIGN_AT_DOCUSIGN")//sends user directly to docusign
                        ->setClientUserId($rand_user_id)
                        ->setTabs($tabs)
                        ->setRoleName("Applicant");


        //webhook config
        $envelope_events = [
            (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("sent"),
            (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("delivered"),
            (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("completed"),
            (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("declined"),
            (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("voided"),
            (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("sent"),
            (new \DocuSign\eSign\Model\EnvelopeEvent())->setEnvelopeEventStatusCode("sent")
        ];

        $recipient_events = [
            (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("Sent"),
            (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("Delivered"),
            (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("Completed"),
            (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("Declined"),
            (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("AuthenticationFailed"),
            (new \DocuSign\eSign\Model\RecipientEvent())->setRecipientEventStatusCode("AutoResponded")
        ];

        /*NOTE *****
        //make sure to add route url to $except in Http\Middleware\VerifyCsrfToken*/
        $event_notification = (new \DocuSign\eSign\Model\EventNotification())
                                ->setUrl(route("webhook"))//url webhook goes to
                                ->setLoggingEnabled("true")
                                ->setRequireAcknowledgment("true")
                                ->setUseSoapInterface("false")
                                ->setIncludeCertificateWithSoap("false")
                                ->setSignMessageWithX509Cert("false")
                                ->setIncludeDocuments("true")
                                ->setIncludeEnvelopeVoidReason("true")
                                ->setIncludeTimeZone("true")
                                ->setIncludeSenderAccountAsCustomField("true")
                                ->setIncludeDocumentFields("true")
                                ->setIncludeCertificateOfCompletion("true")
                                ->setEnvelopeEvents($envelope_events)
                                ->setRecipientEvents($recipient_events);
        //end webhook config







        // instantiate a new envelope object and configure settings
        $envelop_definition = (new \DocuSign\eSign\Model\EnvelopeDefinition())
                                ->setEmailSubject("Docusign Test")
                                ->setTemplateId($template_id)
                                ->setTemplateRoles(array($templateRole))
                                //->setRecipients($recipients)
                                ->setEventNotification($event_notification)
                                ->setStatus("sent");// set envelope status to "sent" to immediately send the signature request


        // optional envelope parameters
        $options = (new \DocuSign\eSign\Api\EnvelopesApi\CreateEnvelopeOptions())
                    ->setCdseMode(null)
                    ->setMergeRolesOnDraft(null);

        // create and send the envelope (aka signature request)
        $envelopeApi = new \DocuSign\eSign\Api\EnvelopesApi($this->api_client);

        $envelop_summary = $envelopeApi->createEnvelope($this->account_id, $envelop_definition, $options);
        if(!empty($envelop_summary)){

            $envelop_summary = json_decode($envelop_summary,true);


            $recipient_view_request = ( new \DocuSign\eSign\Model\RecipientViewRequest() )
                                        ->setReturnUrl( route("return_url_for_document") )
                                        ->setClientUserId($rand_user_id)
                                        ->setAuthenticationMethod("email")
                                        ->setUserName($name)
                                        ->setEmail($email);

            try{
                $signing_view = $envelopeApi->createRecipientView($this->account_id, $envelop_summary["envelopeId"], $recipient_view_request);

                $signing_url                    = $signing_view->getUrl();
                $envelop_summary["signing_url"] = $signing_url;

                return $envelop_summary;

            } catch (\DocuSign\eSign\ApiException $e){
                echo  "Error connecting Docusign : " . $e->getResponseBody()->errorCode . " " . $e->getResponseBody()->message;
            }
        }

【问题讨论】:

    标签: laravel laravel-5 laravel-5.4 docusignapi


    【解决方案1】:

    我的问题是,如果他们点击电子邮件而不是直接从我的网站登陆文档,我该如何将他们重定向回我的网站?

    使用embeddedRecipientStartURL。要使您的应用程序能够理解上下文,请使用 documentation 中所述的合并字段功能:

    可以使用合并字段将信息附加到嵌入的收件人起始 URL。可用的合并字段项有:信封Id、recipientId、recipientName、receiverEmail 和customFields。

    例如,使用embeddedRecipientStartURLvalue of https:myapp.mydomain.com/?envelopeId=[[envelopeId]]&amp;recipientId=[[recipientId]]&amp;recipientName=[[recipientName]]&amp; recipientEmail=[[recipientEmail]]

    【讨论】:

    • 如何让信封 id 附加到 embeddedRecipientStartURL ?这是第 22 个问题。我需要创建信封以获取信封 ID。
    • [[envelopeId]] 将被替换为信封 ID。抱歉,这不清楚。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    • 2019-04-21
    相关资源
    最近更新 更多