WIP 1.51.11: money on v2 via v1 handlers (viaV1 adapter)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
This commit is contained in:
2026-10-29 13:43:36 +02:00
co-authored by Claude Opus 5.5
parent a45417948d
commit 6ee1438e23
36 changed files with 10334 additions and 154 deletions
@@ -3,7 +3,7 @@
import React, { Suspense, useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useAuth } from "@/hooks/useAuth";
import { useRouter, useSearchParams } from "next/navigation";
import { apiFetch, fetchAllUsers, fetchAllPayments, fetchManagedEvents, fetchAllRegistrations } from "@/lib/api";
import { fetchAllUsers, fetchAllPayments, fetchManagedEvents, fetchAllRegistrations } from "@/lib/api";
import { useDismissingState } from "@/hooks/useDismissingState";
import { scoreUser } from "@/lib/fuzzyMatch";
import { Wallet, RotateCcw, HandHeart, ScanLine, Link2 } from "lucide-react";
@@ -14,6 +14,7 @@ import { BackLink } from "@/components/shared/BackLink";
import { useOnlinePayments } from "@/lib/onlinePayments";
import { WaitingForPayment } from "@/components/payments/WaitingForPayment";
import { EventPicker } from "@/components/shared/EventPicker";
import { apiV2Data } from "@/lib/apiV2";
// A donation is never mutated once created — assigning it to a registration creates a separate
// "leg" Payment row (isDonation:false, originalPaymentId -> the donation, amount > 0) instead.
@@ -193,7 +194,7 @@ function PaymentsContent() {
setLoadingList(true);
const start = new Date(); start.setHours(0, 0, 0, 0);
const [recent, today, donations] = await Promise.all([
apiFetch<{ data: Payment[] }>("/api/payments?page=1&limit=40", { authToken: token }),
(apiV2Data("get", "/payments", { query: { page: "1", limit: "40" }, authToken: token }) as Promise<{ data: Payment[] }>),
fetchAllPayments(token, { from: start.toISOString() }),
fetchAllPayments(token, { donations: "1" }),
]);
@@ -301,17 +302,16 @@ function PaymentsContent() {
if (!amt || amt <= 0) { setError("Enter a valid amount"); return; }
try {
setLinkGenerating(true);
const res = await apiFetch<{ redirectUrl?: string; checkoutId?: string; amount?: number; priceUpdated?: boolean; message?: string }>("/api/payments/checkout", {
method: "POST",
const res = await (apiV2Data("post", "/registrations/{id}/payment-link", {
params: { id: linkRegistrationId },
authToken: token,
body: {
registrationId: linkRegistrationId,
amount: amt,
successUrl: window.location.origin + "/payment/success",
cancelUrl: window.location.origin + "/payment/cancel",
failureUrl: window.location.origin + "/payment/failure",
},
});
}) as Promise<{ redirectUrl?: string; checkoutId?: string; amount?: number; priceUpdated?: boolean; message?: string }>);
if (res.priceUpdated) {
setError(res.message || "Pricing has changed for this registration; please re-check the amount.");
return;
@@ -342,10 +342,10 @@ function PaymentsContent() {
setError(null); setInfo(null);
try {
setLinkSending(channel);
await apiFetch("/api/payments/checkout/send", {
method: "POST",
await apiV2Data("post", "/registrations/{id}/payment-link/send", {
params: { id: linkResult.registrationId },
authToken: token,
body: { registrationId: linkResult.registrationId, redirectUrl: linkResult.redirectUrl, channel },
body: { redirectUrl: linkResult.redirectUrl, channel },
});
setInfo(`Payment link sent via ${channel === "email" ? "email" : "WhatsApp"}`);
} catch (e) {
@@ -405,8 +405,7 @@ function PaymentsContent() {
}
try {
setSubmitting(true);
await apiFetch("/api/payments", {
method: "POST",
await apiV2Data("post", "/payments", {
authToken: token,
body: {
amount: amt,
@@ -416,7 +415,7 @@ function PaymentsContent() {
eventId: eventId || undefined,
isDonation: !!isDonation,
paidAt: paidAtLocal ? new Date(paidAtLocal).toISOString() : undefined,
}
},
});
setInfo(`Payment created (R ${amt.toFixed(2)})`);
setAmount(""); setRegistrationId(""); setIsDonation(false); setEventId(""); setPaidAtLocal("");
@@ -447,7 +446,7 @@ function PaymentsContent() {
if (!token) return;
try {
setTxLoading(true);
const res = await apiFetch<{ data?: ProviderTx[] } | ProviderTx[]>("/api/provider-transactions/unreconciled", { authToken: token });
const res = await (apiV2Data("get", "/provider-transactions/unreconciled", { authToken: token }) as Promise<{ data?: ProviderTx[] } | ProviderTx[]>);
const items = Array.isArray(res) ? res : (Array.isArray(res?.data) ? res.data : []);
setProviderTxs(items);
} catch {
@@ -486,18 +485,18 @@ function PaymentsContent() {
setReconcileForm(prev => ({ ...prev, submitting: true }));
if (type === 'reg') {
if (!registrationId) { setError('Please select a registration'); return; }
await apiFetch(`/api/provider-transactions/${encodeURIComponent(txId)}/reconcile`, {
method: 'POST',
await apiV2Data("post", "/provider-transactions/{id}/reconcile", {
params: { id: txId },
authToken: token,
body: { registrationId }
body: { registrationId },
});
setInfo('Reconciled to registration');
} else {
if (!eventId) { setError('Please select an event'); return; }
await apiFetch(`/api/provider-transactions/${encodeURIComponent(txId)}/reconcile`, {
method: 'POST',
await apiV2Data("post", "/provider-transactions/{id}/reconcile", {
params: { id: txId },
authToken: token,
body: { eventId, userId: userId || undefined }
body: { eventId, userId: userId || undefined },
});
setInfo('Reconciled as donation');
}
@@ -617,7 +616,7 @@ function PaymentsContent() {
const ok = window.confirm('Ignore this transaction? It will be marked as ignored and reconciled.');
if (!ok) return;
try {
await apiFetch(`/api/provider-transactions/${encodeURIComponent(tx.id)}/ignore`, { method: 'POST', authToken: token });
await apiV2Data("post", "/provider-transactions/{id}/ignore", { params: { id: tx.id }, authToken: token, body: {} });
setInfo('Transaction ignored');
await loadUnreconciled();
} catch (e) {
@@ -935,9 +934,8 @@ function RefundSection({ allUsers, onDone }: RefundSectionProps) {
if (!method) { setErr('Select a refund method'); return; }
try {
setSubmitting(true);
await apiFetch('/api/payments/refund', {
method: 'POST',
authToken: token!,
await apiV2Data("post", "/payments/refunds", {
authToken: token,
body: {
userId,
amount: amt,
@@ -945,7 +943,7 @@ function RefundSection({ allUsers, onDone }: RefundSectionProps) {
paymentId: target === 'payment' ? paymentId : undefined,
registrationId: target === 'registration' ? registrationId : undefined,
reason: reason || undefined
}
},
});
setUserId(""); setPaymentId(""); setRegistrationId(""); setAmount(""); setReason(""); setMethod("");
await onDone();
@@ -1083,10 +1081,9 @@ function AssignedDonationsList({ payments, onDone }: AssignedDonationsListProps)
if (!ok) return;
try {
setUnassigningId(leg.id);
await apiFetch('/api/payments/unassign-donation', {
method: 'POST',
await apiV2Data("post", "/payments/donations/unassign", {
authToken: token,
body: { legId: leg.id }
body: { legId: leg.id },
});
await onDone();
} catch (e) {
@@ -1266,8 +1263,7 @@ function DonationAssignSection({ payments, allUsers, registrations, regOutstandi
if (amountNum > maxAllocatable + 0.000001) { setErr(`Cannot allocate more than R ${maxAllocatable.toFixed(2)}`); return; }
try {
setAssigning(true);
await apiFetch('/api/payments/assign-donation', {
method: 'PUT',
await apiV2Data("post", "/payments/donations/assign", {
authToken: token,
body: { paymentId, registrationId, amount: amountNum }
});