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

Commit

Permalink
Merge e3c50ee into 927c69a
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Lott committed Mar 5, 2018
2 parents 927c69a + e3c50ee commit 82f9c95
Show file tree
Hide file tree
Showing 8 changed files with 818 additions and 293 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "6.9.1"
- "8.9.3"
after_script:
- npm run coverage
- cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
1 change: 0 additions & 1 deletion bin/create-debits.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const BILLING_URL = process.env.BILLING_URL || 'http://localhost:3000';
const PRIVKEY = process.env.PRIVKEY ||
'd6b0e5ac88be1f9c3749548de7b6148f14c2ca8ccdf5295369476567e8c8d218';


function start() {
const billingClient = new BillingClient(BILLING_URL, PRIVKEY);
const storage = new Storage(process.env.MONGO_URL || 'mongodb://127.0.0.1:27017/bridge', mongoOptions);
Expand Down
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
Loading

0 comments on commit 82f9c95

Please sign in to comment.