Skip to content

Instantly share code, notes, and snippets.

@SimonHoiberg
Created June 19, 2020 14:13
Show Gist options
  • Save SimonHoiberg/119a591da9d0ae84beb5ec048267d79a to your computer and use it in GitHub Desktop.
Save SimonHoiberg/119a591da9d0ae84beb5ec048267d79a to your computer and use it in GitHub Desktop.
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