forked from mrvautin/expressCart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mark Moffat
authored and
Mark Moffat
committed
Jan 1, 2020
1 parent
f2e6b32
commit eafb690
Showing
12 changed files
with
170 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"orderStatus": "Pending", | ||
"buttonText": "Place order, pay instore", | ||
"resultMessage": "The order is place. Please pay for your order instore on pickup." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"properties": { | ||
"orderStatus": { | ||
"type": "string", | ||
"enum": ["Completed", "Paid", "Pending"] | ||
}, | ||
"buttonText": { | ||
"type": "string" | ||
}, | ||
"resultMessage": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"orderStatus", | ||
"buttonText", | ||
"resultMessage" | ||
], | ||
"additionalProperties": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,7 @@ | |
"stripe", | ||
"authorise.net", | ||
"adyen", | ||
"instore", | ||
"lunr", | ||
"cart", | ||
"shopping" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const express = require('express'); | ||
const common = require('../../lib/common'); | ||
const { indexOrders } = require('../../lib/indexing'); | ||
const router = express.Router(); | ||
|
||
// The homepage of the site | ||
router.post('/checkout_action', async (req, res, next) => { | ||
const db = req.app.db; | ||
const config = req.app.config; | ||
const instoreConfig = common.getPaymentConfig(); | ||
|
||
const orderDoc = { | ||
orderPaymentId: common.getId(), | ||
orderPaymentGateway: 'Instore', | ||
orderPaymentMessage: 'Your payment was successfully completed', | ||
orderTotal: req.session.totalCartAmount, | ||
orderItemCount: req.session.totalCartItems, | ||
orderProductCount: req.session.totalCartProducts, | ||
orderEmail: req.session.customerEmail, | ||
orderFirstname: req.session.customerFirstname, | ||
orderLastname: req.session.customerLastname, | ||
orderAddr1: req.session.customerAddress1, | ||
orderAddr2: req.session.customerAddress2, | ||
orderCountry: req.session.customerCountry, | ||
orderState: req.session.customerState, | ||
orderPostcode: req.session.customerPostcode, | ||
orderPhoneNumber: req.session.customerPhone, | ||
orderComment: req.session.orderComment, | ||
orderStatus: instoreConfig.orderStatus, | ||
orderDate: new Date(), | ||
orderProducts: req.session.cart | ||
}; | ||
|
||
// insert order into DB | ||
try{ | ||
const newDoc = await db.orders.insertOne(orderDoc); | ||
|
||
// get the new ID | ||
const newId = newDoc.insertedId; | ||
|
||
// add to lunr index | ||
indexOrders(req.app) | ||
.then(() => { | ||
// set the results | ||
req.session.messageType = 'success'; | ||
req.session.message = 'Your order was successfully placed. Payment for your order will be completed instore.'; | ||
req.session.paymentEmailAddr = newDoc.ops[0].orderEmail; | ||
req.session.paymentApproved = true; | ||
req.session.paymentDetails = `<p><strong>Order ID: </strong>${newId}</p> | ||
<p><strong>Transaction ID: </strong>${orderDoc.orderPaymentId}</p>`; | ||
|
||
// set payment results for email | ||
const paymentResults = { | ||
message: req.session.message, | ||
messageType: req.session.messageType, | ||
paymentEmailAddr: req.session.paymentEmailAddr, | ||
paymentApproved: true, | ||
paymentDetails: req.session.paymentDetails | ||
}; | ||
|
||
// clear the cart | ||
if(req.session.cart){ | ||
req.session.cart = null; | ||
req.session.orderId = null; | ||
req.session.totalCartAmount = 0; | ||
} | ||
|
||
// send the email with the response | ||
// TODO: Should fix this to properly handle result | ||
common.sendEmail(req.session.paymentEmailAddr, `Your order with ${config.cartTitle}`, common.getEmailTemplate(paymentResults)); | ||
|
||
// redirect to outcome | ||
res.redirect('/payment/' + newId); | ||
}); | ||
}catch(ex){ | ||
console.log('Error sending payment to API', ex); | ||
res.status(400).json({ err: 'Your order declined. Please try again' }); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="instore_button col-sm-12 text-center"> | ||
<button id="checkout_instore" class="btn btn-outline-success" type="submit">{{@root.paymentConfig.buttonText}}</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="col-md-10 offset-md-1 col-sm-12 top-pad-50"> | ||
<div class="row"> | ||
<div class="text-center col-md-10 offset-md-1"> | ||
{{#paymentMessage result.orderStatus}}{{/paymentMessage}} | ||
<div> | ||
<p><strong>{{ @root.__ "Order ID" }}:</strong> {{result._id}}</p> | ||
<p><strong>{{ @root.__ "Payment ID" }}:</strong> {{result.orderPaymentId}}</p> | ||
</div> | ||
{{#paymentOutcome result.orderStatus}}{{/paymentOutcome}} | ||
<a href="/" class="btn btn-outline-warning">Home</a> | ||
</div> | ||
</div> | ||
</div> |
This file was deleted.
Oops, something went wrong.