Gift Subscriptions Promo (#8270)

* WIP(promo): buy-1-get-1 subs

* WIP(subscriptions): Slack integration

* feat(Slack): notify on sub buy
This commit is contained in:
Sabe Jones
2016-12-08 18:08:56 -08:00
committed by GitHub
parent 5efe5b7b10
commit f85f2a0c6d
6 changed files with 63 additions and 4 deletions

View File

@@ -6,12 +6,15 @@ import nconf from 'nconf';
const SLACK_FLAGGING_URL = nconf.get('SLACK:FLAGGING_URL');
const SLACK_FLAGGING_FOOTER_LINK = nconf.get('SLACK:FLAGGING_FOOTER_LINK');
const SLACK_SUBSCRIPTIONS_URL = nconf.get('SLACK:SUBSCRIPTIONS_URL');
const BASE_URL = nconf.get('BASE_URL');
let flagSlack;
let subscriptionSlack;
try {
flagSlack = new IncomingWebhook(SLACK_FLAGGING_URL);
subscriptionSlack = new IncomingWebhook(SLACK_SUBSCRIPTIONS_URL);
} catch (err) {
logger.error(err);
}
@@ -61,6 +64,31 @@ function sendFlagNotification ({
});
}
function sendSubscriptionNotification ({
buyer,
recipient,
paymentMethod,
months,
}) {
if (!SLACK_SUBSCRIPTIONS_URL) {
return;
}
let text;
let timestamp = new Date();
if (!recipient.id) {
text = `${buyer.name} ${buyer.id} ${buyer.email} bought a ${months}-month recurring subscription using ${paymentMethod} on ${timestamp}`;
} else if (recipient.id === buyer.id) {
text = `${buyer.name} ${buyer.id} ${buyer.email} bought a ${months}-month gift subscription for ${recipient.name} ${recipient.id} ${recipient.email} using ${paymentMethod} on ${timestamp}`;
} else {
text = `${buyer.name} ${buyer.id} ${buyer.email} bought a ${months}-month gift subscription for ${recipient.name} ${recipient.id} ${recipient.email} and got a promo using ${paymentMethod} on ${timestamp}`;
}
subscriptionSlack.send({
text,
});
}
module.exports = {
sendFlagNotification,
sendSubscriptionNotification,
};