<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8">

<!--- List US states for address forms --->
<cfscript>
try {
    qStates = queryExecute("
        SELECT tt_StateID as StateID, tt_StateAbbreviation as StateAbbreviation, tt_StateName as StateName
        FROM tt_States
        ORDER BY tt_StateName
    ", {}, { datasource: "payfrit" });

    states = [];
    for (row in qStates) {
        arrayAppend(states, {
            "StateID": row.StateID,
            "Abbr": row.StateAbbreviation,
            "Name": row.StateName
        });
    }

    writeOutput(serializeJSON({
        "OK": true,
        "STATES": states
    }));

} catch (any e) {
    writeOutput(serializeJSON({
        "OK": false,
        "ERROR": "server_error",
        "MESSAGE": e.message
    }));
}
</cfscript>
