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/stripe/status.cfm
John Mizerek 1210249f54 Normalize database column and table names across entire codebase
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>
2026-01-30 15:39:12 -08:00

109 lines
3.6 KiB
Text

<cfscript>
/**
* Check Stripe Connect Status
* Returns the current status of a business's Stripe account
*
* POST: { BusinessID: int }
* Returns: { OK: true, CONNECTED: bool, ACCOUNT_STATUS: string, ... }
*/
response = { "OK": false };
try {
requestData = deserializeJSON(toString(getHttpRequestData().content));
businessID = val(requestData.BusinessID ?: 0);
if (businessID == 0) {
response["ERROR"] = "BusinessID is required";
writeOutput(serializeJSON(response));
abort;
}
stripeSecretKey = application.stripeSecretKey ?: "";
// Get business Stripe info
qBusiness = queryExecute("
SELECT StripeAccountID, StripeOnboardingComplete
FROM Businesses
WHERE ID = :businessID
", { businessID: businessID });
if (qBusiness.recordCount == 0) {
response["ERROR"] = "Business not found";
writeOutput(serializeJSON(response));
abort;
}
stripeAccountID = qBusiness.StripeAccountID;
if (stripeAccountID == "" || isNull(stripeAccountID)) {
response["OK"] = true;
response["CONNECTED"] = false;
response["ACCOUNT_STATUS"] = "not_started";
writeOutput(serializeJSON(response));
abort;
}
// Retrieve account from Stripe to check status
if (stripeSecretKey != "") {
httpService = new http();
httpService.setMethod("GET");
httpService.setUrl("https://api.stripe.com/v1/accounts/#stripeAccountID#");
httpService.setUsername(stripeSecretKey);
httpService.setPassword("");
result = httpService.send().getPrefix();
accountData = deserializeJSON(result.fileContent);
if (structKeyExists(accountData, "error")) {
response["OK"] = true;
response["CONNECTED"] = false;
response["ACCOUNT_STATUS"] = "error";
response["ERROR_DETAIL"] = accountData.error.message;
writeOutput(serializeJSON(response));
abort;
}
// Check if onboarding is complete
chargesEnabled = accountData.charges_enabled ?: false;
payoutsEnabled = accountData.payouts_enabled ?: false;
detailsSubmitted = accountData.details_submitted ?: false;
if (chargesEnabled && payoutsEnabled) {
accountStatus = "active";
// Mark as complete in database if not already
if (!qBusiness.StripeOnboardingComplete) {
queryExecute("
UPDATE Businesses
SET StripeOnboardingComplete = 1
WHERE BusinessID = :businessID
", { businessID: businessID });
}
} else if (detailsSubmitted) {
accountStatus = "pending_verification";
} else {
accountStatus = "incomplete";
}
response["OK"] = true;
response["CONNECTED"] = chargesEnabled && payoutsEnabled;
response["ACCOUNT_STATUS"] = accountStatus;
response["STRIPE_ACCOUNT_ID"] = stripeAccountID;
response["CHARGES_ENABLED"] = chargesEnabled;
response["PAYOUTS_ENABLED"] = payoutsEnabled;
response["DETAILS_SUBMITTED"] = detailsSubmitted;
} else {
// No Stripe key, just return what we have in DB
response["OK"] = true;
response["CONNECTED"] = qBusiness.StripeOnboardingComplete == 1;
response["ACCOUNT_STATUS"] = qBusiness.StripeOnboardingComplete == 1 ? "active" : "unknown";
response["STRIPE_ACCOUNT_ID"] = stripeAccountID;
}
} catch (any e) {
response["ERROR"] = e.message;
}
writeOutput(serializeJSON(response));
</cfscript>