Payment Providers - one provider's window: Add (no id, or from * payment_provider_add.php) or Edit. Its keys - the secret one never put back * into the page, so left empty it stays - whether it is on, the account its * payments go into, the card limit, whether its fees are recorded as * expenses, and whether clients pay a card fee to cover them. Save asks first (check_payment_provider, * admin/post/payment_provider.php): what is wrong shows beside each field and * the window stays open; once all is right, it saves. */ require_once '../../includes/modal_header.php'; $provider_id = intval($_GET['id'] ?? 0); $row = $provider_id ? paymentProviderRow($provider_id) : null; if ($provider_id && !$row) { echo json_encode(['error' => 'That payment provider no longer exists.']); exit; } $kinds = paymentProviderKinds(); $taken = []; $sql = mysqli_query($mysqli, "SELECT payment_provider_name FROM payment_providers"); while ($taken_row = mysqli_fetch_row($sql)) { $taken[$taken_row[0]] = true; } $free_kinds = array_diff_key($kinds, $taken); $name = $row ? (string) $row['payment_provider_name'] : (string) (array_key_first($free_kinds) ?? array_key_first($kinds)); $kind = $kinds[$name] ?? reset($kinds); $mode = $row ? paymentProviderMode($row['payment_provider_private_key']) : ''; $account_id = intval($row['payment_provider_account'] ?? 0); $vendor_id = intval($row['payment_provider_expense_vendor'] ?? 0); $category_id = intval($row['payment_provider_expense_category'] ?? 0); $threshold = round(floatval($row['payment_provider_threshold'] ?? 0), 2); $records_fees = $row ? ($vendor_id > 0 && $category_id > 0) : true; $card_fee = intval($row['payment_provider_card_fee'] ?? 0) === 1; $card_fee_percent = round(floatval($row['payment_provider_card_fee_percent'] ?? 0), 2); $card_fee_fixed = round(floatval($row['payment_provider_card_fee_fixed'] ?? 0), 2); // A new one starts on an account and a vendor named for it, and Processing Fee, where there are those if (!$row) { $starts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT (SELECT account_id FROM accounts WHERE account_name = '" . escapeSql($name) . "' AND account_archived_at IS NULL LIMIT 1), (SELECT vendor_id FROM vendors WHERE vendor_name = '" . escapeSql($name) . "' AND vendor_client_id = 0 AND vendor_archived_at IS NULL LIMIT 1), (SELECT category_id FROM categories WHERE category_type = 'Expense' AND category_name = 'Processing Fee' AND category_archived_at IS NULL LIMIT 1)")); $account_id = intval($starts[0] ?? 0); $vendor_id = intval($starts[1] ?? 0); $category_id = intval($starts[2] ?? 0); } $accounts = mysqli_query($mysqli, "SELECT account_id, account_name, account_archived_at FROM accounts WHERE account_archived_at IS NULL OR account_id = $account_id ORDER BY account_name ASC"); $vendors = mysqli_query($mysqli, "SELECT vendor_id, vendor_name, vendor_archived_at FROM vendors WHERE vendor_client_id = 0 AND (vendor_archived_at IS NULL OR vendor_id = $vendor_id) ORDER BY vendor_name ASC"); $currency = (string) ($session_company_currency ?? ''); // Where what is wrong with a field shows $error_for = function ($field) { return '
'; }; ob_start(); ?>