Update all SQL queries, query result references, and ColdFusion code to match
the renamed database schema. Tables use plural CamelCase, PKs are all `ID`,
column prefixes stripped (e.g. BusinessName→Name, UserFirstName→FirstName).
Key changes:
- Strip table-name prefixes from all column references (Businesses, Users,
Addresses, Hours, Menus, Categories, Items, Stations, Orders,
OrderLineItems, Tasks, TaskCategories, TaskRatings, QuickTaskTemplates,
ScheduledTaskDefinitions, ChatMessages, Beacons, ServicePoints, Employees,
VisitorTrackings, ApiPerfLogs, tt_States, tt_Days, tt_AddressTypes,
tt_OrderTypes, tt_TaskTypes)
- Rename PK references from {TableName}ID to ID in all queries
- Rewrite 7 admin beacon files to use ServicePoints.BeaconID instead of
dropped lt_Beacon_Businesses_ServicePoints link table
- Rewrite beacon assignment files (list, save, delete) for new schema
- Fix FK references incorrectly changed to ID (OrderLineItems.OrderID,
Categories.MenuID, Tasks.CategoryID, ServicePoints.BeaconID)
- Update Addresses: AddressLat→Latitude, AddressLng→Longitude
- Update Users: UserPassword→Password, UserIsEmailVerified→IsEmailVerified,
UserIsActive→IsActive, UserBalance→Balance, etc.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
94 lines
2.8 KiB
Text
94 lines
2.8 KiB
Text
<cfsetting showdebugoutput="false">
|
|
<cfsetting enablecfoutputonly="true">
|
|
<cfcontent type="application/json; charset=utf-8" reset="true">
|
|
|
|
<cfscript>
|
|
/**
|
|
* Create or reuse Stripe Connect Express account for worker.
|
|
*/
|
|
|
|
response = { "OK": false };
|
|
|
|
try {
|
|
requestData = deserializeJSON(toString(getHttpRequestData().content));
|
|
userID = val(requestData.UserID ?: 0);
|
|
|
|
if (userID == 0 && structKeyExists(request, "UserID")) {
|
|
userID = val(request.UserID);
|
|
}
|
|
|
|
if (userID == 0) {
|
|
response["ERROR"] = "missing_params";
|
|
response["MESSAGE"] = "UserID is required.";
|
|
writeOutput(serializeJSON(response));
|
|
abort;
|
|
}
|
|
|
|
qUser = queryExecute("
|
|
SELECT StripeConnectedAccountID, EmailAddress, FirstName, LastName
|
|
FROM Users WHERE ID = :userID
|
|
", { userID: userID }, { datasource: "payfrit" });
|
|
|
|
if (qUser.recordCount == 0) {
|
|
response["ERROR"] = "user_not_found";
|
|
writeOutput(serializeJSON(response));
|
|
abort;
|
|
}
|
|
|
|
existingAccountID = qUser.StripeConnectedAccountID ?: "";
|
|
|
|
if (len(trim(existingAccountID)) > 0) {
|
|
// Already has an account
|
|
response["OK"] = true;
|
|
response["ACCOUNT_ID"] = existingAccountID;
|
|
response["CREATED"] = false;
|
|
writeOutput(serializeJSON(response));
|
|
abort;
|
|
}
|
|
|
|
// Create new Stripe Connect Express account
|
|
stripeSecretKey = application.stripeSecretKey ?: "";
|
|
|
|
httpService = new http();
|
|
httpService.setMethod("POST");
|
|
httpService.setUrl("https://api.stripe.com/v1/accounts");
|
|
httpService.setUsername(stripeSecretKey);
|
|
httpService.setPassword("");
|
|
|
|
httpService.addParam(type="formfield", name="type", value="express");
|
|
httpService.addParam(type="formfield", name="country", value="US");
|
|
|
|
userEmail = qUser.EmailAddress ?: "";
|
|
if (len(trim(userEmail)) > 0) {
|
|
httpService.addParam(type="formfield", name="email", value=userEmail);
|
|
}
|
|
|
|
httpService.addParam(type="formfield", name="capabilities[transfers][requested]", value="true");
|
|
httpService.addParam(type="formfield", name="metadata[user_id]", value=userID);
|
|
|
|
result = httpService.send().getPrefix();
|
|
acctData = deserializeJSON(result.fileContent);
|
|
|
|
if (structKeyExists(acctData, "error")) {
|
|
response["ERROR"] = acctData.error.message;
|
|
writeOutput(serializeJSON(response));
|
|
abort;
|
|
}
|
|
|
|
newAccountID = acctData.id;
|
|
|
|
// Save to Users table
|
|
queryExecute("
|
|
UPDATE Users SET StripeConnectedAccountID = :acctID WHERE ID = :userID
|
|
", { acctID: newAccountID, userID: userID }, { datasource: "payfrit" });
|
|
|
|
response["OK"] = true;
|
|
response["ACCOUNT_ID"] = newAccountID;
|
|
response["CREATED"] = true;
|
|
|
|
} catch (any e) {
|
|
response["ERROR"] = e.message;
|
|
}
|
|
|
|
writeOutput(serializeJSON(response));
|
|
</cfscript>
|