Created
April 16, 2018 16:02
-
-
Save sebelga/5645b48cf7ae7686146a80c9d0f5641d 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
// ./middleware/billing.js | |
const billingApi = require('your-billing-package'); | |
/** | |
* Dont' allow payment below 1$ | |
*/ | |
function validateAmount(amount, source, description, currency) { | |
if (amount < 1) { | |
return Promise.reject('Payement not allowed. The minimum charge is 1.00$.'); | |
} | |
return Promise.resolve(); | |
} | |
/** | |
* Only allow payement by Card | |
*/ | |
function validateSource(amount, source) { | |
if (source !== 'Card') { | |
return Promise.reject('Only "Card" payement are allowed.') | |
} | |
return Promise.resolve(); | |
} | |
// Add middleware to execute before any payement | |
// These are rules specific to this application | |
billingApi.pre('processPayement', [validateAmount, validateSource]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment