Created
May 5, 2019 20:44
-
-
Save LukeMwila/f55460d4e8b383ea6c5673cd6f00d8d6 to your computer and use it in GitHub Desktop.
Handler for creating a customer
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
import { APIGatewayEvent, Callback, Context, Handler } from "aws-lambda"; | |
import { createCustomerAndSubscribeToPlan } from "./stripe-api"; | |
interface ICreateCustomer { | |
stripeToken: string; | |
email: string; | |
productPlan: string; | |
} | |
export const respond = (fulfillmentText: any): any => { | |
return { | |
statusCode: 200, | |
body: JSON.stringify(fulfillmentText), | |
headers: { | |
"Access-Control-Allow-Credentials": true, | |
"Access-Control-Allow-Origin": "*", | |
"Content-Type": "application/json" | |
} | |
}; | |
}; | |
export const createCustomer: Handler = async ( | |
event: APIGatewayEvent, | |
context: Context | |
) => { | |
const incoming: ICreateCustomer = JSON.parse(event.body); | |
const { stripeToken, email, productPlan } = incoming; | |
try { | |
const data = await createCustomerAndSubscribeToPlan( | |
stripeToken, | |
email, | |
productPlan | |
); | |
return respond(data); | |
} catch (err) { | |
return respond(err); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment