payfrit-works/api/stripe/status.cfm
John Mizerek 0765dc1e27 Add business portal, Stripe Connect, beacon APIs, and task system
Portal:
- New business portal UI (portal/index.html, portal.css, portal.js)
- Dashboard with real-time stats (orders today, revenue, pending, menu items)
- Business info endpoint (api/businesses/get.cfm)
- Portal stats endpoint (api/portal/stats.cfm)
- Menu page links to existing full-featured menu editor

Stripe Connect:
- Onboarding endpoint (api/stripe/onboard.cfm)
- Status check endpoint (api/stripe/status.cfm)
- Payment intent creation (api/stripe/createPaymentIntent.cfm)
- Webhook handler (api/stripe/webhook.cfm)

Beacon APIs:
- List all beacons (api/beacons/list_all.cfm)
- Get business from beacon (api/beacons/getBusinessFromBeacon.cfm)

Task System:
- List pending tasks (api/tasks/listPending.cfm)
- Accept task (api/tasks/accept.cfm)

Other:
- HUD interface for quick order status display
- KDS debug/test pages
- Updated Application.cfm with public endpoint allowlist
- Order status check improvements

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 23:38:26 -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 BusinessStripeAccountID, BusinessStripeOnboardingComplete
FROM Businesses
WHERE BusinessID = :businessID
", { businessID: businessID });
if (qBusiness.recordCount == 0) {
response["ERROR"] = "Business not found";
writeOutput(serializeJSON(response));
abort;
}
stripeAccountID = qBusiness.BusinessStripeAccountID;
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.BusinessStripeOnboardingComplete) {
queryExecute("
UPDATE Businesses
SET BusinessStripeOnboardingComplete = 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.BusinessStripeOnboardingComplete == 1;
response["ACCOUNT_STATUS"] = qBusiness.BusinessStripeOnboardingComplete == 1 ? "active" : "unknown";
response["STRIPE_ACCOUNT_ID"] = stripeAccountID;
}
} catch (any e) {
response["ERROR"] = e.message;
}
writeOutput(serializeJSON(response));
</cfscript>