Created
June 19, 2020 14:13
-
-
Save SimonHoiberg/119a591da9d0ae84beb5ec048267d79a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const handler = async ( | |
event: APIGatewayProxyEvent, | |
context: any, | |
callback: (err: Error | null, data: any) => void, | |
) => { | |
if (!event.body) { | |
callback(Error('Invalid body')); | |
return; | |
} | |
const body = JSON.parse(event.body) as IBody; | |
const { email, username } = body; | |
if (!email || !username) { | |
callback(null, { | |
statusCode: 400, | |
body: 'Missing email or username', | |
}); | |
return; | |
} | |
try { | |
// Create a new customer | |
const customer = await stripe.customers.create({ | |
email, | |
name: username, | |
}); | |
callback(null, { | |
statusCode: 200, | |
body: JSON.stringify(customer), | |
}); | |
} catch (error) { | |
callback(error); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment