Skip to content

Instantly share code, notes, and snippets.

View SimonHoiberg's full-sized avatar

Simon Høiberg SimonHoiberg

View GitHub Profile
# serverless.yml
stripe-create-customer:
handler: dist/lambdas/stripe/createCustomer.handler
events:
- http:
path: stripe/create-customer
method: post
environment:
STRIPE_SECRET_KEY: PUT-YOUR-SECRET-KEY-HERE
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY || '', {
apiVersion: '2020-03-02',
});
interface IBody {
email: string;
username: string;
}
export const handler = async (
event: APIGatewayProxyEvent,
context: any,
callback: (err: Error | null, data: any) => void,
) => {
if (!event.body) {
callback(Error('Invalid body'));
return;
}
# serverless.yml
stripe-create-subscription:
handler: dist/lambdas/stripe/createSubscription.handler
events:
- http:
path: stripe/create-subscription
method: post
environment:
STRIPE_SECRET_KEY: PUT-YOUR-SECRET-KEY-HERE
STRIPE_PRICE_ID: PUT-YOUR-PRICE-ID-HERE
interface IBody {
paymentMethodID: string;
customerID: string;
}
export const handler = async (
event: APIGatewayProxyEvent,
context: any,
callback: (err: Error | null, data: any) => void,
) => {
if (!event.body) {
callback(Error('Invalid body'));
return;
}
# serverless.yml
stripe-handle-subscription:
handler: dist/lambdas/stripe/handleSubscription.handler
events:
- http:
path: stripe/handle-subscription
method: post
environment:
STRIPE_SECRET_KEY: PUT-YOUR-SECRET-KEY-HERE
interface IBody {
subscriptionID: string;
end: boolean;
}
export const handler = async (
event: APIGatewayProxyEvent,
context: any,
callback: (err: Error | null, data: any) => void,
) => {
if (!event.body) {
callback(Error('Invalid body'));
return;
}