Skip to content

Commit 7971789

Browse files
author
Olena Harkusha
committed
Add create a new clickwrap version example
1 parent 62d95f7 commit 7971789

7 files changed

Lines changed: 199 additions & 2 deletions

File tree

app/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
elif EXAMPLES_API_TYPE["Click"]:
4747
app.register_blueprint(click_examples.eg001)
4848
app.register_blueprint(click_examples.eg002)
49+
app.register_blueprint(click_examples.eg005)
4950
app.register_blueprint(click_examples.eg006)
5051
else:
5152
app.register_blueprint(examples.eg001)

app/click/examples/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from .eg001_create_clickwrap import eg001
22
from .eg002_activate_clickwrap import eg002
3+
from .eg005_create_new_clickwrap_version import eg005
34
from .eg006_list_clickwraps import eg006
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .views import eg005
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import base64
2+
from os import path
3+
4+
from docusign_click import AccountsApi, ClickwrapRequest, DisplaySettings, \
5+
Document
6+
from flask import session
7+
8+
from ....consts import demo_docs_path
9+
from ....ds_config import DS_CONFIG
10+
from ...utils import create_click_api_client
11+
12+
13+
class Eg005Controller:
14+
@staticmethod
15+
def get_args():
16+
"""Get required session and request arguments"""
17+
return {
18+
"account_id": session["ds_account_id"], # Represents your {ACCOUNT_ID}
19+
"access_token": session["ds_access_token"], # Represents your {ACCESS_TOKEN}
20+
"clickwrap_id": session["clickwrap_id"],
21+
"clickwrap_name": session["clickwrap_name"],
22+
}
23+
24+
@staticmethod
25+
def worker(args):
26+
"""
27+
1. Create an API client with headers
28+
2. Create a display settings model
29+
3. Create a document model.
30+
4. Create a clickwrap request model
31+
5. Create a new clickwrap version using SDK
32+
"""
33+
# Step 1. Create an API client with headers
34+
api_client = create_click_api_client(
35+
access_token=args["access_token"]
36+
)
37+
38+
# Step 2. Create a display settings model
39+
display_settings = DisplaySettings(
40+
consent_button_text="I Agree",
41+
display_name=f"{args.get('clickwrap_name')} v2",
42+
downloadable=False,
43+
format="modal",
44+
must_read=True,
45+
must_view=False,
46+
require_accept=False,
47+
# size="medium",
48+
document_display="document",
49+
send_to_email=False
50+
)
51+
52+
# read file from a local directory
53+
# The reads could raise an exception if the file is not available!
54+
with open(path.join(demo_docs_path, DS_CONFIG["doc_terms_pdf"]),
55+
"rb") as file:
56+
doc_docx_bytes = file.read()
57+
doc_b64 = base64.b64encode(doc_docx_bytes).decode("ascii")
58+
59+
# Step 3. Create a document model.
60+
document = Document( # create the DocuSign document object
61+
document_base64=doc_b64,
62+
document_name="Terms of Service", # can be different from actual file name
63+
file_extension="pdf", # many different document types are accepted
64+
order=0
65+
)
66+
67+
# Step 4. Create a clickwrap request model
68+
clickwrap_request = ClickwrapRequest(
69+
display_settings=display_settings,
70+
documents=[document, ],
71+
name=args.get("clickwrap_name"),
72+
require_reacceptance=True,
73+
status="active"
74+
# user_id=DS_CONFIG["signer_name"]
75+
)
76+
77+
# Step 5. Create a new clickwrap version using SDK
78+
accounts_api = AccountsApi(api_client)
79+
response = accounts_api.create_clickwrap_version(
80+
account_id=args["account_id"],
81+
clickwrap_id=args["clickwrap_id"],
82+
clickwrap_request=clickwrap_request,
83+
)
84+
85+
return response
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""Example 005: Creating a new clickwrap version"""
2+
3+
from os import path
4+
import json
5+
6+
from docusign_click.client.api_exception import ApiException
7+
from flask import render_template, current_app, Blueprint, session
8+
9+
from .controller import Eg005Controller
10+
from app.docusign import authenticate
11+
from app.ds_config import DS_CONFIG
12+
from app.error_handlers import process_error
13+
14+
eg = "eg005" # reference (and url) for this example
15+
eg005 = Blueprint("eg005", __name__)
16+
17+
18+
@eg005.route("/eg005", methods=["POST"])
19+
@authenticate(eg=eg)
20+
def create_new_clickwrap_version():
21+
"""
22+
1. Get required arguments
23+
2. Call the worker method
24+
3. Render the response
25+
"""
26+
# 1. Get required arguments
27+
args = Eg005Controller.get_args()
28+
29+
try:
30+
# 2. Call the worker method to create a new clickwrap version
31+
results = Eg005Controller.worker(args)
32+
current_app.logger.info(
33+
f"""The 2nd version of clickwrap "{args['clickwrap_name']}" has been created!"""
34+
)
35+
except ApiException as err:
36+
return process_error(err)
37+
38+
# 3. Render the response
39+
return render_template(
40+
"example_done.html",
41+
title="Creating a new clickwrap version",
42+
h1="Creating a new clickwrap version",
43+
message=f"""The 2nd version of clickwrap "{args['clickwrap_name']}" has been created!""",
44+
json=json.dumps(json.dumps(results.to_dict(), default=str))
45+
)
46+
47+
48+
@eg005.route("/eg005", methods=["GET"])
49+
@authenticate(eg=eg)
50+
def get_view():
51+
"""responds with the form for the example"""
52+
return render_template(
53+
"eg005_create_new_clickwrap_version.html",
54+
title="Creating a new clickwrap version",
55+
clickwrap_ok="clickwrap_id" in session,
56+
source_file=path.basename(path.dirname(__file__)) + "/controller.py",
57+
source_url=DS_CONFIG["github_example_url"] + path.basename(
58+
path.dirname(__file__)) + "/controller.py",
59+
)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!-- extend base layout --> {% extends "base.html" %} {% block content %}
2+
<h4>5. Creating a new clickwrap version</h4>
3+
<p>This example demonstrates how to use the Click API to create a new version
4+
of a clickwrap.<br/>You can specify whether you require users who have
5+
previously accepted the clickwrap to accept the new version when they
6+
return to your website.</p>
7+
8+
{% if show_doc %}
9+
<p><a target='_blank' href='{{ documentation | safe }}'>Documentation</a>
10+
about this example.</p>
11+
{% endif %}
12+
13+
<p>API method used:
14+
<a target='_blank'
15+
href="https://developers.docusign.com/docs/click-api/reference/accounts/clickwraps/updateclickwrapversion">ClickWraps::updateClickwrapVersion</a>
16+
</p>
17+
18+
<p>
19+
View source file <a target="_blank" href="{{ source_url | safe }}">{{
20+
source_file }}</a> on GitHub.
21+
</p>
22+
23+
{% if clickwrap_ok %}
24+
<p>The clickwrap you created via example 1 will be queried.</p>
25+
26+
<form class="eg" action="" method="post" data-busy="form">
27+
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
28+
<button type="submit" class="btn btn-docu">Continue</button>
29+
</form>
30+
31+
{% else %}
32+
<p>Problem: please first create a clickwrap using <a href="eg001">example
33+
1.</a><br/>Thank you.</p>
34+
35+
<form class="eg" action="eg001" method="get">
36+
<button type="submit" class="btn btn-docu">Continue</button>
37+
</form>
38+
{% endif %}
39+
40+
{% endblock %}

app/click/templates/home_click.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,18 @@ <h4 id="example002">2. <a href="eg002">Activating a clickwrap</a></h4>
4949
<a target='_blank'
5050
href="https://developers.docusign.com/docs/click-api/reference/accounts/clickwraps/updateclickwrapversion">ClickWraps::updateClickwrapVersion</a>
5151
</p>
52-
<h4 id="example006">6. <a href="eg006">Getting a list of clickwraps</a></h4>
53-
<p>This example demonstrates how to use the Click API to get a list of clickwraps associated with a specific DocuSign user.</p>
52+
<h4 id="example005">5. <a href="eg005">Creating a new clickwrap
53+
version</a></h4>
54+
<p>This example demonstrates how to use the Click API to
55+
create a new version of a clickwrap.</p>
56+
<p>API method used:
57+
<a target='_blank'
58+
href="https://developers.docusign.com/docs/click-api/reference/accounts/clickwraps/updateclickwrapversion">ClickWraps::updateClickwrapVersion</a>
59+
</p>
60+
<h4 id="example006">6. <a href="eg006">Getting a list of clickwraps</a>
61+
</h4>
62+
<p>This example demonstrates how to use the Click API to get a list of
63+
clickwraps associated with a specific DocuSign user.</p>
5464
<p>API method used:
5565
<a target='_blank'
5666
href="https://developers.docusign.com/docs/click-api/reference/accounts/clickwraps/getclickwraps">ClickWraps::getClickwraps</a>

0 commit comments

Comments
 (0)