diff --git a/routes/payments/authorizenet.js b/routes/payments/authorizenet.js
index 7f96275..e231bed 100644
--- a/routes/payments/authorizenet.js
+++ b/routes/payments/authorizenet.js
@@ -36,7 +36,7 @@ router.post('/checkout_action', (req, res, next) => {
};
axios.post(authorizeUrl, chargeJson, { responseType: 'text' })
- .then((response) => {
+ .then(async(response) => {
// This is crazy but the Authorize.net API returns a string with BOM and totally
// screws the JSON response being parsed. So many hours wasted!
const txn = JSON.parse(stripBom(response.data)).transactionResponse;
@@ -76,10 +76,8 @@ router.post('/checkout_action', (req, res, next) => {
};
// insert order into DB
- db.orders.insertOne(orderDoc, (err, newDoc) => {
- if(err){
- console.info(err.stack);
- }
+ try{
+ const newDoc = await db.orders.insertOne(orderDoc);
// get the new ID
const newId = newDoc.insertedId;
@@ -129,7 +127,10 @@ router.post('/checkout_action', (req, res, next) => {
res.status(400).json({ err: true, orderId: newId });
}
});
- });
+ }catch(ex){
+ console.log('Error sending payment to API', ex);
+ res.status(400).json({ err: 'Your payment has declined. Please try again' });
+ }
})
.catch((err) => {
console.log('Error sending payment to API', err);
diff --git a/views/partials/payments/authorizenet.hbs b/views/partials/payments/authorizenet.hbs
index 3e06e6d..fb19c60 100644
--- a/views/partials/payments/authorizenet.hbs
+++ b/views/partials/payments/authorizenet.hbs
@@ -1,14 +1,11 @@
-{{#ifCond paymentConfig.mode '==' 'test'}}
{{else}}
-
-{{/ifCond}}