From 9e0fa81f5537227f5b90099a4c4a077c7119e7f3 Mon Sep 17 00:00:00 2001 From: Mohamed Termoul Date: Fri, 17 May 2019 11:26:39 -0400 Subject: [PATCH] Article.md last edits --- article/article.md | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/article/article.md b/article/article.md index 13d8bfc..b4f87c6 100644 --- a/article/article.md +++ b/article/article.md @@ -302,11 +302,13 @@ As most marketers have come to realize, the cost of acquiring any quality traffi For the purpose of this app, I will add two `style.css` files and once the user visits the site I will be randomly selecting one stylesheet. The stylesheet selection will affect how the color theme will look like. So basically the user can see either version A of the site or version B. ``` -# server.js +// server.js app.get('/', async function(req, res) { ... - const pageVeriant = Math.floor(Math.random() * 2); - res.locals.pageB = (pageVeriant === 1 ? true : false); + if (req.session.pageVariant === undefined) { + req.session.pageVariant = Math.floor(Math.random() * 2); + } + res.locals.pageB = (req.session.pageVariant === 1 ? true : false); res.render('home'); }); ``` @@ -316,9 +318,9 @@ Then we load either style A or B on the `main.handlebars` file like this: ``` ... {{#if pageB }} - + {{else }} - + {{/if}} ... ``` @@ -332,13 +334,18 @@ We also have a javascript variable that will be used during the payment process then we save the page source along the stripe charge on the server post method. ``` -stripe.charges.create({ - amount: Number(req.body.amount) * 100, // amount in cents - currency: 'usd', - description: `${req.body.firstName} ${req.body.lastName} (${req.body.email}) - ${req.body.orderSummary} - Source: ${req.body.pageSource}`, - source: req.body.stripeToken, - statement_descriptor: 'CROWD-PITHC GOOG CASHM' -}) +// server.js +... +app.post('/pay', function(req, res) { + stripe.charges.create({ + amount: Number(req.body.amount) * 100, // amount in cents + currency: 'usd', + description: `${req.body.firstName} ${req.body.lastName} (${req.body.email}) - ${req.body.orderSummary} - Source: ${req.body.pageSource}`, + source: req.body.stripeToken, + statement_descriptor: 'CROWD-PITHC GOOG CASHM' + }) + ... +}); ``` ## Conclusion