Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
adding more logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanlott committed Oct 9, 2017
1 parent 8306089 commit 9493488
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 34 deletions.
11 changes: 0 additions & 11 deletions lib/server/routes/marketing.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ const log = require('../../logger');
const errors = require('storj-service-error-types');
const Promise = require('bluebird');

// TODO: Refactor all stripe-related endpoints into a single endpoint
// to remain payment processor agnostic.

/**
* Handles endpoints for all user related operations
*/
function MarketingRouter(options) {
if (!(this instanceof MarketingRouter)) {
return new MarketingRouter(options);
Expand All @@ -37,7 +31,6 @@ MarketingRouter.prototype.get = function (req, res) {
if (doc) {
return res.status(200).send(doc);
}
console.log('no user');

Marketing.create(user, function (err, marketing) {
if (err) {
Expand All @@ -52,10 +45,6 @@ MarketingRouter.prototype.create = function (req, res) {

}

/**
* Export definitions
* @private
*/
MarketingRouter.prototype._definitions = function() {
return [
['GET', '/marketing',
Expand Down
27 changes: 10 additions & 17 deletions lib/server/routes/payment-processors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const Router = require('./index');
const middleware = require('storj-service-middleware');
const errors = require('storj-service-error-types');
const Promise = require('bluebird');
const StorjMailer = require('storj-service-mailer');
const defaults = require('../../config.js').DEFAULTS;
const mailer = new StorjMailer(defaults.mailer);

function PaymentProcessorsRouter(options) {
if (!(this instanceof PaymentProcessorsRouter)) {
Expand Down Expand Up @@ -37,7 +40,12 @@ PaymentProcessorsRouter.prototype._addPaymentProcessor = function(req) {
.then((pp) => resolve(pp))
.catch((err) => reject(err));
})
.catch((err) => reject(err));
.catch((err) => {
mailer.dispatch(req.user.id, add-card, {}, (err, res) => {
console.log('add-card email sent', res);
});
reject(err)
});
});
};

Expand All @@ -54,35 +62,24 @@ PaymentProcessorsRouter.prototype.addPaymentMethod = function(req, res, next) {
const PaymentProcessor = this.models.PaymentProcessor;
const User = this.models.User;

console.log('req.user: ', req.user);

return PaymentProcessor
.findOne({
user: req.user.id,
name: req.body.processor.name
})
.then((pp) => {
console.log('PP: ', pp);

if (pp) {
pp.addPaymentMethod(req.body.data);
console.log('added payment method with', req.body.data);
return pp;
}

self._addPaymentProcessor(req);
console.log('added payment processor');

return pp;
})
.then((pp) => {

// set user to free tier
self._setUserFreeTier(req, false);

console.log('set to free tier');

// respond
return res.status(200).send({
pp,
user: req.user
Expand All @@ -99,19 +96,16 @@ PaymentProcessorsRouter.prototype.removePaymentMethod = function(req, res, next)
PaymentProcessor.findOne({ _id: ppId })
.then((pp) => {
if (pp.paymentMethods.length <= 0) {
console.error('No payment methods to remove.');
return res.status(200).send(`No payment processor id ${ppId}`);
}

console.log('removing method', methodId);
pp.adapter.removePaymentMethod(methodId);
// mailer.dispatch(req.user._id, remove-card, {}, (

return pp;
})
.then(pp => {
const user = self._setUserFreeTier(req, true);
console.log('user: ', user);
console.log('pp: ', pp);

return res.status(200).json({
user,
Expand All @@ -132,7 +126,6 @@ PaymentProcessorsRouter.prototype.getDefaultPP = function(req, res, next) {
return res.status(200).send({ pp: null });
})
.catch((err) => {
console.error('Error #getDefaultPP', err);
res.status(500).send(err);
})
};
Expand Down
6 changes: 0 additions & 6 deletions lib/server/routes/referrals.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ ReferralsRouter.prototype.sendReferralEmail = function(req, res) {
emailList.forEach((email) => {
const emailPromise = function() {
return new Promise((resolve, reject) => {
console.log('sending from: ', marketing.user);
console.log('sending to: ', email);
console.log('sending marketing: ', marketing);
const user = marketing.user;
self._isNotCurrentUser(email)
.then(() => self._sendEmail(user, email, marketing))
Expand Down Expand Up @@ -103,16 +100,13 @@ ReferralsRouter.prototype._isNotCurrentUser = function(recipientEmail) {

ReferralsRouter.prototype._sendEmail = function(senderEmail, recipientEmail, marketing) {
return new Promise((resolve, reject) => {
console.log('GOT INTO PROMISE')
mailer.dispatch(recipientEmail, 'referral', {
url: 'https://app.storj.io/#/signup?referralLink=' + marketing.referralLink,
senderEmail: senderEmail
}, function(err) {
if (err) {
console.error('Error sendReferralEmail: ', err);
return reject(new errors.InternalError('Internal mailer error'));
}
console.log('GOT PASS ERROR');
return resolve(true);
});
});
Expand Down

0 comments on commit 9493488

Please sign in to comment.