fix(emails): re-add emails for payments, @lefnire should be ok now I had used req.user but it did not exist. There is a way to test payments locally? Because even now I can not verify it is really ok

This commit is contained in:
Matteo Pagliazzi 2014-09-17 15:55:19 +02:00
parent ad146d6d88
commit 900d8e7dfa

View file

@ -10,6 +10,7 @@ var User = require('./../models/user').model;
var ga = require('./../utils').ga;
var logging = require('./../logging');
var userAPI = require('./user');
var request = require('request');
var api = module.exports;
var isProduction = nconf.get("NODE_ENV") === "production";
@ -54,6 +55,37 @@ function createSubscription(user, data) {
revealMysteryItems(user);
user.purchased.txnCount++;
ga.event('subscribe', data.paymentMethod).send()
if(isProduction){
var email, name;
if(user.auth.local){
email = user.auth.local.email;
name = user.profile.name || user.auth.local.username;
}else if(user.auth.facebook && user.auth.facebook.emails && user.auth.facebook.emails[0] && user.auth.facebook.emails[0].value){
email = user.auth.facebook.emails[0].value;
name = user.auth.facebook.displayName || user.auth.facebook.username;
}
if(email){
request({
url: nconf.get('EMAIL_SERVER_URL') + '/job',
method: 'POST',
auth: {
user: nconf.get('EMAIL_SERVER_AUTH_USER'),
pass: nconf.get('EMAIL_SERVER_AUTH_PASSWORD')
},
json: {
type: 'email',
data: {
emailType: 'subscription-begins',
to: {
name: name,
email: email
}
}
}
});
}
}
ga.transaction(data.customerId, 5).item(5, 1, data.paymentMethod.toLowerCase() + '-subscription', data.paymentMethod + " > Stripe").send();
}
@ -74,6 +106,37 @@ function buyGems(user, data) {
user.purchased.txnCount++;
ga.event('checkout', data.paymentMethod).send();
ga.transaction(data.customerId, 5).item(5, 1, data.paymentMethod.toLowerCase() + "-checkout", "Gems > " + data.paymentMethod).send();
if(isProduction){
var email, name;
if(user.auth.local){
email = user.auth.local.email;
name = user.profile.name || user.auth.local.username;
}else if(user.auth.facebook && user.auth.facebook.emails && user.auth.facebook.emails[0] && user.auth.facebook.emails[0].value){
email = user.auth.facebook.emails[0].value;
name = user.auth.facebook.displayName || user.auth.facebook.username;
}
if(email){
request({
url: nconf.get('EMAIL_SERVER_URL') + '/job',
method: 'POST',
auth: {
user: nconf.get('EMAIL_SERVER_AUTH_USER'),
pass: nconf.get('EMAIL_SERVER_AUTH_PASSWORD')
},
json: {
type: 'email',
data: {
emailType: 'donation',
to: {
name: name,
email: email
}
}
}
});
}
}
}
// Expose some functions for tests