The element transactionRequest has invalid child element lineItems

239 Views Asked by At

I'm trying to send a payment request to Authorize.Net using Accept.js,
They require the "lineItems" to look like this:

"lineItems": {
    {
        "lineItem": {
            "itemId": "item1",
            "name": "item1",
            "description": "item1",
            "quantity": "1",
            "unitPrice": "10"
        }
    },
    {
        "lineItem": {
            "itemId": "item2",
            "name": "item2",
            "description": "item2",
            "quantity": "1",
            "unitPrice": "10"
        }
    }
},

The problem is that I have each lineitem set as an array,
And building the json from an array results a json with a squared brackets:

"lineItems": [
    {
        "lineItem": {
            "itemId": "item1",
            "name": "item1",
            "description": "item1",
            "quantity": "1",
            "unitPrice": "10"
        }
    },
    {
        "lineItem": {
            "itemId": "item2",
            "name": "item2",
            "description": "item2",
            "quantity": "1",
            "unitPrice": "10"
        }
    }
],

Which get the following error:

The element transactionRequest has invalid child element lineItems,

Any idea how to fix this?

1

There are 1 best solutions below

1
John Conde On

Change:

"lineItems": [
    {
        "lineItem": {
            "itemId": "item1",
            "name": "item1",
            "description": "item1",
            "quantity": "1",
            "unitPrice": "10"
        }
    },
    {
        "lineItem": {
            "itemId": "item2",
            "name": "item2",
            "description": "item2",
            "quantity": "1",
            "unitPrice": "10"
        }
    }
],

to:

"lineItems":
 {
    "lineItem": [
        {
            "itemId": "item1",
            "name": "item1",
            "description": "item1",
            "quantity": "1",
            "unitPrice": "10"
        },
        {
            "itemId": "item2",
            "name": "item2",
            "description": "item2",
            "quantity": "1",
            "unitPrice": "10"
        }
    ]
},