Authorize.net fixes

master
Mark Moffat 2019-11-14 21:43:29 +10:30
parent 83a23d397d
commit 9e5074f7c7
2 changed files with 11 additions and 13 deletions

View File

@ -36,7 +36,7 @@ router.post('/checkout_action', (req, res, next) => {
}; };
axios.post(authorizeUrl, chargeJson, { responseType: 'text' }) 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 // 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! // screws the JSON response being parsed. So many hours wasted!
const txn = JSON.parse(stripBom(response.data)).transactionResponse; const txn = JSON.parse(stripBom(response.data)).transactionResponse;
@ -76,10 +76,8 @@ router.post('/checkout_action', (req, res, next) => {
}; };
// insert order into DB // insert order into DB
db.orders.insertOne(orderDoc, (err, newDoc) => { try{
if(err){ const newDoc = await db.orders.insertOne(orderDoc);
console.info(err.stack);
}
// get the new ID // get the new ID
const newId = newDoc.insertedId; const newId = newDoc.insertedId;
@ -129,7 +127,10 @@ router.post('/checkout_action', (req, res, next) => {
res.status(400).json({ err: true, orderId: newId }); 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) => { .catch((err) => {
console.log('Error sending payment to API', err); console.log('Error sending payment to API', err);

View File

@ -1,14 +1,11 @@
{{#ifCond paymentConfig.mode '==' 'test'}}
<script type="text/javascript" <script type="text/javascript"
{{#ifCond @root.paymentConfig.mode '==' 'test'}}
src="https://jstest.authorize.net/v3/AcceptUI.js" src="https://jstest.authorize.net/v3/AcceptUI.js"
charset="utf-8">
</script>
{{else}} {{else}}
<script type="text/javascript"
src="https://js.authorize.net/v3/AcceptUI.js" src="https://js.authorize.net/v3/AcceptUI.js"
{{/ifCond}}
charset="utf-8"> charset="utf-8">
</script> </script>
{{/ifCond}}
<script> <script>
function responseHandler(data){ function responseHandler(data){
// Set fields from the form // Set fields from the form
@ -51,8 +48,8 @@
<button type="button" <button type="button"
class="AcceptUI btn btn-success waves-effect waves-light blue darken-3" class="AcceptUI btn btn-success waves-effect waves-light blue darken-3"
data-billingAddressOptions='{"show":false, "required":false}' data-billingAddressOptions='{"show":false, "required":false}'
data-apiLoginID="{{paymentConfig.loginId}}" data-apiLoginID="{{@root.paymentConfig.loginId}}"
data-clientKey="{{paymentConfig.clientKey}}" data-clientKey="{{@root.paymentConfig.clientKey}}"
data-acceptUIFormBtnTxt="Submit" data-acceptUIFormBtnTxt="Submit"
data-acceptUIFormHeaderTxt="Card Information" data-acceptUIFormHeaderTxt="Card Information"
data-responseHandler="responseHandler">Process payment data-responseHandler="responseHandler">Process payment