diff --git a/app/controllers/grant.controller.js b/app/controllers/grant.controller.js index d84b3a5..9d7241d 100644 --- a/app/controllers/grant.controller.js +++ b/app/controllers/grant.controller.js @@ -6,6 +6,7 @@ const sendgrid = require('./sendgrid.controller'); const { Grant, + Donor, Charge, Cause, Region, @@ -82,11 +83,24 @@ exports.createGrant = async (req, res, next) => { { transaction } ); + const donors = await sequelize.query( + ` + SELECT email, first_name, last_name + FROM donors + WHERE id = :donor_id + `, + { + type: db.Sequelize.QueryTypes.SELECT, + replacements: { donor_id: user.id } + } + ); + // send email await sendgrid.paymentReceipt({ + grant, organizations, total_amount: actual_total, - receiver: user.email + receiver: donors[0] }); // commit diff --git a/app/controllers/sendgrid.controller.js b/app/controllers/sendgrid.controller.js index 3ee07eb..f76274c 100644 --- a/app/controllers/sendgrid.controller.js +++ b/app/controllers/sendgrid.controller.js @@ -6,7 +6,12 @@ sgMail.setApiKey(process.env.SENDGRID_KEY); const {} = db; -exports.paymentReceipt = async ({ organizations, total_amount, receiver }) => { +exports.paymentReceipt = async ({ + grant, + organizations, + total_amount, + receiver +}) => { try { var charitiesHtml = ''; @@ -22,17 +27,18 @@ exports.paymentReceipt = async ({ organizations, total_amount, receiver }) => { }); const msg = { - to: receiver, + to: receiver.email, from: { email: 'no-reply@charify.com', name: 'Charify Payments' }, template_id: 'd-569f804f5e7749cba66bac1994607280', substitutionWrappers: ['{{', '}}'], dynamic_template_data: { - donor_name: 'Arjun Patel', + donor_name: receiver.first_name, + bundle_id: grant.id, charities_list: charitiesHtml, total_amount, - date: 'April 1st, 2018', - subject: 'Your Charity Bundle Payment - Charify' + date: grant.created_at, + subject: 'Your Charify Bundle Payment - Charify' } }; const sentRes = await sgMail.send(msg);