Created
April 3, 2018 12:23
-
-
Save sebelga/f48a4f5b992f26cfeab2252022ef0f67 to your computer and use it in GitHub Desktop.
This file contains 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
// ./vendors/stripe.js | |
const stripe = require('stripe')('sk_test_your-token'); | |
const hooks = require('promised-hooks'); | |
// Add Hooks functionalities to the "stripe.charges" methods | |
hooks.wrap(stripe.charges); | |
// Add a "pre" middleware | |
stripe.charges.pre('create', function preCharge({ amount, source, description, currency }) { | |
// All the arguments passed to the charges.create() method are available | |
// Make any async call as long as it returns a *Promise*. | |
// If the async call rejects, then the "create()" method won't be executed | |
return someService.doAsyncStuff(amount, currency, description); | |
}); | |
// Add a "post" middleware | |
stripe.charges.post('create', function postCharge(charge) { | |
return myTraceService.log(`New charge ${charge.amount}`); | |
}); | |
// Export Stripe with the hooks | |
module.exports = stripe; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment