mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-17 11:32:16 +00:00
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:
parent
ad146d6d88
commit
900d8e7dfa
1 changed files with 63 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue