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' })
.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);

View File

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