mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
WIP: Buy-1-Get-1 Gift Subs (#9719)
* feat(promo): Buy-1-Get-1 Gift Subs * feat(promo): add explanatory text to subscription screens Also adds some add'l test coverage and creates a test context for this event
This commit is contained in:
@@ -191,7 +191,7 @@ describe('payments/index', () => {
|
|||||||
await api.createSubscription(data);
|
await api.createSubscription(data);
|
||||||
let msg = '\`Hello recipient, sender has sent you 3 months of subscription!\`';
|
let msg = '\`Hello recipient, sender has sent you 3 months of subscription!\`';
|
||||||
|
|
||||||
expect(user.sendMessage).to.be.calledOnce;
|
expect(user.sendMessage).to.be.calledTwice;
|
||||||
expect(user.sendMessage).to.be.calledWith(recipient, { receiverMsg: msg, senderMsg: msg });
|
expect(user.sendMessage).to.be.calledWith(recipient, { receiverMsg: msg, senderMsg: msg });
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -229,6 +229,77 @@ describe('payments/index', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
context('Winter 2017-18 Gift-1-Get-1 Promotion', async () => {
|
||||||
|
it('creates a gift subscription for purchaser and recipient if none exist', async () => {
|
||||||
|
await api.createSubscription(data);
|
||||||
|
|
||||||
|
expect(user.items.pets['Jackalope-RoyalPurple']).to.eql(5);
|
||||||
|
expect(user.purchased.plan.customerId).to.eql('Gift');
|
||||||
|
expect(user.purchased.plan.dateTerminated).to.exist;
|
||||||
|
expect(user.purchased.plan.dateUpdated).to.exist;
|
||||||
|
expect(user.purchased.plan.dateCreated).to.exist;
|
||||||
|
|
||||||
|
expect(recipient.items.pets['Jackalope-RoyalPurple']).to.eql(5);
|
||||||
|
expect(recipient.purchased.plan.customerId).to.eql('Gift');
|
||||||
|
expect(recipient.purchased.plan.dateTerminated).to.exist;
|
||||||
|
expect(recipient.purchased.plan.dateUpdated).to.exist;
|
||||||
|
expect(recipient.purchased.plan.dateCreated).to.exist;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds extraMonths to existing subscription for purchaser and creates a gift subscription for recipient without sub', async () => {
|
||||||
|
user.purchased.plan = plan;
|
||||||
|
|
||||||
|
expect(user.purchased.plan.extraMonths).to.eql(0);
|
||||||
|
|
||||||
|
await api.createSubscription(data);
|
||||||
|
|
||||||
|
expect(user.purchased.plan.extraMonths).to.eql(3);
|
||||||
|
|
||||||
|
expect(recipient.items.pets['Jackalope-RoyalPurple']).to.eql(5);
|
||||||
|
expect(recipient.purchased.plan.customerId).to.eql('Gift');
|
||||||
|
expect(recipient.purchased.plan.dateTerminated).to.exist;
|
||||||
|
expect(recipient.purchased.plan.dateUpdated).to.exist;
|
||||||
|
expect(recipient.purchased.plan.dateCreated).to.exist;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds extraMonths to existing subscription for recipient and creates a gift subscription for purchaser without sub', async () => {
|
||||||
|
recipient.purchased.plan = plan;
|
||||||
|
|
||||||
|
expect(recipient.purchased.plan.extraMonths).to.eql(0);
|
||||||
|
|
||||||
|
await api.createSubscription(data);
|
||||||
|
|
||||||
|
expect(recipient.purchased.plan.extraMonths).to.eql(3);
|
||||||
|
|
||||||
|
expect(user.items.pets['Jackalope-RoyalPurple']).to.eql(5);
|
||||||
|
expect(user.purchased.plan.customerId).to.eql('Gift');
|
||||||
|
expect(user.purchased.plan.dateTerminated).to.exist;
|
||||||
|
expect(user.purchased.plan.dateUpdated).to.exist;
|
||||||
|
expect(user.purchased.plan.dateCreated).to.exist;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds extraMonths to existing subscriptions for purchaser and recipient', async () => {
|
||||||
|
user.purchased.plan = plan;
|
||||||
|
recipient.purchased.plan = plan;
|
||||||
|
|
||||||
|
expect(user.purchased.plan.extraMonths).to.eql(0);
|
||||||
|
expect(recipient.purchased.plan.extraMonths).to.eql(0);
|
||||||
|
|
||||||
|
await api.createSubscription(data);
|
||||||
|
|
||||||
|
expect(user.purchased.plan.extraMonths).to.eql(3);
|
||||||
|
expect(recipient.purchased.plan.extraMonths).to.eql(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sends a private message about the promotion', async () => {
|
||||||
|
await api.createSubscription(data);
|
||||||
|
let msg = '\`Hello sender, you received 3 months of subscription as part of our holiday gift-giving promotion!\`';
|
||||||
|
|
||||||
|
expect(user.sendMessage).to.be.calledTwice;
|
||||||
|
expect(user.sendMessage).to.be.calledWith(user, { senderMsg: msg });
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('Purchasing a subscription for self', () => {
|
context('Purchasing a subscription for self', () => {
|
||||||
|
|||||||
@@ -31,11 +31,17 @@ b-modal#send-gems(:title="title", :hide-footer="true", size='lg')
|
|||||||
)
|
)
|
||||||
h3.panel-heading {{ $t('subscription') }}
|
h3.panel-heading {{ $t('subscription') }}
|
||||||
.panel-body
|
.panel-body
|
||||||
.form-group
|
.row
|
||||||
.radio(v-for='block in subscriptionBlocks', v-if="block.target !== 'group' && block.canSubscribe === true")
|
.col-md-4
|
||||||
label
|
.form-group
|
||||||
input(type="radio", name="subRadio", :value="block.key", v-model='gift.subscription.key')
|
.radio(v-for='block in subscriptionBlocks', v-if="block.target !== 'group' && block.canSubscribe === true")
|
||||||
| {{ $t('sendGiftSubscription', {price: block.price, months: block.months}) }}
|
label
|
||||||
|
input(type="radio", name="subRadio", :value="block.key", v-model='gift.subscription.key')
|
||||||
|
| {{ $t('sendGiftSubscription', {price: block.price, months: block.months}) }}
|
||||||
|
.col-md-8
|
||||||
|
h4 {{ $t('winterPromoGiftHeader') }}
|
||||||
|
p {{ $t('winterPromoGiftDetails1') }}
|
||||||
|
p {{ $t('winterPromoGiftDetails2') }}
|
||||||
|
|
||||||
textarea.form-control(rows='3', v-model='gift.message', :placeholder="$t('sendGiftMessagePlaceholder')")
|
textarea.form-control(rows='3', v-model='gift.message', :placeholder="$t('sendGiftMessagePlaceholder')")
|
||||||
//include ../formatting-help
|
//include ../formatting-help
|
||||||
|
|||||||
@@ -90,6 +90,11 @@
|
|||||||
li {{ $t('giftSubscriptionText2') }}
|
li {{ $t('giftSubscriptionText2') }}
|
||||||
li {{ $t('giftSubscriptionText3') }}
|
li {{ $t('giftSubscriptionText3') }}
|
||||||
h4 {{ $t('giftSubscriptionText4') }}
|
h4 {{ $t('giftSubscriptionText4') }}
|
||||||
|
.col-6
|
||||||
|
h2 {{ $t('winterPromoGiftHeader') }}
|
||||||
|
p {{ $t('winterPromoGiftDetails1') }}
|
||||||
|
p {{ $t('winterPromoGiftDetails2') }}
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -120,5 +120,8 @@
|
|||||||
"dateEndAugust": "August 31",
|
"dateEndAugust": "August 31",
|
||||||
"dateEndOctober": "October 31",
|
"dateEndOctober": "October 31",
|
||||||
"dateEndNovember": "November 30",
|
"dateEndNovember": "November 30",
|
||||||
"discountBundle": "bundle"
|
"discountBundle": "bundle",
|
||||||
|
"winterPromoGiftHeader": "GIFT A SUBSCRIPTION AND GET ONE FREE!",
|
||||||
|
"winterPromoGiftDetails1": "Until January 12th only, when you gift somebody a subscription, you get the same subscription for yourself for free!",
|
||||||
|
"winterPromoGiftDetails2": "Please note that if you or your gift recipient already have a recurring subscription, the gifted subscription will only start after that subscription is cancelled or has expired. Thanks so much for your support! <3"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@
|
|||||||
"APIToken": "API Token (this is a password - see warning above!)",
|
"APIToken": "API Token (this is a password - see warning above!)",
|
||||||
"showAPIToken": "Show API Token",
|
"showAPIToken": "Show API Token",
|
||||||
"hideAPIToken": "Hide API Token",
|
"hideAPIToken": "Hide API Token",
|
||||||
"APITokenWarning": "If you need a new API Token (e.g., if you accidentally shared it), email <%= hrefTechAssistanceEmail %> with your User ID and current Token. Once it is reset you will need to re-authorize everything by logging out of the website and mobile app and by providing the new Token to any other Habitica tools that you use.",
|
"APITokenWarning": "If you need a new API Token (e.g., if you accidentally shared it), email <%= hrefTechAssistanceEmail %> with your User ID and current Token. Once it is reset you will need to re-authorize everything by logging out of the website and mobile app and by providing the new Token to any other Habitica tools that you use.",
|
||||||
"thirdPartyApps": "Third Party Apps",
|
"thirdPartyApps": "Third Party Apps",
|
||||||
"dataToolDesc": "A webpage that shows you certain information from your Habitica account, such as statistics about your tasks, equipment, and skills.",
|
"dataToolDesc": "A webpage that shows you certain information from your Habitica account, such as statistics about your tasks, equipment, and skills.",
|
||||||
"beeminder": "Beeminder",
|
"beeminder": "Beeminder",
|
||||||
@@ -118,6 +118,7 @@
|
|||||||
"giftedSubscription": "Gifted Subscription",
|
"giftedSubscription": "Gifted Subscription",
|
||||||
"giftedSubscriptionInfo": "<%= name %> gifted you a <%= months %> month subscription",
|
"giftedSubscriptionInfo": "<%= name %> gifted you a <%= months %> month subscription",
|
||||||
"giftedSubscriptionFull": "Hello <%= username %>, <%= sender %> has sent you <%= monthCount %> months of subscription!",
|
"giftedSubscriptionFull": "Hello <%= username %>, <%= sender %> has sent you <%= monthCount %> months of subscription!",
|
||||||
|
"giftedSubscriptionWinterPromo": "Hello <%= username %>, you received <%= monthCount %> months of subscription as part of our holiday gift-giving promotion!",
|
||||||
"invitedParty": "Invited To Party",
|
"invitedParty": "Invited To Party",
|
||||||
"invitedGuild": "Invited To Guild",
|
"invitedGuild": "Invited To Guild",
|
||||||
"importantAnnouncements": "Reminders to check in to complete tasks and receive prizes",
|
"importantAnnouncements": "Reminders to check in to complete tasks and receive prizes",
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
@@ -363,47 +363,59 @@ api.createSubscription = async function createSubscription (data) {
|
|||||||
txnEmail(data.user, emailType);
|
txnEmail(data.user, emailType);
|
||||||
}
|
}
|
||||||
|
|
||||||
analytics.trackPurchase({
|
if (!data.promo) {
|
||||||
uuid: data.user._id,
|
analytics.trackPurchase({
|
||||||
groupId,
|
uuid: data.user._id,
|
||||||
itemPurchased,
|
groupId,
|
||||||
sku: `${data.paymentMethod.toLowerCase()}-subscription`,
|
itemPurchased,
|
||||||
purchaseType,
|
sku: `${data.paymentMethod.toLowerCase()}-subscription`,
|
||||||
paymentMethod: data.paymentMethod,
|
purchaseType,
|
||||||
quantity: 1,
|
paymentMethod: data.paymentMethod,
|
||||||
gift: Boolean(data.gift),
|
quantity: 1,
|
||||||
purchaseValue: block.price,
|
gift: Boolean(data.gift),
|
||||||
headers: data.headers,
|
purchaseValue: block.price,
|
||||||
});
|
headers: data.headers,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!group) data.user.purchased.txnCount++;
|
if (!group && !data.promo) data.user.purchased.txnCount++;
|
||||||
|
|
||||||
if (data.gift) {
|
if (data.gift) {
|
||||||
let byUserName = getUserInfo(data.user, ['name']).name;
|
let byUserName = getUserInfo(data.user, ['name']).name;
|
||||||
|
|
||||||
// generate the message in both languages, so both users can understand it
|
// generate the message in both languages, so both users can understand it
|
||||||
let languages = [data.user.preferences.language, data.gift.member.preferences.language];
|
let languages = [data.user.preferences.language, data.gift.member.preferences.language];
|
||||||
let senderMsg = shared.i18n.t('giftedSubscriptionFull', {
|
if (data.promo) {
|
||||||
username: data.gift.member.profile.name,
|
let senderMsg = shared.i18n.t(`giftedSubscription${data.promo}Promo`, {
|
||||||
sender: byUserName,
|
username: data.gift.member.profile.name,
|
||||||
monthCount: shared.content.subscriptionBlocks[data.gift.subscription.key].months,
|
monthCount: shared.content.subscriptionBlocks[data.gift.subscription.key].months,
|
||||||
}, languages[0]);
|
}, languages[0]);
|
||||||
senderMsg = `\`${senderMsg}\``;
|
|
||||||
|
|
||||||
let receiverMsg = shared.i18n.t('giftedSubscriptionFull', {
|
senderMsg = `\`${senderMsg}\``;
|
||||||
username: data.gift.member.profile.name,
|
data.user.sendMessage(data.gift.member, { senderMsg });
|
||||||
sender: byUserName,
|
} else {
|
||||||
monthCount: shared.content.subscriptionBlocks[data.gift.subscription.key].months,
|
let senderMsg = shared.i18n.t('giftedSubscriptionFull', {
|
||||||
}, languages[1]);
|
username: data.gift.member.profile.name,
|
||||||
receiverMsg = `\`${receiverMsg}\``;
|
sender: byUserName,
|
||||||
|
monthCount: shared.content.subscriptionBlocks[data.gift.subscription.key].months,
|
||||||
|
}, languages[0]);
|
||||||
|
senderMsg = `\`${senderMsg}\``;
|
||||||
|
|
||||||
if (data.gift.message) {
|
let receiverMsg = shared.i18n.t('giftedSubscriptionFull', {
|
||||||
receiverMsg += ` ${data.gift.message}`;
|
username: data.gift.member.profile.name,
|
||||||
senderMsg += ` ${data.gift.message}`;
|
sender: byUserName,
|
||||||
|
monthCount: shared.content.subscriptionBlocks[data.gift.subscription.key].months,
|
||||||
|
}, languages[1]);
|
||||||
|
receiverMsg = `\`${receiverMsg}\``;
|
||||||
|
|
||||||
|
if (data.gift.message) {
|
||||||
|
receiverMsg += ` ${data.gift.message}`;
|
||||||
|
senderMsg += ` ${data.gift.message}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.user.sendMessage(data.gift.member, { receiverMsg, senderMsg });
|
||||||
}
|
}
|
||||||
|
|
||||||
data.user.sendMessage(data.gift.member, { receiverMsg, senderMsg });
|
|
||||||
|
|
||||||
if (data.gift.member.preferences.emailNotifications.giftedSubscription !== false) {
|
if (data.gift.member.preferences.emailNotifications.giftedSubscription !== false) {
|
||||||
txnEmail(data.gift.member, 'gifted-subscription', [
|
txnEmail(data.gift.member, 'gifted-subscription', [
|
||||||
{name: 'GIFTER', content: byUserName},
|
{name: 'GIFTER', content: byUserName},
|
||||||
@@ -411,7 +423,12 @@ api.createSubscription = async function createSubscription (data) {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.gift.member._id !== data.user._id) { // Only send push notifications if sending to a user other than yourself
|
if (data.gift.member._id !== data.user._id) { // If sending to a user other than yourself, don't push notify, and get bonus sub for self per holiday promo
|
||||||
|
let promoData = data;
|
||||||
|
promoData.gift.member = data.user;
|
||||||
|
promoData.promo = 'Winter';
|
||||||
|
await this.createSubscription(promoData);
|
||||||
|
|
||||||
if (data.gift.member.preferences.pushNotifications.giftedSubscription !== false) {
|
if (data.gift.member.preferences.pushNotifications.giftedSubscription !== false) {
|
||||||
sendPushNotification(data.gift.member,
|
sendPushNotification(data.gift.member,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ function sendSubscriptionNotification ({
|
|||||||
let text;
|
let text;
|
||||||
let timestamp = new Date();
|
let timestamp = new Date();
|
||||||
if (recipient.id) {
|
if (recipient.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}`;
|
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}`;
|
||||||
} else if (groupId) {
|
} else if (groupId) {
|
||||||
text = `${buyer.name} ${buyer.id} ${buyer.email} bought a 1-month recurring group-plan for ${groupId} using ${paymentMethod} on ${timestamp}`;
|
text = `${buyer.name} ${buyer.id} ${buyer.email} bought a 1-month recurring group-plan for ${groupId} using ${paymentMethod} on ${timestamp}`;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user