Created
April 16, 2018 15:59
-
-
Save sebelga/0e4ed46e32762abbdf8f3c0dfc71d3e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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