Skip to content

Commit 5d402b2

Browse files
Merge pull request #47 from Dwolla/DEV-1054--sthapa-review-edits
Add print_location function, correct request syntax, read Key/Secret from env vars
2 parents da697dd + e07ae8c commit 5d402b2

File tree

3 files changed

+46
-46
lines changed

3 files changed

+46
-46
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This repository contains the source code for Dwolla's Python-based SDK, which al
1414
- [Responses](#responses)
1515
- [Success](#success)
1616
- [Error](#error)
17+
- [Example App](#example-app)
1718
- [Changelog](#changelog)
1819
- [Community](#community)
1920
- [Additional Resources](#additional-resources)
@@ -200,6 +201,13 @@ _See https://developers.dwolla.com/api-reference#errors for more info._
200201
- `dwollav2.TooManyRequestsError`
201202
- `dwollav2.ConflictError`
202203

204+
### Example App
205+
206+
Take a look at the
207+
[Sample Application](https://github.com/Dwolla/dwolla-v2-python/tree/main/sample_app) for examples
208+
on how to use this SDK to call the Dwolla API. Before you can begin using the app, however,
209+
you will need to specify a `DWOLLA_APP_KEY` and `DWOLLA_APP_SECRET` environment variable.
210+
203211
## Changelog
204212

205213
- **2.2.1**

sample_app/helpers.py

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@ def display_options():
2525
retrieve KBA (RKBA)
2626
verify KBA (VKBA)
2727
Create beneficial owner (CBO)
28-
Reterieve beneficial owner (RBO)
28+
Retrieve beneficial owner (RBO)
2929
list beneficial owners (LBO)
3030
update beneficial owner (UBO)
3131
Remove beneficial owner (DBO)
3232
Retrieve beneficial ownership status (RBOS)
3333
Certify beneficial ownership (CBOS)
34+
Quit (Q)
3435
'''
3536
print(action_menu)
3637

3738
def get_user_input():
3839
return input('Enter your action: ')
3940

40-
def handle_input(input, pk, sk):
41-
client = dwollav2.Client(key = pk, secret = sk, environment = 'sandbox')
41+
def handle_input(input, DWOLLA_APP_KEY, DWOLLA_APP_SECRET):
42+
client = dwollav2.Client(key = DWOLLA_APP_KEY, secret = DWOLLA_APP_SECRET, environment = 'sandbox')
4243
application_token = client.Auth.client()
4344
if input == 'R':
4445
root(application_token)
@@ -90,11 +91,16 @@ def handle_input(input, pk, sk):
9091
retrieve_beneficial_ownership_status(application_token)
9192
elif input == 'CBOS':
9293
certify_beneficial_ownership(application_token)
94+
elif input == 'Q':
95+
quit()
9396

9497

9598
def print_response(res):
9699
print(json.dumps(res.body, indent = 4))
97100

101+
def print_location(res):
102+
print(res.headers['Location'])
103+
98104
# ROOT RESOURCE
99105
def root(token):
100106
res = token.get('/')
@@ -112,23 +118,15 @@ def create_account_funding_source(token):
112118
bankAccountType = input('Enter your bank account type: ')
113119
name = input('Enter your funding source nickname: ')
114120

115-
has_channels = input('Does your funding source have channels? (y/n): ')
116-
117121
body = {
118122
'routingNumber': routingNumber,
119123
'accountNumber': accountNumber,
120124
'type': bankAccountType,
121125
'name': name
122126
}
123127

124-
if has_channels == 'y':
125-
channels = input('Enter your channels seperated by commas: ')
126-
channels = channels.split(',')
127-
body['channels'] = channels
128-
129-
130128
res = token.post(f'/funding-sources', body)
131-
print_response(res)
129+
print_location(res)
132130

133131
def create_account_van(token):
134132
name = input('Enter your account name: ')
@@ -141,7 +139,7 @@ def create_account_van(token):
141139
}
142140

143141
res = token.post(f'/funding-sources', body)
144-
print_response(res)
142+
print_location(res)
145143

146144
def list_account_funding_sources(token):
147145
id = input('Enter your account ID: ')
@@ -173,7 +171,7 @@ def create_receive_only_customer(token):
173171
}
174172

175173
res = token.post(f'/customers', body)
176-
print_response(res)
174+
print_location(res)
177175

178176
def create_unverified_customer(token):
179177
firstName = input('Enter customer first name: ')
@@ -187,7 +185,7 @@ def create_unverified_customer(token):
187185
}
188186

189187
res = token.post(f'/customers', body)
190-
print_response(res)
188+
print_location(res)
191189

192190
def create_verified_personal_customer(token):
193191
firstName = input('Enter customer first name: ')
@@ -215,7 +213,7 @@ def create_verified_personal_customer(token):
215213
}
216214

217215
res = token.post(f'/customers', body)
218-
print_response(res)
216+
print_location(res)
219217

220218
def retrieve_customer(token):
221219
id = input('Enter customer ID: ')
@@ -228,26 +226,10 @@ def list_and_search_customers(token):
228226

229227
def update_customer(token):
230228
id = input('Enter customer ID: ')
231-
firstName = input('Enter customer first name: ')
232-
lastName = input('Enter customer last name: ')
233-
email = input('Enter customer email: ')
234-
address1 = input('Enter customer address 1: ')
235-
city = input('Enter customer city: ')
236-
state = input('Enter customer state: ')
237-
postalCode = input('Enter customer postal code: ')
238-
dateOfBirth = input('Enter customer date of birth: ')
239-
ssn = input('Enter customer ssn: ')
229+
email = input('Enter updated customer email: ')
240230

241231
body = {
242-
'firstName': firstName,
243-
'lastName': lastName,
244232
'email': email,
245-
'address1': address1,
246-
'city': city,
247-
'state': state,
248-
'postalCode': postalCode,
249-
'dateOfBirth': dateOfBirth,
250-
'ssn': ssn,
251233
}
252234

253235
res = token.post(f'/customers/{id}', body)
@@ -266,7 +248,7 @@ def retrieve_business_classification(token):
266248
def initiate_kba(token):
267249
id = input('Enter customer ID: ')
268250
res = token.post(f'/customers/{id}/kba')
269-
print_response(res)
251+
print_location(res)
270252

271253
def retrieve_kba(token):
272254
id = input('Enter KBA session ID: ')
@@ -302,21 +284,25 @@ def create_beneficial_owner(token):
302284
address1 = input('Enter beneficial owner address 1: ')
303285
city = input('Enter beneficial owner city: ')
304286
state = input('Enter beneficial owner state: ')
287+
country = input('Enter beneficial owner country: ')
305288
postalCode = input('Enter beneficial owner postal code: ')
306289

307290
body = {
308291
'firstName': firstName,
309292
'lastName': lastName,
310293
'dateOfBirth': dateOfBirth,
311294
'ssn': ssn,
312-
'address1': address1,
313-
'city': city,
314-
'state': state,
315-
'postalCode': postalCode
295+
'address': {
296+
'address1': address1,
297+
'city': city,
298+
'stateProvinceRegion': state,
299+
'country': country,
300+
'postalCode': postalCode
301+
}
316302
}
317303

318304
res = token.post(f'/customers/{id}/beneficial-owners', body)
319-
print_response(res)
305+
print_location(res)
320306

321307
def retrieve_beneficial_owner(token):
322308
id = input('Enter beneficial owner ID: ')
@@ -337,17 +323,21 @@ def update_beneficial_owner(token):
337323
address1 = input('Enter beneficial owner address 1: ')
338324
city = input('Enter beneficial owner city: ')
339325
state = input('Enter beneficial owner state: ')
326+
country = input('Enter beneficial owner country: ')
340327
postalCode = input('Enter beneficial owner postal code: ')
341328

342329
body = {
343330
'firstName': firstName,
344331
'lastName': lastName,
345332
'dateOfBirth': dateOfBirth,
346333
'ssn': ssn,
347-
'address1': address1,
348-
'city': city,
349-
'state': state,
350-
'postalCode': postalCode
334+
'address': {
335+
'address1': address1,
336+
'city': city,
337+
'stateProvinceRegion': state,
338+
'country': country,
339+
'postalCode': postalCode
340+
}
351341
}
352342

353343
res = token.post(f'/beneficial-owners/{id}', body)

sample_app/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
import os
12
from helpers import *
23

34
exit = False
45

5-
pk = input('Enter your Dwolla public key: ')
6-
sk = input('Enter your Dwolla secret key: ')
6+
# Get DWOLLA_APP_KEY and DWOLLA_APP_KEY from environment variables
7+
DWOLLA_APP_KEY = os.getenv('DWOLLA_APP_KEY')
8+
DWOLLA_APP_SECRET = os.environ.get('DWOLLA_APP_SECRET')
79

810
while not exit:
911
display_options()
1012
input = get_user_input()
1113
if input == 'exit':
1214
exit = True
1315
else:
14-
handle_input(input, pk, sk)
16+
handle_input(input, DWOLLA_APP_KEY, DWOLLA_APP_SECRET)

0 commit comments

Comments
 (0)