Skip to content

Instantly share code, notes, and snippets.

@LukeMwila
Created May 5, 2019 20:44
Show Gist options
  • Save LukeMwila/f55460d4e8b383ea6c5673cd6f00d8d6 to your computer and use it in GitHub Desktop.
Save LukeMwila/f55460d4e8b383ea6c5673cd6f00d8d6 to your computer and use it in GitHub Desktop.
Handler for creating a customer
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