Skip to content

Instantly share code, notes, and snippets.

@sebelga
Created April 16, 2018 16:02
Show Gist options
  • Save sebelga/5645b48cf7ae7686146a80c9d0f5641d to your computer and use it in GitHub Desktop.
Save sebelga/5645b48cf7ae7686146a80c9d0f5641d to your computer and use it in GitHub Desktop.
// ./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