This is the JSON that I send:
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "test",
"transactionKey": "test"
},
"refId": "0000",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "100.00",
"payment": {
"opaqueData": {
"dataDescriptor": "COMMON.ACCEPT.INAPP.PAYMENT",
"dataValue": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}
},
"lineItems": [
{
"lineItem": {
"itemId": "item1",
"name": "item1",
"description": "item1",
"quantity": "1",
"unitPrice": "10"
}
},
{
"lineItem": {
"itemId": "item2",
"name": "item2",
"description": "item2",
"quantity": "1",
"unitPrice": "10"
}
},
{
"lineItem": {
"itemId": "item3",
"name": "item3",
"description": "item3",
"quantity": "1",
"unitPrice": "10"
}
},
{
"lineItem": {
"itemId": "item4",
"name": "item4",
"description": "item4",
"quantity": "1",
"unitPrice": "10"
}
}, {
"lineItem": {
"itemId": "item5",
"name": "item5",
"description": "item5",
"quantity": "1",
"unitPrice": "10"
}
}
],
"userFields": {
"userField": [
{
"name": "custom_data_1",
"value": "1"
}, {
"name": "custom_data_2",
"value": "2"
}
]
}
}
}
}Can someone explain what's wrong?
Solved! Go to Solution.
11-17-2020 12:40 PM
Maybe this example will help?
var obj = {};
obj.lineItems = {};
obj.lineItems.lineItem = [ {itemId: "1", name: "one"}, {itemId: "2",name: "two"}, {itemId: "3",name: "three"} ];
var myJSON = JSON.stringify(obj);
11-18-2020 03:57 PM - edited 11-18-2020 04:07 PM
Is it the "[ ]" (braces). I think it only curly braces an lineitems and brace lineItem? i mainly use XML.
11-17-2020 08:15 PM - edited 11-17-2020 08:24 PM
Yep. See getTransactionDetailsResponse example in the API Reference.
lineItem will be the array with brace.
11-17-2020 09:02 PM
Thank you for your answer,
You are right and I need to change the square brackets,
The issue now is how do I do it using javascript,
I have multiple inputs related to the lineitems and the "JSON.stringify" generate it automatically,
Is there another way to do it?
11-17-2020 10:52 PM
Maybe this example will help?
var obj = {};
obj.lineItems = {};
obj.lineItems.lineItem = [ {itemId: "1", name: "one"}, {itemId: "2",name: "two"}, {itemId: "3",name: "three"} ];
var myJSON = JSON.stringify(obj);
11-18-2020 03:57 PM - edited 11-18-2020 04:07 PM
I had to change it a little bit but it actually works,
I'm suprised, it seems that they want the wanted like this (with lineItem for each set):
"lineItems": {
{
"lineItem": {
"itemId": "item1",
"name": "item1",
"description": "item1",
"quantity": "1",
"unitPrice": "10"
}
},
{
"lineItem": {
"itemId": "item2",
"name": "item2",
"description": "item2",
"quantity": "1",
"unitPrice": "10"
}
}
},While yours generate this:
"lineItems": {
"lineItem": [
{
"itemId": "1",
"name": "one",
"description": "desc1",
"quantity": "1",
"unitPrice": "11.00"
},
{
"itemId": "2",
"name": "two",
"description": "desc2",
"quantity": "1",
"unitPrice": "12.00"
},
{
"itemId": "3",
"name": "three",
"description": "desc3",
"quantity": "1",
"unitPrice": "13.00"
}
]
},
This is what I changed:
var lineItems = {};
lineItems.lineItem = [ {itemId: "1", name: "one", description: "desc1", quantity: "1", unitPrice: "11.00"}, {itemId: "2",name: "two", description: "desc2", quantity: "1", unitPrice: "12.00"}, {itemId: "3",name: "three", description: "desc3", quantity: "1", unitPrice: "13.00"} ];
var myJSON = JSON.stringify(lineItems);Thank you!
11-18-2020 05:12 PM - edited 11-18-2020 05:12 PM