Skip to content

Commit 4c10a18

Browse files
added dynamic content (#28)
1 parent 51d10ad commit 4c10a18

File tree

10 files changed

+32472
-14353
lines changed

10 files changed

+32472
-14353
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ DS_PAYMENT_GATEWAY_ID={DS_PAYMENT_GATEWAY_ID}
1616
DS_PAYMENT_GATEWAY_NAME={DS_PAYMENT_GATEWAY_NAME}
1717
DS_PAYMENT_GATEWAY_DISPLAY_NAME={DS_PAYMENT_GATEWAY_DISPLAY_NAME}
1818

19+
# The ID of clickwrap with dynamic content properties
20+
CLICKWRAP_ID={CLICKWRAP_ID}
21+
1922
# private key string - source or path, for instance: /app/id_rsa
2023
# NOTE: the Python config file parser requires that you
2124
# add a space at the beginning of the second and

README.MD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ MySure demonstrates the following:
4545
* **DS_PAYMENT_GATEWAY_ID** - Payment gateway ID (Only Stripe method supported)
4646
* **DS_PAYMENT_GATEWAY_NAME** - Payment gateway name
4747
* **DS_PAYMENT_GATEWAY_DISPLAY_NAME** - Payment gateway display name
48+
* **CLICKWRAP_ID** - The ID of clickwrap with dynamic content properties
4849
* **DS_PRIVATE_KEY** - Private key string, source or path; for instance: /app/id_rsa
4950
* **REACT_APP_DS_RETURN_URL** - URL where the back end of the application is located (If you run it locally, use `http://localhost:3000`)
5051
* **REACT_APP_API_BASE_URL** - URL where the front end of the application is located; will be used by Docusign to redirect back after signing ceremony (If you run it locally, use `http://localhost:5001/api`)
@@ -63,6 +64,8 @@ MySure demonstrates the following:
6364
5. Update the **.env** file with the integration key and other settings.
6465
> **Note:** Protect your integration key and client secret. You should make sure that the **.env** file will not be stored in your source code repository.
6566
67+
> **Note:** You should add a dynamic content properties to your clickwrap by following this [instruction](https://developers.docusign.com/docs/click-api/click101/customize-clickwrap-fields/) before using it in the sample app.
68+
6669
**Using installation scripts**
6770

6871
1. Download or clone this repository to your workstation in a new folder named **sample-app-mysure-python**.

app/api/clickwrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def insurance_renewal():
2424
}
2525

2626
try:
27-
clickwrap_ = Clickwrap.create(clickwrap_args, session)
27+
clickwrap_ = Clickwrap.get(clickwrap_args, session)
2828
except ApiException as exc:
2929
return process_error(exc)
3030
return jsonify(clickwrap=clickwrap_)

app/clickwrap.py

Lines changed: 8 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,17 @@
1-
import base64
2-
from os import path
3-
4-
from app.ds_config import (
5-
TPL_PATH,
6-
CLICKWRAP_BASE_HOST,
7-
CLICKWRAP_BASE_URI
8-
)
9-
from app.ds_client import DsClient
10-
1+
from app.ds_config import CLICKWRAP_ID
112

123
class Clickwrap: # pylint: disable=too-few-public-methods
134
@staticmethod
14-
def create(args, session):
15-
"""Creates a clickwrap for an account
16-
Parameters:
17-
args (dict): Parameters for the clickwrap.
5+
def get(args, session):
6+
"""Gets a clickwrap and account data
187
Returns:
19-
JSON structure of the created clickwrap.
8+
JSON structure of the clickwrap.
209
"""
21-
terms_name = args.get('terms_name')
22-
file_name = 'terms-renewal.docx'
2310
account_id = session.get('account_id')
2411

25-
with open(path.join(TPL_PATH, file_name), 'rb') as binary_file:
26-
binary_file_data = binary_file.read()
27-
base64_encoded_data = base64.b64encode(binary_file_data)
28-
base64_terms = base64_encoded_data.decode('utf-8')
29-
30-
# Construct clickwrap JSON body
31-
body = {
32-
'displaySettings': {
33-
'consentButtonText': 'I Agree',
34-
'displayName': args.get('display_name'),
35-
'downloadable': True,
36-
'format': 'modal',
37-
'hasAccept': True,
38-
'mustRead': True,
39-
'requireAccept': True,
40-
'size': 'medium',
41-
'documentDisplay': 'document',
42-
},
43-
'documents': [
44-
{
45-
'documentBase64': base64_terms,
46-
'documentName': terms_name,
47-
'fileExtension': file_name[file_name.rfind('.')+1:],
48-
'order': 0
49-
}
50-
],
51-
'name': terms_name,
52-
'requireReacceptance': True
12+
clickwrap = {
13+
'accountId': account_id,
14+
'clickwrapId': CLICKWRAP_ID
5315
}
5416

55-
# Make a POST call to the clickwraps endpoint to create a clickwrap for an account
56-
ds_client = DsClient.get_configured_instance(
57-
session.get('access_token'),
58-
CLICKWRAP_BASE_HOST
59-
)
60-
61-
uri = f"{CLICKWRAP_BASE_URI}/{account_id}/clickwraps"
62-
response = ds_client.call_api(
63-
uri, 'POST', body=body, response_type='object'
64-
)
65-
66-
clickwrap_id = response[0].get('clickwrapId')
67-
68-
# Make a PUT call to the clickwraps endpoint to activate created clickwrap
69-
uri = f"{CLICKWRAP_BASE_URI}/{account_id}/clickwraps/{clickwrap_id}/versions/1"
70-
response_active = ds_client.call_api(
71-
uri, 'PUT', body={'status': 'active'}, response_type='object'
72-
)
73-
return response_active[0]
17+
return clickwrap

app/ds_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@
2020
DS_RETURN_URL = os.environ.get('REACT_APP_DS_RETURN_URL')
2121
DS_AUTH_SERVER = os.environ.get('DS_AUTH_SERVER')
2222
DS_DEMO_SERVER = os.environ.get('REACT_APP_DS_DEMO_SERVER')
23+
24+
CLICKWRAP_ID = os.environ.get('CLICKWRAP_ID')

0 commit comments

Comments
 (0)