Issue
I am getting a response from authorize.net payment gateway and tried many times and many ways to parse it but no luck.
Here is the main response from authorize.net:
"{"transactionResponse":{"responseCode":"1","authCode":"XXXXXX","avsResultCode":"Y","cvvResultCode":"P","cavvResultCode":"2","transId":"11111111111","refTransID":"","transHash":"","testRequest":"0","accountNumber":"XXXX0002","accountType":"AmericanExpress","messages":[{"code":"1","description":"This transaction has been approved."}],"transHashSha2":"2E6533BDC93C975EE3C1134B7421A337D5B8FB9C257437DB8B4XXXX4BCD92024B33704B811C69E58527359CA8628E8E33E55AA68B881E6F3D15B5F2FEAEB490B","SupplementalDataQualificationIndicator":0,"networkTransId":"HLH5UGDQFZ98LHRLDGIZEG7"},"messages":{"resultCode":"Ok","message":[{"code":"I00001","text":"Successful."}]}}"
I am following this tutorial.
I have tried this:
const result = JSON.parse(JSON.stringify(res.response));
console.log('1', result);
And result is:
1 {"transactionResponse":{"responseCode":"1","authCode":"9UQISS","avsResultCode":"Y","cvvResultCode":"P","cavvResultCode":"2","transId":"60164579108","refTransID":"","transHash":"","testRequest":"0","accountNumber":"XXXX0002","accountType":"AmericanExpress","messages":[{"code":"1","description":"This transaction has been approved."}],"transHashSha2":"2E6533BDC93C975EE3C1134B7421A337D5B8FB9C257437DB8B4DA924BCD92024B33704B811C69E58527359CA8628E8E33E55AA68B881E6F3D15B5F2FEAEB490B","SupplementalDataQualificationIndicator":0,"networkTransId":"HLH5UGDQFZ98LHRLDGIZEG7"},"messages":{"resultCode":"Ok","message":[{"code":"I00001","text":"Successful."}]}}
I want result like this:
{
"transactionResponse": {
"responseCode": "1",
"authCode": "XXXXXX",
"avsResultCode": "Y",
"cvvResultCode": "P",
"cavvResultCode": "2",
"transId": "11111111111",
"refTransID": "",
"transHash": "",
"testRequest": "0",
"accountNumber": "XXXX0002",
"accountType": "AmericanExpress",
"messages": [
{
"code": "1",
"description": "This transaction has been approved."
}
],
"transHashSha2": "2E6533BDC93C975EE3C1134B7421A337D5B8FB9C257437DB8B4XXXX4BCD92024B33704B811C69E58527359CA8628E8E33E55AA68B881E6F3D15B5F2FEAEB490B",
"SupplementalDataQualificationIndicator": 0,
"networkTransId": "HLH5UGDQFZ98LHRLDGIZEG7"
},
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
}
}
Please guide me...
Solution
This is the Answer to my question:
I am getting this data in res.response:
"{"transactionResponse":{"responseCode":"1","authCode":"XXXXXX","avsResultCode":"Y","cvvResultCode":"P","cavvResultCode":"2","transId":"11111111111","refTransID":"","transHash":"","testRequest":"0","accountNumber":"XXXX0002","accountType":"AmericanExpress","messages":[{"code":"1","description":"This transaction has been approved."}],"transHashSha2":"2E6533BDC93C975EE3C1134B7421A337D5B8FB9C257437DB8B4XXXX4BCD92024B33704B811C69E58527359CA8628E8E33E55AA68B881E6F3D15B5F2FEAEB490B","SupplementalDataQualificationIndicator":0,"networkTransId":"HLH5UGDQFZ98LHRLDGIZEG7"},"messages":{"resultCode":"Ok","message":[{"code":"I00001","text":"Successful."}]}}"
console.log('API', res);
var obj = eval("(" + res.response + ")");
console.log(obj);
I solve the problem so I thought I should have to post answers it may be helpful to others.
Answered By - user9088454
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.