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

Commit

Permalink
Merge a75281b into 927c69a
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Lott committed Feb 22, 2018
2 parents 927c69a + a75281b commit 1c2534e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ TODO.md
.env
coverage
npm-debug.log
package-lock.json
4 changes: 2 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ Config.DEFAULTS = {
level: CONSTANTS.LOG_LEVEL_INFO
},
coinpayments: {
merchantId: process.env.CP_MERCHANT_ID || '',
merchantSecret: process.env.CP_IPN_SECRET || ''
merchantId: ENV.CP_MERCHANT_ID || '',
merchantSecret: ENV.CP_IPN_SECRET || ''
}
};

Expand Down
20 changes: 17 additions & 3 deletions lib/server/routes/coinpayments.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ CoinpaymentsRouter.prototype._currentPrice = function () {

CoinpaymentsRouter.prototype.handleIPN = function (req, res) {
log.info('handle ipn request', req.body);
const self = this;
const PaymentProcessor = this.models.PaymentProcessor;
const Credit = this.models.Credit;

const User = this.models.User;
let credit;

const formatted = {
Expand Down Expand Up @@ -134,6 +135,8 @@ CoinpaymentsRouter.prototype.handleIPN = function (req, res) {
data: req.body
});

self._isFreeTier(credit.user, false)

return credit.save()
.then((savedCredit) => {
log.info('credit created', savedCredit);
Expand All @@ -144,6 +147,8 @@ CoinpaymentsRouter.prototype.handleIPN = function (req, res) {
credit.paid_amount = USD;
credit.paid = true;

self._isFreeTier(credit.user, false)

return credit.save()
.then((savedCredit) => {
log.info('ipn credit found and updated', savedCredit);
Expand All @@ -167,14 +172,23 @@ CoinpaymentsRouter.prototype.handleIPN = function (req, res) {
}
}

CoinpaymentsRouter.prototype._isFreeTier = function (user, status) {
return User.findOne({ _id: user })
.then((_user) => {
user.isFreeTier = status;
return user.save()
})
.catch((err) => log.error(`error marking user ${user._id} as isFreeTier ${status}`))
}

CoinpaymentsRouter.prototype._definitions = function () {
return [
['POST', '/coinpayments',
bodyParser.urlencoded({ extended: true }),
bodyParser.json(),
Coinpayments.ipn({
'merchantId': this.config.coinpayments.merchantId,
'merchantSecret': this.config.coinpayments.merchantSecret
'merchantId': this.config.coinpayments.merchantId || process.env.CP_MERCHANT_ID,
'merchantSecret': this.config.coinpayments.merchantSecret || process.env.CP_IPN_SECRET
}),
this.handleIPN
]
Expand Down
7 changes: 2 additions & 5 deletions lib/server/routes/credits.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CreditsRouter.prototype.handleSignups = function (req, res) {
console.log('Error creating signup marketing: ', err);
return res.status(500).send(err);
}
console.log('CREATED MARKETING DOC: ', marketing);

if (req.body.referralLink) {
return self.handleReferralSignup(req, res);
}
Expand Down Expand Up @@ -149,8 +149,6 @@ CreditsRouter.prototype._issueReferralSignupCredit = function(data, referral) {
const Credit = this.models.Credit;

return new Promise((resolve, reject) => {
console.log('_issueReferralSignupCredit', data, referral.id);

const newCredit = new Credit({
user: data.email,
type: CREDIT_TYPES.AUTO,
Expand Down Expand Up @@ -186,7 +184,7 @@ CreditsRouter.prototype._convertReferralRecipient = function(referral, credit) {
};

function handlePaymentFailure(res) {
console.log("payment failed: ", res.locals.event.type);
console.log('payment failed: ', res.locals.event.type);
}

CreditsRouter.prototype.verify = function(req, res, next) {
Expand Down Expand Up @@ -332,7 +330,6 @@ CreditsRouter.prototype.handleConfirmCredit = function(req, res) {
};

CreditsRouter.prototype.getCredits = function(req, res, next) {
console.log('body', req.body, 'params', req.params, 'query', req.query);
const Credit = this.models.Credit;

if (!req.query.startDate && !req.query.endDate) {
Expand Down
34 changes: 17 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1c2534e

Please sign in to comment.