-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
62 lines (51 loc) · 1.54 KB
/
app.py
File metadata and controls
62 lines (51 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from flask import Flask, jsonify, request
from dotenv import load_dotenv
from venmo_api import Client
from os import getenv
import boto3
load_dotenv()
ACCESS_TOKEN = getenv('VENMO_ACCESS_TOKEN')
VENMO_TABLE = getenv('VENMO_TABLE')
IS_OFFLINE = getenv('IS_OFFLINE')
app = Flask(__name__)
venmo = Client(access_token=ACCESS_TOKEN)
if IS_OFFLINE:
client = boto3.resource(
'dynamodb',
region_name='localhost',
endpoint_url='http://localhost:8000'
)
else:
client = boto3.resource('dynamodb')
# Example of how to integrate with venmo api, dynamodb and use flask
@app.route("/createToken", methods=["POST"])
def create_token():
table = client.Table(VENMO_TABLE)
user_id = request.json['userId']
response = table.put_item(
Item={
'userId': user_id
}
)
user = venmo.user.search_for_users(query=user_id)[0]
print(user)
transactions = venmo.user.get_user_transactions(user=user)
print(transactions)
return jsonify({
'lastTransactionNote': transactions[0].note
})
@app.route('/associateVenmoUsernameWithUser', methods=["POST"])
def associate_venmo_username_with_user():
user_id = request.json.get('userId')
venmo_username = request.json.get('venmoUsername')
return jsonify({
'userId': user_id,
'venmo_username': venmo_username
})
@app.route("/verifyPaymentStatus/<string:user_id>", methods=["GET"])
def verify_payment_status(user_id):
return jsonify({
'userId': user_id
})
if __name__ == "__main__":
app.run()