Add appStore.setupBilling() using stripe
This commit is contained in:
parent
59cdb33915
commit
65002ac27a
32
appstore.js
32
appstore.js
@ -1,8 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
var debug = require('debug')('e2e:appstore'),
|
||||
path = require('path'),
|
||||
request = require('superagent-sync'),
|
||||
sleep = require('sleep').sleep,
|
||||
stripe = require('stripe');
|
||||
|
||||
exports = module.exports = AppStore;
|
||||
|
||||
@ -14,6 +16,8 @@ function AppStore(origin) {
|
||||
password: null,
|
||||
accessToken: null
|
||||
};
|
||||
|
||||
this._ecosystem = require(path.join(__dirname, '..', 'keys', 'appstore', 'ecosystem-staging.json'));
|
||||
}
|
||||
|
||||
function verifyResponse(res, errorMessage) {
|
||||
@ -82,3 +86,31 @@ AppStore.prototype.restore = function (boxId, backupId) {
|
||||
verifyResponse(res, 'Could not restore cloudron');
|
||||
};
|
||||
|
||||
AppStore.prototype.setupBilling = function (callback) {
|
||||
var stripeApi = stripe(this._ecosystem.env['STRIPE_SECRET']);
|
||||
|
||||
var that = this;
|
||||
|
||||
stripeApi.tokens.create({
|
||||
card: {
|
||||
number: '4242424242424242',
|
||||
exp_month: 12,
|
||||
exp_year: 2016,
|
||||
cvc: '123'
|
||||
}
|
||||
}, function (error, token) {
|
||||
if (error) return callback(error);
|
||||
|
||||
debug('Got stripe token', token.id);
|
||||
|
||||
var data = {
|
||||
password: that._credentials.password,
|
||||
billingToken: token.id
|
||||
};
|
||||
|
||||
var res = request.put(that._origin + '/api/v1/users').send(data).query({ accessToken: that._credentials.accessToken }).end();
|
||||
verifyResponse(res, 'Could not setup billing');
|
||||
|
||||
callback(null);
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user