This repository has been archived on 2026-03-21. You can view files and clone it, but cannot push or open issues or pull requests.
payfrit-biz/api/orders/abandonOrder.cfm
John 16a3b7c9a3 Replace queryExecute with queryTimed across all endpoints for perf tracking
Converts 200+ endpoint files to use queryTimed() wrapper which tracks
DB query count and execution time. Restores perf dashboard files that
were accidentally moved to _scripts/. Includes portal UI updates.
2026-02-02 00:28:37 -08:00

77 lines
2.3 KiB
Text

<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cffunction name="readJsonBody" access="public" returntype="struct" output="false">
<cfset var raw = getHttpRequestData().content>
<cfif isNull(raw) OR len(trim(raw)) EQ 0>
<cfreturn {}>
</cfif>
<cftry>
<cfset var data = deserializeJSON(raw)>
<cfif isStruct(data)>
<cfreturn data>
<cfelse>
<cfreturn {}>
</cfif>
<cfcatch>
<cfreturn {}>
</cfcatch>
</cftry>
</cffunction>
<cffunction name="apiAbort" access="public" returntype="void" output="true">
<cfargument name="payload" type="struct" required="true">
<cfcontent type="application/json; charset=utf-8">
<cfoutput>#serializeJSON(arguments.payload)#</cfoutput>
<cfabort>
</cffunction>
<cfset data = readJsonBody()>
<cfset OrderID = val(structKeyExists(data, "OrderID") ? data.OrderID : 0)>
<cfif OrderID LTE 0>
<cfset apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "OrderID is required.", "DETAIL": "" })>
</cfif>
<cftry>
<!--- Verify order exists and is in cart status (0) --->
<cfset qOrder = queryTimed(
"SELECT ID, StatusID FROM Orders WHERE ID = ? LIMIT 1",
[{ value = OrderID, cfsqltype = "cf_sql_integer" }],
{ datasource = "payfrit" }
)>
<cfif qOrder.recordCount EQ 0>
<cfset apiAbort({ "OK": false, "ERROR": "not_found", "MESSAGE": "Order not found.", "DETAIL": "" })>
</cfif>
<cfif qOrder.StatusID NEQ 0>
<cfset apiAbort({ "OK": false, "ERROR": "invalid_status", "MESSAGE": "Only cart orders can be abandoned.", "DETAIL": "" })>
</cfif>
<!--- Delete line items --->
<cfset queryTimed(
"DELETE FROM OrderLineItems WHERE OrderID = ?",
[{ value = OrderID, cfsqltype = "cf_sql_integer" }],
{ datasource = "payfrit" }
)>
<!--- Mark order with status 7 (Deleted and started new cart) --->
<cfset queryTimed(
"UPDATE Orders SET StatusID = 7, LastEditedOn = NOW() WHERE ID = ?",
[{ value = OrderID, cfsqltype = "cf_sql_integer" }],
{ datasource = "payfrit" }
)>
<cfset apiAbort({ "OK": true, "MESSAGE": "Order abandoned successfully." })>
<cfcatch>
<cfset apiAbort({
"OK": false,
"ERROR": "server_error",
"MESSAGE": "Failed to abandon order: " & cfcatch.message,
"DETAIL": cfcatch.message
})>
</cfcatch>
</cftry>