Created
June 19, 2020 14:17
-
-
Save SimonHoiberg/68ba1da17aebef648e52dc5066e27ba7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { subscriptionID } = body; | |
if (!subscriptionID) { | |
callback(null, { | |
statusCode: 400, | |
body: 'Missing subscription id', | |
}); | |
return; | |
} | |
try { | |
// Get the subscription | |
const subscription = await stripe.subscriptions.retrieve(subscriptionID); | |
callback(null, { | |
statusCode: 200, | |
body: JSON.stringify(subscription), | |
}); | |
} catch (error) { | |
callback(error); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment