node-mangopay
Version:
mangopay package for payment implementation with nodejs
49 lines (38 loc) • 1.12 kB
JavaScript
function node_mangopay(options) {
this._options = options || {};
if(!(this instanceof node_mangopay))
return new node_mangopay(options)
if(Object.keys(this._options).length==0)
return {};
this._api = {
auth: false
, protocol: 'https'
, host: 'api.sandbox.mangopay.com'
, port: ''
, basePath: ''
, version: this._options.version || 'v2.01'
};
// set base path
this._api.basePath = ['/', this._api.version, '/', this._options.clientid].join('')
// switch to production url
if(this._options.production)
this._api.host = 'api.mangopay.com';
this.auth(options);
return require('./api/services')(this._api);
}
node_mangopay.prototype={
auth :function(options){
if (!(options.hasOwnProperty('clientid')) || !(options.hasOwnProperty('passphrase')))
{
throw Error('Provide credentials');
}
else
{
if(!options.clientid || !options.passphrase)
throw Error('Provide credentials');
else
this._api.auth='Basic ' + new Buffer(options.clientid + ':' + options.passphrase).toString('base64')
}
}
}
module.exports = node_mangopay