-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_object.py
75 lines (63 loc) · 1.74 KB
/
user_object.py
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
63
64
65
66
67
68
69
70
71
72
73
74
import os
import time
import boto3
from modo import *
class AnyPayAPI(object):
def __init__(self):
self.MAPI = Modo()
self.vault = ModoVualt(self.MAPI)
self.ACCESS_KEY = os.environ.get('access_key_id')
self.SECRET_KEY = os.environ.get('secret_access_key')
self.dynamodb = boto3.resource(
'dynamodb',
region_name="us-west-1",
aws_access_key_id=self.ACCESS_KEY,
aws_secret_access_key=self.SECRET_KEY
)
self.person_table = self.dynamodb.Table("Users")
self.payment_table = self.dynamodb.Table("open_payments")
def make_user(self, first_name=None, last_name=None, phone=None, email=None):
user = ModoPerson(self.MAPI, phone=phone, email=email, lname=last_name, fname=first_name)
self.person_table.put_item(
Item={
'User_ID': user.user_id,
'First_Name': first_name,
'Last_Name': last_name,
'Phone': phone,
'Email': email,
'Payment_Methods': []
}
)
return user.user_id
def get_user(self, user_id):
person = self.person_table.get_item(
Key={
'User_ID': user_id
}
)
return person['Item']
def add_card(self, user_id, account=""):
card = ModoEscrow(self.vault, account=account)
self.person_table.update_item(
Key={
'User_ID': user_id
},
UpdateExpression="SET Payment_Methods = list_append(Payment_Methods, :i)",
ExpressionAttributeValues={
':i': [card.account]
},
ReturnValues="UPDATED_NEW"
)
return card.vault_id
def add_new_card(self, data):
self.payment_table.put_item(
Item={
'id': str(time.time()),
'data': data
}
)
if __name__ == '__main__':
a = AnyPayAPI()
user_id = a.make_user(first_name="Mark", last_name="Omo", phone="7025576763", email="[email protected]")
acc = a.add_card(user_id)
print json.dumps(a.get_user(user_id), indent=4)