mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
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:
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user