-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (38 loc) · 975 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
var fs = require('fs');
var path = require('path');
var stripe = require('stripe');
var stripetools = require('./lib/stripetools');
function create(configstr) {
var config;
if (!configstr) {
try {
config = {
apikey: fs.readFileSync(__dirname + '/apikey').toString()
};
} catch (e) {
console.log('No auth supplied');
process.exit(1);
}
} else if (configstr[0] === '@') {
var configfile = configstr.slice(1);
if (configfile.indexOf('/') === -1) {
configfile = path.parse(process.cwd() + '/' + configfile);
}
config = fs.readFileSync(configfile);
} else {
try {
config = JSON.parse(configstr);
} catch (e) {
config = {
apikey: configstr
};
}
}
var instance = Object.create(stripetools);
instance.config = config;
instance.stripe = stripe(config.apikey);
instance.apikey = config.apikey;
return instance;
}
exports.create = create;