为什么DocuSign EventNotification停止工作?

时间:2019-11-06 23:07:12

标签: php docusignapi

2017年,我使用官方的DocuSign PHP客户端(https://github.com/docusign/docusign-php-client)将DocuSign与一个网站集成在一起。

我采用了示例代码并对其进行了修改,以便它注册了一个EventNotification,一旦签署过程完成,该EventNotification就会回呼网站。下面的代码。

        require_once('docusign-php-client/autoload.php');

        $username = "XXXXX";
        $password = "XXXXX";
        $integrator_key = "XXXXX";

        // change to production (www.docusign.net) before going live
        $host = "https://www.docusign.net/restapi";

        // create configuration object and configure custom auth header
        $config = new DocuSign\eSign\Configuration();
        $config->setHost($host);
        $config->addDefaultHeader("X-DocuSign-Authentication", "{\"Username\":\"" . $username . "\",\"Password\":\"" . $password . "\",\"IntegratorKey\":\"" . $integrator_key . "\"}");

        // instantiate a new docusign api client
        $apiClient = new DocuSign\eSign\Client\ApiClient($config);
        $accountId = null;

        try {
            //*** STEP 1 - Login API: get first Account ID and baseURL
            $authenticationApi = new DocuSign\eSign\Api\AuthenticationApi($apiClient);
            $options = new \DocuSign\eSign\Api\AuthenticationApi\LoginOptions();
            $loginInformation = $authenticationApi->login($options);
            if (isset($loginInformation) && count($loginInformation) > 0) {
                $loginAccount = $loginInformation->getLoginAccounts()[0];
                $host = $loginAccount->getBaseUrl();
                $host = explode("/v2", $host);
                $host = $host[0];

                // UPDATE configuration object
                $config->setHost($host);

                // instantiate a NEW docusign api client (that has the correct baseUrl/host)
                $apiClient = new DocuSign\eSign\Client\ApiClient($config);

                if (isset($loginInformation)) {
                    $accountId = $loginAccount->getAccountId();
                    if (!empty($accountId)) {
                        //*** STEP 2 - Signature Request from a Template
                        // create envelope call is available in the EnvelopesApi
                        $envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);

                        // 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();
                        $templateRole->setEmail($vars['client_email']['value']);
                        //$templateRole->setEmail("robbielewis@me.com");
                        $templateRole->setName($vars['client_name']['value']);
                        $templateRole->setRoleName("Signee");

                        // pre-populate text tabs
                        $tabFields = array();

                        foreach ($vars as $var) {
                            $tabField = new \DocuSign\eSign\Model\Text();
                            $tabField->setTabLabel($var['label']);
                            $tabField->setValue($var['value']);
                            $tabFields[] = $tabField;
                        }

                        $tabs = new DocuSign\eSign\Model\Tabs();
                        $tabs->setTextTabs($tabFields);
                        $templateRole->setTabs($tabs);

                        // create event notification webhook
                        $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")
                        ];

                        $event_notification = new \DocuSign\eSign\Model\EventNotification();
                        $event_notification->setUrl("https://www.XXXXX.com/wp-content/plugins/XXXXX/XXXXX.php?action=docusign-callback");
                        $event_notification->setLoggingEnabled("true");
                        $event_notification->setRequireAcknowledgment("true");
                        $event_notification->setUseSoapInterface("false");
                        $event_notification->setIncludeCertificateWithSoap("false");
                        $event_notification->setSignMessageWithX509Cert("false");
                        $event_notification->setIncludeDocuments("true");
                        $event_notification->setIncludeEnvelopeVoidReason("true");
                        $event_notification->setIncludeTimeZone("true");
                        $event_notification->setIncludeSenderAccountAsCustomField("true");
                        $event_notification->setIncludeDocumentFields("true");
                        $event_notification->setIncludeCertificateOfCompletion("true");
                        $event_notification->setEnvelopeEvents($envelope_events);
                        $event_notification->setRecipientEvents($recipient_events);

                        // instantiate a new envelope object and configure settings
                        $envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
                        $envelop_definition->setEmailSubject("Please review and sign your booking contract");
                        $envelop_definition->setTemplateId("XXXXX");
                        $envelop_definition->setTemplateRoles(array($templateRole));
                        $envelop_definition->setEventNotification($event_notification);

                        // set envelope status to "sent" to immediately send the signature request
                        $envelop_definition->setStatus("sent");

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

                        // create and send the envelope (aka signature request)
                        $envelop_summary = $envelopeApi->createEnvelope($accountId, $envelop_definition, $options);
                        if (!empty($envelop_summary)) {
                            echo "Contract sent at " . date('d/m/Y H:i:s') .' to '.$templateRole->getEmail();
                        }
                    }
                }
            }
        } catch (DocuSign\eSign\ApiException $ex) {
            echo "Exception: " . $ex->getMessage() . "\n";
            file_put_contents('XXXXX.log', "\n\n" . date('d/m/Y H:i:s') . ' - Docusign API error ' . $ex->getMessage(), FILE_APPEND);
            wp_mail('XXXXX', 'Docusign API error', date('d/m/Y H:i:s') . ' - Docusign API error: ' . $ex->getMessage());
        }

这工作了好几年,直到最近我们在信封签名后才停止从Docusign将EventNotification请求发送到我们的服务器。信封仍然可以成功创建并发送给收件人。

我尝试解决此问题的方法:

  • 使用我的脚本创建了许多测试信封并对其进行了签名
  • 在脚本创建的信封签名后,监视服务器上的所有http请求的访问日志,什么也没收到
  • 将DocuSign PHP客户端更新到最新版本
  • 启用了登录DocuSign的功能,并在创建信封时检查了DocuSign是否已收到EventNotification请求,请参见此处:https://pastebin.com/xbS338Hx
  • 与我的主机联系,以确保没有硬件防火墙可以阻止服务器从DocuSign接收HTTP请求
  • 关闭Cloudflare DNS代理以确保它不会阻止对服务器的请求
  • 联系了DocuSign支持人员,后者表示无法在代码问题上提供帮助。

我还能尝试找出这个问题的原因吗?

1 个答案:

答案 0 :(得分:1)

在DocuSign Admin中使用“ DocuSign连接失败”屏幕,我能够在列表中看到失败的连接。

https://www.XXXXX.com/wp-content/plugins/sXXXXX/XXXXX.php?action=docusign-callback :: Error - The remote server returned an error: (403) Forbidden.

事实证明这是Wordpress拒绝请求的iThemes安全插件。我禁用了插件,并在DocuSign Admin中重新发布了最近失败的请求。该请求已成功通过。