Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
northerner committed Dec 19, 2019
0 parents commit 913d13a
Show file tree
Hide file tree
Showing 10 changed files with 3,226 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "memberful-webhooks"
}
}
65 changes: 65 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*

# Firebase cache
.firebase/

# Firebase config

# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Memberful Firebase webhooks example

This repo is a basic example of extracting data from a Memberful webhook and storing it in Google Firebase.

To deploy you need Cloud Functions for Firebase enabled on your project and a Firestore collection named "subscriptions".

Any Memberful webhooks containing a subscription object, like "subscription.updated", will create or update the subscription by ID when posted to the function endpoint.

All the logic can be found in functions/index.js.

![Firestore screenshot](screenshot.png)
1 change: 1 addition & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
18 changes: 18 additions & 0 deletions functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const admin = require('firebase-admin');
const functions = require('firebase-functions');

admin.initializeApp();
var db = admin.firestore();

exports.subscription = functions.https.onRequest((request, response) => {
const payload = request.body

if ("subscription" in payload) {
const subscription = payload.subscription

db.collection("subscriptions").doc(subscription.id.toString()).set(subscription)
.then(function() {
response.status(200).send()
})
}
});
Loading

0 comments on commit 913d13a

Please sign in to comment.