Skip to content

Instantly share code, notes, and snippets.

@SimonHoiberg
Created June 19, 2020 14:18
Show Gist options
  • Save SimonHoiberg/ba30bf2fe25d27ad1a20f81aceadc3b5 to your computer and use it in GitHub Desktop.
Save SimonHoiberg/ba30bf2fe25d27ad1a20f81aceadc3b5 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 { paymentMethodID } = body;
if (!paymentMethodID) {
callback(null, {
statusCode: 400,
body: 'Invalid payment method',
});
return;
}
try {
// Get the payment method
const paymentMethod = await stripe.paymentMethods.retrieve(paymentMethodID);
callback(null, {
statusCode: 200,
body: JSON.stringify(paymentMethod),
});
} catch (error) {
callback(error);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment