Skip to content

Commit

Permalink
feat(VirtualCard): Send gift cards redeem link emails
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Dec 14, 2018
1 parent 4a69c40 commit 10596f1
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 81 deletions.
80 changes: 48 additions & 32 deletions scripts/compile-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ data['collective.expense.paid'] = {
viewLatestExpenses: 'https://opencollective.com/wwcodeaustin/expenses',
},
};
(data['user.card.claimed'] = {
data['user.card.claimed'] = {
currency: 'USD',
initialBalance: 10000,
expiryDate: new Date().setMonth(new Date().getMonth() + 3),
Expand All @@ -73,37 +73,53 @@ data['collective.expense.paid'] = {
'https://opencollective-production.s3-us-west-1.amazonaws.com/02f87560-b2f1-11e8-85a0-75f200a0e2db.png',
},
loginLink: 'https://opencollective.com/signin?next=',
}),
(data['ticket.confirmed'] = {
recipient: {
name: 'Xavier Damman',
},
event: {
name: 'Sustain 2019 San Francisco',
slug: 'sutain-2019-sf',
startsAt: '2019-06-19 17:15:00+00',
endsAt: '2019-06-19 21:15:00+00',
timezone: 'America/Los_Angeles',
locationName: 'Github HQ',
address: '88 Colin P Kelly Jr Street, San Francisco, CA',
},
collective: {
slug: 'sustainoss',
},
tier: {
id: 1,
name: 'Regular Ticket',
description: 'This gives you access to all the workshops',
amount: 1000,
currency: 'USD',
},
order: {
id: 2312321,
quantity: 2,
totalAmount: 5000,
currency: 'USD',
},
});
};
data['user.card.invited'] = {
currency: 'USD',
initialBalance: 10000,
expiryDate: new Date().setMonth(new Date().getMonth() + 3),
emitter: {
slug: 'triplebyte',
name: 'Triplebyte',
description:
'Triplebyte lets talented software engineers skip resumes recruiters and go straight to final interviews at multiple top tech companies at once.',
image: 'https://opencollective-production.s3-us-west-1.amazonaws.com/02f87560-b2f1-11e8-85a0-75f200a0e2db.png',
backgroundImage: 'https://d.pr/free/i/GEbbjb+',
previewImage:
'https://opencollective-production.s3-us-west-1.amazonaws.com/02f87560-b2f1-11e8-85a0-75f200a0e2db.png',
},
redeemCode: '00000000',
};
data['ticket.confirmed'] = {
recipient: {
name: 'Xavier Damman',
},
event: {
name: 'Sustain 2019 San Francisco',
slug: 'sutain-2019-sf',
startsAt: '2019-06-19 17:15:00+00',
endsAt: '2019-06-19 21:15:00+00',
timezone: 'America/Los_Angeles',
locationName: 'Github HQ',
address: '88 Colin P Kelly Jr Street, San Francisco, CA',
},
collective: {
slug: 'sustainoss',
},
tier: {
id: 1,
name: 'Regular Ticket',
description: 'This gives you access to all the workshops',
amount: 1000,
currency: 'USD',
},
order: {
id: 2312321,
quantity: 2,
totalAmount: 5000,
currency: 'USD',
},
};
data['ticket.confirmed.sustainoss'] = data['ticket.confirmed'];
data['ticket.confirmed.fearlesscitiesbrussels'] = data['ticket.confirmed'];
data['github.signup'] = {
Expand Down
2 changes: 1 addition & 1 deletion server/graphql/v1/mutations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { omit, times } from 'lodash';
import { omit } from 'lodash';
import {
claimCollective,
createCollective,
Expand Down
2 changes: 2 additions & 0 deletions server/lib/emailTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const templateNames = [
'thankyou.laprimaire',
'user.card.claimed',
'user.card.claimed.text',
'user.card.invited',
'user.card.invited.text',
'user.forgot.password',
'user.monthlyreport',
'user.monthlyreport.text',
Expand Down
28 changes: 26 additions & 2 deletions server/paymentProviders/opencollective/virtualcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import models, { Op, sequelize } from '../../models';
import * as libpayments from '../../lib/payments';
import * as currency from '../../lib/currency';
import { formatCurrency, isValidEmail } from '../../lib/utils';
import emailLib from '../../lib/email';

/**
* Virtual Card Payment method - This payment Method works basically as an alias
Expand Down Expand Up @@ -147,7 +148,7 @@ async function create(args, remoteUser) {
const sourcePaymentMethod = await getSourcePaymentMethodFromCreateArgs(args, collective);
const createParams = getCreateParams(args, collective, sourcePaymentMethod, remoteUser);
const virtualCard = await models.PaymentMethod.create(createParams);
// TODO send email
sendVirtualCardCreatedEmail(virtualCard, collective);
return virtualCard;
}

Expand Down Expand Up @@ -192,7 +193,7 @@ export async function createVirtualCardsForEmails(args, remoteUser, emails) {
getCreateParams({ ...args, data: { email } }, collective, sourcePaymentMethod, remoteUser),
);
const virtualCards = models.PaymentMethod.bulkCreate(virtualCardsParams);
// TODO send emails
virtualCards.map(vc => sendVirtualCardCreatedEmail(vc, collective));
return virtualCards;
}

Expand Down Expand Up @@ -302,6 +303,29 @@ function getCreateParams(args, collective, sourcePaymentMethod, remoteUser) {
};
}

/**
* Send an email with the virtual card redeem URL to the user.
*
* @param {object} virtualCard
*/
async function sendVirtualCardCreatedEmail(virtualCard, emitterCollective) {
const code = virtualCard.uuid.split('-')[0];
const email = get(virtualCard, 'data.email');

if (!email) {
return false;
}

return emailLib.send('user.card.invited', email, {
redeemCode: code,
initialBalance: virtualCard.initialBalance,
expiryDate: virtualCard.expiryDate,
name: virtualCard.name,
currency: virtualCard.currency,
emitter: emitterCollective,
});
}

/** Claim the Virtual Card Payment Method By an (existing or not) user
* @param {Object} args contains the parameters
* @param {String} args.code The 8 last digits of the UUID
Expand Down
27 changes: 27 additions & 0 deletions templates/emails/user.card.invited.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Subject: 🎁 {{emitter.name}} has granted you a {{{currency initialBalance currency=currency}}} gift card to donate on Open Collective!

{{> header}}

<table>
<tr>
<td>
<center>
<h1>{{#ifCond currency '===' 'USD'}}💵{{/ifCond}}{{#ifCond currency '===' 'EUR'}}💶{{/ifCond}}{{#ifCond currency '===' 'GBP'}}💷{{/ifCond}}</h1>
<p>
You're one step away to redeem the {{{currency initialBalance currency=currency}}} gift card
offered to you by <a href="{{config.host.website}}/{{emitter.slug}}">{{emitter.name}}</a>. Just
click on the button bellow and fill your info to redeem your gift card 🎁
</p>
<center>
<a href="{{config.host.website}}/redeem/{{redeemCode}}" class="btn blue"><div>Redeem</div></a>
</center>
</center>
</td>
<td></td>
<td valign="top">
{{> collectivecard emitter}}
</td>
</tr>
</table>

{{> footer}}
4 changes: 4 additions & 0 deletions templates/emails/user.card.invited.text.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
You're one step away to redeem the {{{currency initialBalance currency=currency}}} gift card
offered to you by {{emitter.name}}. Just click on the button bellow and fill your info to redeem your gift card 🎁

{{config.host.website}}/redeem/{{redeemCode}}
Loading

0 comments on commit 10596f1

Please sign in to comment.