Socket
Book a DemoInstallSign in
Socket

feathers-stripe-webhooks

Package Overview
Dependencies
Maintainers
3
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

feathers-stripe-webhooks

Handle stripe webhooks in a feathersjs service

2.1.6
latest
Source
npmnpm
Version published
Weekly downloads
79
229.17%
Maintainers
3
Weekly downloads
 
Created
Source

feathers-stripe-webhooks

Build Status

Installation

npm install --save feathers-stripe-webhooks

Usage

// default.json
{
  "stripe": {
    "apiKey": "sk_test_MP5bNSfgUyBG2cq3bCntjfLm",
    "webhooks": {
      "signature": {
        "verify": true,
        "secret": "whsec_sZYN4b3x00PWFvTejfY5xudYx4D8TvW9"
      }
    }
  }
}
// app.js
const stripe = require('stripe')(config.stripe.apiKey);
const { stripeSignatureValidationMiddleware } = require('feathers-stripe-webhooks');

if (config.stripe.webhooks.signature.verify)
  app.configure(stripeSignatureValidationMiddleware(stripe, '/stripe/webhooks', config.stripe.webhooks.signature.secret));

// run other body-parser rules here, i.e. app.use(bodyParser.json())
// stripe-webhooks.service.js
const { stripeWebhooksService } = require('feathers-stripe-webhooks');
const handlers = require('./stripe-webhooks.handlers');
const hooks = require('./stripe-webhooks.hooks');

module.exports = function (app) {
  app.use('/stripe/webhooks', stripeWebhooksService(handlers));

  const service = app.service('stripe/webhooks');

  service.hooks(hooks);
};
// stripe-webhooks.handlers.js
module.exports = {
  customer: {
    // Handles customer.created event
    async created({ object, event, params, app }) {
      // Handle webhook
      // NOTE: Whatever you return will be returned as a response to stripe.
      // If you return undefined feathers will 404 and the hook will fail
      
      params.doSomething = true;
      
      return {};
    },
    async updated({ object, event, params, app }) {
      return {};
    },
    subscription: {
      async created({ object, event, params, app }) {
        return {};
      },
    },
  },
  invoice: {
    // Handles invoice.created event
    async created() { /*...*/ },
  },
  //....
};
// stripe-webhooks.hooks.js
module.exports = {
  after: {
    create: [
      iff(hook => hook.params.doSomething,
        doSomething()
      ),
    ],
  },
};

Keywords

feathers

FAQs

Package last updated on 04 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.