cancel
Showing results for 
Search instead for 
Did you mean: 

The element transactionRequest has invalid child element lineItems

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?

1 ACCEPTED SOLUTION

Accepted Solutions

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);

 

View solution in original post

5 REPLIES 5

Is it the "[ ]" (braces).  I think it only curly braces an lineitems and brace lineItem? i mainly use XML.

kabutotx
Regular Contributor

Yep. See getTransactionDetailsResponse example in the API Reference.

lineItem will be the array with brace.

kabutotx
Regular Contributor

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?

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);

 

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!