Skip to content

Instantly share code, notes, and snippets.

@ispeakcomputer
Forked from vktr/rule.js
Created December 31, 2018 09:21
Show Gist options
  • Save ispeakcomputer/2e6d4cbf7befd3d1df7e5ee8cd253771 to your computer and use it in GitHub Desktop.
Save ispeakcomputer/2e6d4cbf7befd3d1df7e5ee8cd253771 to your computer and use it in GitHub Desktop.
Add Stripe Customer Id to Auth0 via custom rule
function (user, context, callback) {
user.app_metadata = user.app_metadata || {};
if ('stripe_customer_id' in user.app_metadata) {
context.idToken['https://example.com/stripe_customer_id'] = user.app_metadata.stripe_customer_id;
return callback(null, user, context);
}
var stripe = require('stripe')('sk_....');
var customer = {
email: user.email
};
stripe.customers.create(customer, function(err, customer) {
if (err) {
return callback(err);
}
user.app_metadata.stripe_customer_id = customer.id;
auth0.users.updateAppMetadata(user.user_id, user.app_metadata)
.then(function() {
context.idToken['https://example.com/stripe_customer_id'] = user.app_metadata.stripe_customer_id;
callback(null, user, context);
})
.catch(function(err) {
callback(err);
});
});
}
@ispeakcomputer
Copy link
Author

Tie in auth0 to stripe customer ID. Solution to payment processing without building memberships?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment