-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomerAuthentication.py
More file actions
95 lines (85 loc) · 3.5 KB
/
customerAuthentication.py
File metadata and controls
95 lines (85 loc) · 3.5 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import json
import boto3
import os
client_db = boto3.client('dynamodb')
client_profile = boto3.client('customer-profiles')
def lambda_handler(event, context):
eventParameters = event['Details']['Parameters']
CustomerId = eventParameters.get('CustomerId')
CustomerNumber = eventParameters.get('CustomerNumber')
table_name = os.environ['TABLE_NAME']
domain_name = os.environ['DOMAIN_NAME']
if CustomerId == None or CustomerNumber == None:
return {
'statusCode': 500,
'lambdaResult': 'Parametros faltantes.'
}
response = client_db.query(TableName=table_name, ExpressionAttributeValues={":varString": {"S":str(CustomerId),},}, KeyConditionExpression="CustomerId = :varString",)
if response["ResponseMetadata"]["HTTPStatusCode"] == 200:
items = response.get("Items")
if items != None:
if len(items) > 0:
Address = items[0]['Address']['S']
BirthDate = items[0]['BirthDate']['S']
CPF = items[0]['CPF']['S']
Email = items[0]['Email']['S']
FirstName = items[0]['FirstName']['S']
LastName = items[0]['LastName']['S']
else:
return {
'statusCode': 500,
'lambdaResult': 'CustomerId not found'
}
profile_id = None
account_number = None
response = client_profile.search_profiles(DomainName=domain_name, KeyName='_phone', Values=[CustomerNumber])
if response["ResponseMetadata"]["HTTPStatusCode"] == 200:
items = response.get("Items")
if items != None:
if len(items) > 0:
profile_id = items[0].get("ProfileId")
account_number = items[0].get("AccountNumber")
if account_number != CPF:
response = client_profile.update_profile(
DomainName=domain_name,
ProfileId=profile_id,
PhoneNumber=CustomerNumber,
AccountNumber=CPF,
AdditionalInformation=CPF,
FirstName=FirstName,
LastName=LastName,
BirthDate=BirthDate,
EmailAddress=Email,
Address={'Address1': Address},
MailingAddress={'Address1': Address},
BillingAddress={'Address1': Address}
)
message="Perfil atualizado."
else:
message="Perfil identificado."
else:
response = client_profile.create_profile(
DomainName=domain_name,
PhoneNumber=CustomerNumber,
AccountNumber=CPF,
AdditionalInformation=CPF,
FirstName=FirstName,
LastName=LastName,
BirthDate=BirthDate,
EmailAddress=Email,
Address={'Address1': Address},
MailingAddress={'Address1': Address},
BillingAddress={'Address1': Address}
)
message="Perfil criado."
return {
'id': CustomerId,
'cpf': CPF,
'first_name': FirstName,
'last_name': LastName,
'address': Address,
'birth_date': BirthDate,
'email': Email,
'statusCode': 200,
'lambdaResult': message
}