I am getting error : 'NoneType' object has no attribute 'get': AttributeError. PLease help me to figure out.
File "/var/task/lambda_function.py", line 15, in lambda_handler create_stripe_customer(cardData,phone,email)
import json
import boto3
import stripe
client = boto3.client('secretsmanager')
keys = json.loads(client.get_secret_value(
SecretId = 'arn:aws:secretsmanager:ap-so',
)['SecretString'])
public_key = keys['stripe-public']
secret_key = keys['stripe-secret']
stripe.api_key = secret_key
def lambda_handler(event, context):
cardData = event.get('cardData')
phone = event.get('phone')
email = event.get('email')
create_stripe_customer(cardData,phone,email)
return event
def create_stripe_customer(payment_info, phone, email):
customer_id = stripe.Customer.create( phone = phone,email=email)['id']
payment_method_id = create_payment_method(payment_info)
stripe.PaymentMethod.attach(payment_method_id, customer = customer_id)
return {"customer_id": customer_id,
"plan": create_stripe_plan(customer_id)
}
def create_payment_method(payment_info):
return stripe.PaymentMethod.create(type = "card",
card = {"number": payment_info.get('cardNumber'),
"exp_month": payment_info.get('expirationMonth'),
"exp_year": payment_info.get('expirationYear'),
"cvc": payment_info.get('ccv'),
}).get('id')
def create_stripe_plan(customer_id):
return stripe.Subscription.create(
customer = customer_id,items = [{"plan": "plan_idxxxxxxx"}]).get("id")