Backend services: - targo-hub: extract deepGetValue to helpers.js, DRY disconnect reasons lookup map, compact CAPABILITIES, consolidate vision.js prompts/schemas, extract dispatch scoring weights, trim section dividers across 9 files - modem-bridge: extract getSession() helper (6 occurrences), resetIdleTimer(), consolidate DM query factory, fix duplicate username fill bug, trim headers (server.js -36%, tplink-session.js -47%, docker-compose.yml -57%) Frontend: - useWifiDiagnostic: extract THRESHOLDS const, split processDiagnostic into 6 focused helpers (processOnlineStatus, processWanIPs, processRadios, processMeshNodes, processClients, checkRadioIssues) - EquipmentDetail: merge duplicate ROLE_LABELS, remove verbose comments Documentation (17 → 13 files, -1,400 lines): - New consolidated README.md (architecture, services, dependencies, auth) - Merge ECOSYSTEM-OVERVIEW into ARCHITECTURE.md - Merge MIGRATION-PLAN + ARCHITECTURE-COMPARE + FIELD-GAP + CHANGELOG → MIGRATION.md - Merge COMPETITIVE-ANALYSIS into PLATFORM-STRATEGY.md - Update ROADMAP.md with current phase status - Delete CONTEXT.md (absorbed into README) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
50 lines
1.8 KiB
JavaScript
50 lines
1.8 KiB
JavaScript
/**
|
|
* Payment API — talks to targo-hub /payments/* endpoints
|
|
*/
|
|
const HUB = location.hostname === 'localhost' ? 'http://localhost:3300' : 'https://msg.gigafibre.ca'
|
|
|
|
async function hubGet (path) {
|
|
const r = await fetch(HUB + path)
|
|
if (!r.ok) {
|
|
const data = await r.json().catch(() => ({}))
|
|
throw new Error(data.error || `Hub ${r.status}`)
|
|
}
|
|
return r.json()
|
|
}
|
|
|
|
async function hubPost (path, body) {
|
|
const r = await fetch(HUB + path, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(body),
|
|
})
|
|
const data = await r.json().catch(() => ({}))
|
|
if (!r.ok) throw new Error(data.error || `Hub ${r.status}`)
|
|
return data
|
|
}
|
|
|
|
/** Get customer balance + unpaid invoices */
|
|
export const getBalance = (customer) => hubGet(`/payments/balance/${encodeURIComponent(customer)}`)
|
|
|
|
/** Get saved payment methods for customer */
|
|
export const getPaymentMethods = (customer) => hubGet(`/payments/methods/${encodeURIComponent(customer)}`)
|
|
|
|
/** Get invoice payment info */
|
|
export const getInvoicePaymentInfo = (invoice) => hubGet(`/payments/invoice/${encodeURIComponent(invoice)}`)
|
|
|
|
/** Create checkout session for full balance */
|
|
export const checkoutBalance = (customer) => hubPost('/payments/checkout', { customer })
|
|
|
|
/** Create checkout session for specific invoice */
|
|
export const checkoutInvoice = (customer, invoice, { save_card = true, payment_method = 'card' } = {}) =>
|
|
hubPost('/payments/checkout-invoice', { customer, invoice, save_card, payment_method })
|
|
|
|
/** Save card (setup mode) */
|
|
export const setupCard = (customer) => hubPost('/payments/setup', { customer })
|
|
|
|
/** Open Stripe billing portal */
|
|
export const openBillingPortal = (customer) => hubPost('/payments/portal', { customer })
|
|
|
|
/** Toggle auto-pay (PPA) */
|
|
export const togglePPA = (customer, enabled) => hubPost('/payments/toggle-ppa', { customer, enabled })
|