'Springfield Elementary', // required * 'amount' => '25.00', // required (string, major units) * 'currency' => 'CAD', // optional, default from onboarding/CAD * 'order_api_url' => '/square/order-api.php', // URL to order-api.php * 'success_url' => '/payment-success', // redirect after a successful charge (Phase 4) * 'buyer_email' => 'parent@school.com', // optional, for receipts (Phase 4) * ]; * require_once '/path/to/square/square-checkout-widget.php'; * * The widget resolves the school's Square connection server-side; if the school * is not connected / not ready, it renders a small muted notice and stops. */ if (!isset($sqCheckout) || !is_array($sqCheckout)) { throw new RuntimeException('$sqCheckout array must be set before including square-checkout-widget.php'); } require_once __DIR__ . '/lib/SquareClient.php'; require_once __DIR__ . '/lib/MerchantStore.php'; $_sqConfig = require __DIR__ . '/config.php'; $_sqSchool = (string)($sqCheckout['school_name'] ?? ''); $_sqAmount = (string)($sqCheckout['amount'] ?? ''); $_sqSchoolNum = (int)($sqCheckout['school_num'] ?? 0); // ── Resolve the school's Square connection server-side ──────────────────────── $_sqAppId = $_sqConfig['web_payments_app_id'] ?: $_sqConfig['client_id']; $_sqEnv = $_sqConfig['env'] ?? 'sandbox'; $_sqStore = new MerchantStore($_sqConfig); $_sqClient = new SquareClient($_sqConfig); $_sqMeta = $_sqSchoolNum > 0 ? $_sqStore->getMetaByNum($_sqSchoolNum) : ($_sqSchool !== '' ? $_sqStore->getMeta($_sqSchool) : []); $_sqMerchantId = $_sqMeta['merchant_id'] ?? null; $_sqLocationId = ($_sqSchool !== '' || $_sqSchoolNum > 0) ? $_sqStore->locationId($_sqSchool, $_sqClient, $_sqSchoolNum > 0 ? $_sqSchoolNum : null) : null; $_sqReady = !isset($_sqMeta['square_ready']) || (bool)$_sqMeta['square_ready']; $_sqRevoked = !empty($_sqMeta['authorization_revoked']); $_sqCurrency = strtoupper((string)($sqCheckout['currency'] ?? ($_sqMeta['currency'] ?? 'CAD'))); // Helper to render a muted, non-blocking notice and bail out. $_sqNotice = function (string $msg): void { echo '