serverless-stripe
v0.1.1
Published
Serverless plugin for managing Stripe webhooks.
Downloads
254
Readme
Serverless Stripe Plugin
This plugin is designed for the Serverless Framework. It automates the creation of Stripe webhooks and binds them to serverless functions. It also provides some basic functionality for creating products and prices to them (the focus is is to help create subscriptions that utilize those).
Steps for using this plugin:
Install and configure the
serverless-domain-manager
plugin.Generate a Stripe API key. You'll need permissions for managing webhooks, products, customer portal and prices. Also make sure you have aws rights to put and read aws ssm parameters
Modify your serverless configuration as shown below:
custom: { stripe: [ { accountId: 'Default', apiKey: 'my-stripe-api-key', webhooks: [ { functionName: 'webhookHandler', events: [ 'invoice.payment_succeeded', ], webhookSecretEnvVariableName: 'stripeWebhookSecret', }, ], products: [ { name: 'Subscription', internal: { id: 'subscription', description: 'Subscription product', }, prices: [ { id: 'price_sweden', price: 9900, currency: 'sek', interval: 'year', countryCode: 'SE', }, ], }, ], billingPortals: [ { configuration: {...}, //Stripe.BillingPortal.ConfigurationCreateParams internalId: 'portal2', envVariableName: 'customerSupportPortalId', }, ], } ], domain: { // Please note these are serverless-domain-manager configurations but they're also used in this plugin domainName: "mydomain.com", basePath: "my-api", }, },
Develop the
webhookHandler
function. The Stripe webhook endpoint secret will be available asprocess.env.stripeWebhookSecret
(or under whatever name you've configured inwebhookSecretEnvVariableName
).If you add any products, the generated Stripe product id will be accessible through environment variables, using the internal id (e.g.,
process.env["subscription"]
in this example). The same applies to product prices (e.g.,process.env["price_sweden"]
for this case).Deploy your Serverless application.
You can refer to the source code provided if you're interested in the underlying implementation of this plugin.