Reputation: 1
I have integration with payment service, and he send me a curl like this
curl -d '{"merchantAccount":"pipedrive_youscore_rubicon_ltd","orderReference":"WFP-BTN-7181819-635e48482b33d","merchantSignature":"7bff82ec724b2a3ade7fe74e3b829f2c","amount":3,"currency":"UAH","authCode":"326470","email":"[email protected]","phone":"380669114250","createdDate":1667123272,"processingDate":1667123284,"cardPan":"44****6705","cardType":"Visa","issuerBankCountry":"Ukraine","issuerBankName":"MONObank","recToken":"","transactionStatus":"Approved","reason":"Ok","reasonCode":1100,"fee":0.07,"paymentSystem":"googlePay","acquirerBankName":"WayForPay","cardProduct":"credit","clientName":"Rubicon Sergii","products":[{"name":"\u0422\u0435\u0441\u0442\u043e\u0432\u0438\u0439 \u0442\u043e\u0432\u0430\u0440","price":3,"count":1}],"clientFields":[{"name":"\u0414\u043e\u043c\u0435\u043d \u043f\u043e\u0440\u0442\u0430\u043b\u0443","value":"rawgsag"}]}' http://app.rubicon.tips:3000/checkSupPay
Where content type 'application/x-www-form-urlencoded'
And on server i have next req.body
body: [Object: null prototype] {
"'{merchantAccount:pipedrive_youscore_rubicon_ltd,orderReference:WFP-BTN-7181819-635e48482b33d,merchantSignature:7bff82ec724b2a3ade7fe74e3b829f2c,amount:3,currency:UAH,authCode:326470,email:[email protected],phone:380669114250,createdDate:1667123272,processingDate:1667123284,cardPan:44****6705,cardType:Visa,issuerBankCountry:Ukraine,issuerBankName:MONObank,recToken:,transactionStatus:Approved,reason:Ok,reasonCode:1100,fee:0.07,paymentSystem:googlePay,acquirerBankName:WayForPay,cardProduct:credit,clientName:Rubicon Sergii,products:[{name:\\u0422\\u0435\\u0441\\u0442\\u043e\\u0432\\u0438\\u0439 \\u0442\\u043e\\u0432\\u0430\\u0440,price:3,count:1}],clientFields:[{name:\\u0414\\u043e\\u043c\\u0435\\u043d \\u043f\\u043e\\u0440\\u0442\\u0430\\u043b\\u0443,value:rawgsag}]}'": ''
},
I think this req.body
parsed like 'application/x-www-form-urlencoded'
but in body json object, how to parse it?
I trying parse with express.urlencoded({ extended: false })
express.urlencoded({ extended: false, type: 'application/json' })
and
express.json({ strict: false, type: 'application/x-www-form-urlencoded' })
with all options, but i cant parse it correctly
Upvotes: 0
Views: 632
Reputation: 103
var bodyParser = require('body-parser');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
// With body-parser configured, now create our route. We can grab POST
// parameters using req.body.variable_name
// POST http://localhost:8080/api/books
// parameters sent with
app.post('/api/books', function(req, res) {
var book_id = req.body.id;
var bookName = req.body.token;
//Send the response back
res.send(book_id + ' ' + bookName);
});
From https://stackoverflow.com/a/42129247/17278956
Upvotes: 0