cancel
Showing results for 
Search instead for 
Did you mean: 

JSON issues

Great to see JSON being implemented! There are some issues though.

 

1.

With the JSON response a BOM UTF-8 character is included. BOM on UTF-8 makes no sense. This should not be there as it will confuse most JSON parses. You will have lots of feedback from people who can't understand why they cannot parse the JSON - and they won't know why because it's usually not apparent that the BOM is the issue, the parser just says "sorry, can't do it" with no further meaningful error message. References: http://en.wikipedia.org/wiki/Byte_order_mark and http://stackoverflow.com/questions/14532149/bom-in-server-response-screws-up-json-parsing

 

As a temporary fix for PHP using this service right now the following code will remove the BOM character and should be run before you run it through json_decode(): $response = preg_replace('/\xEF\xBB\xBF/', '', $response);

 

2.

How do you specify multiple settings in the request? Logically it should be defined like this:

 

{
    "createTransactionRequest": {
        "merchantAuthentication": {
            "name": "xxxxxx",
            "transactionKey": "xxxxxx"
        },
        "refId": "123456",
        "transactionRequest": {
            "transactionType": "authCaptureTransaction",
            "amount": "5",
            "payment": {
                "creditCard": {
                    "cardNumber": "5424000000000015",
                    "expirationDate": "1220",
                    "cardCode": "999"
                }
            },
            "lineItems": {
                "lineItem": {
                    "itemId": "1",
                    "name": "vase",
                    "description": "Cannes logo",
                    "quantity": "18",
                    "unitPrice": "45.00"
                }
            },
            "tax": {
                "amount": "4.26",
                "name": "level2 tax name",
                "description": "level2 tax"
            },
            "duty": {
                "amount": "8.55",
                "name": "duty name",
                "description": "duty description"
            },
            "shipping": {
                "amount": "4.26",
                "name": "level2 tax name",
                "description": "level2 tax"
            },
            "poNumber": "456654",
            "customer": {
                "id": "99999456654"
            },
            "billTo": {
                "firstName": "Ellen",
                "lastName": "Johnson",
                "company": "Souveniropolis",
                "address": "14 Main Street",
                "city": "Pecan Springs",
                "state": "TX",
                "zip": "44628",
                "country": "USA"
            },
            "shipTo": {
                "firstName": "China",
                "lastName": "Bayles",
                "company": "Thyme for Tea",
                "address": "12 Main Street",
                "city": "Pecan Springs",
                "state": "TX",
                "zip": "44628",
                "country": "USA"
            },
            "customerIP": "192.168.1.1",
            "transactionSettings": [
				{
					"setting": {
						"settingName": "duplicateWindow",
						"settingValue": "240"
					}
				},
				{
					"setting": {
						"settingName": "merchantEmail",
						"settingValue": "my@email.com"
					}
				}
            ]
        }
    }
}

 

 But this will produce the following truly misleading error message:

 

{
    "messages": {
        "resultCode": "Error",
        "message": [
            {
                "code": "E00003",
                "text": "The element 'transactionRequest' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'transactionSettings' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'userFields' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'."
            }
        ]
    }
}

The error message makes the programmer focus on element transactionSettings within transactionRequest - instead of the real issue deeper down.

As soon as you remove one of the settings from the array the error disappears.

 

The same issue applies to "lineItems".

 

3.

Also, the correct way to set a single setting is wrapping it in an array like this:

"transactionSettings": [
	{
		"setting": {
			"settingName": "merchantEmail",
			"settingValue": "allan@sharehim.org"
		}
	}
]

 The way the online API reference does it without the array is not the proper way to do it since you end up with different types of structures depending on whether you have one or multiple settings - and that's not smart. Both ways seem to work for a single setting though.

winternet
Contributor
11 REPLIES 11

This might help some of you who are trying to parse out the bom in php:

https://stackoverflow.com/questions/10290849/how-to-remove-multiple-utf-8-bom-sequences

jasonjudge
Contributor