Skip to content

Instantly share code, notes, and snippets.

@sebelga
Created April 16, 2018 15:59
Show Gist options
  • Save sebelga/0e4ed46e32762abbdf8f3c0dfc71d3e0 to your computer and use it in GitHub Desktop.
Save sebelga/0e4ed46e32762abbdf8f3c0dfc71d3e0 to your computer and use it in GitHub Desktop.
// your-billing-package
const stripe = require('stripe')('sk_test_token');
const hooks = require('promised-hooks');
const { notify } = require('some-notification-package');
async function processPayement(amount, source, description, currency) {
return new Promise((resolve, reject) => {
let charge;
try {
charge = await stripe.charges.create({
amount,
source,
description,
currency
});
} catch(e) {
// Error handling
// Might want to retry under certain conditions
reject(e);
}
try {
notify('New payement received', { amount, source, description });
} catch(e) {
// Silently fail
}
resolve(charge);
});
}
const api = {
processPayement
};
// Add hook functionalities to the api
hooks.wrap(api);
module.exports = api;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment