fix(ancpi): use JSON body for EpayJsonInterceptor + EditCartItemJson
Root cause from ePay Angular analysis:
- EpayJsonInterceptor needs Content-Type: application/json + {"judet": N}
- EditCartItemJson needs JSON with bigDecimalValue/stringValue structure
- SearchEstate needs basketId in body for JSON response
- Queue skips SearchEstate (data already from eTerra), uses
configureCartItem → submitOrder flow directly
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -77,50 +77,43 @@ export async function GET(req: Request) {
|
||||
}
|
||||
|
||||
// ── Step: search ──
|
||||
// Test EditCartItemJson.action — the real endpoint for configuring cart items
|
||||
// Test UAT lookup (JSON) + SearchEstate (with basketId)
|
||||
if (step === "search") {
|
||||
const client = await EpayClient.create(username, password);
|
||||
const BASE = process.env.ANCPI_BASE_URL || "https://epay.ancpi.ro/epay";
|
||||
const countyIdx = resolveEpayCountyIndex("Cluj")!;
|
||||
const results: Record<string, unknown> = { countyIdx };
|
||||
|
||||
// Add to cart
|
||||
// 1. Get UAT list (JSON body now)
|
||||
const uatList = await client.getUatList(countyIdx);
|
||||
results["uatCount"] = uatList.length;
|
||||
results["uatFirst5"] = uatList.slice(0, 5);
|
||||
|
||||
// Find our test UATs
|
||||
const normalize = (s: string) =>
|
||||
s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toUpperCase();
|
||||
const clujNapoca = uatList.find((u) => normalize(u.value).includes("CLUJ-NAPOCA") || normalize(u.value).includes("CLUJNAPOCA"));
|
||||
const feleacu = uatList.find((u) => normalize(u.value).includes("FELEACU"));
|
||||
const floresti = uatList.find((u) => normalize(u.value).includes("FLORESTI"));
|
||||
results["uatMatches"] = { clujNapoca, feleacu, floresti };
|
||||
|
||||
// 2. Add to cart + SearchEstate with basketId
|
||||
const basketRowId = await client.addToCart(14200);
|
||||
results["basketRowId"] = basketRowId;
|
||||
|
||||
const results: Record<string, unknown> = { basketRowId };
|
||||
|
||||
// Test 1: Set county via EditCartItemJson to get UAT list
|
||||
try {
|
||||
const body1 = new URLSearchParams();
|
||||
body1.set("basketId", String(basketRowId));
|
||||
body1.set("metadate.judet", "13"); // CLUJ
|
||||
|
||||
const resp1 = await client.postRaw(
|
||||
`${BASE}/EditCartItemJson.action`,
|
||||
body1.toString(),
|
||||
);
|
||||
results["setCounty_type"] = typeof resp1;
|
||||
results["setCounty_len"] = typeof resp1 === "string" ? resp1.length : JSON.stringify(resp1).length;
|
||||
results["setCounty_sample"] = (typeof resp1 === "string" ? resp1 : JSON.stringify(resp1)).slice(0, 1000);
|
||||
} catch (e) {
|
||||
results["setCounty_error"] = (e as Error).message;
|
||||
if (clujNapoca) {
|
||||
results["search_345295"] = await client
|
||||
.searchEstate("345295", countyIdx, clujNapoca.id, basketRowId)
|
||||
.catch((e: Error) => ({ error: e.message }));
|
||||
}
|
||||
|
||||
// Test 2: Try SearchEstate via the Angular way (maybe it's inside EditCartItemJson)
|
||||
try {
|
||||
const body2 = new URLSearchParams();
|
||||
body2.set("basketId", String(basketRowId));
|
||||
body2.set("identifier", "345295");
|
||||
body2.set("countyId", "13");
|
||||
|
||||
const resp2 = await client.postRaw(
|
||||
`${BASE}/SearchEstate.action`,
|
||||
body2.toString(),
|
||||
{ "X-Requested-With": "XMLHttpRequest", Accept: "application/json" },
|
||||
);
|
||||
results["searchAjax_type"] = typeof resp2;
|
||||
results["searchAjax_len"] = typeof resp2 === "string" ? resp2.length : JSON.stringify(resp2).length;
|
||||
results["searchAjax_sample"] = (typeof resp2 === "string" ? resp2 : JSON.stringify(resp2)).slice(0, 1000);
|
||||
} catch (e) {
|
||||
results["searchAjax_error"] = (e as Error).message;
|
||||
if (feleacu) {
|
||||
results["search_63565"] = await client
|
||||
.searchEstate("63565", countyIdx, feleacu.id, basketRowId)
|
||||
.catch((e: Error) => ({ error: e.message }));
|
||||
}
|
||||
if (floresti) {
|
||||
results["search_88089"] = await client
|
||||
.searchEstate("88089", countyIdx, floresti.id, basketRowId)
|
||||
.catch((e: Error) => ({ error: e.message }));
|
||||
}
|
||||
|
||||
return NextResponse.json({ step: "search", results });
|
||||
@@ -128,7 +121,6 @@ export async function GET(req: Request) {
|
||||
|
||||
// ── Step: order ── (USES 3 CREDITS!)
|
||||
if (step === "order") {
|
||||
// Ensure session exists
|
||||
if (!getEpayCredentials()) {
|
||||
createEpaySession(username, password, 0);
|
||||
}
|
||||
@@ -158,6 +150,7 @@ export async function GET(req: Request) {
|
||||
if (!clujNapoca || !feleacu || !floresti) {
|
||||
return NextResponse.json({
|
||||
error: "Nu s-au găsit UAT-urile.",
|
||||
uatCount: uatList.length,
|
||||
clujNapoca, feleacu, floresti,
|
||||
});
|
||||
}
|
||||
@@ -168,21 +161,21 @@ export async function GET(req: Request) {
|
||||
judetIndex: countyIdx,
|
||||
judetName: "CLUJ",
|
||||
uatId: clujNapoca.id,
|
||||
uatName: "Cluj-Napoca",
|
||||
uatName: clujNapoca.value,
|
||||
},
|
||||
{
|
||||
nrCadastral: "63565",
|
||||
judetIndex: countyIdx,
|
||||
judetName: "CLUJ",
|
||||
uatId: feleacu.id,
|
||||
uatName: "Feleacu",
|
||||
uatName: feleacu.value,
|
||||
},
|
||||
{
|
||||
nrCadastral: "88089",
|
||||
judetIndex: countyIdx,
|
||||
judetName: "CLUJ",
|
||||
uatId: floresti.id,
|
||||
uatName: "Florești",
|
||||
uatName: floresti.value,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -195,11 +188,12 @@ export async function GET(req: Request) {
|
||||
return NextResponse.json({
|
||||
step: "order",
|
||||
credits,
|
||||
message: `Enqueued ${ids.length} orders. Queue processing started.`,
|
||||
message: `Enqueued ${ids.length} orders. Processing sequentially...`,
|
||||
orderIds: ids,
|
||||
parcels: parcels.map((p, i) => ({
|
||||
nrCadastral: p.nrCadastral,
|
||||
uatName: p.uatName,
|
||||
uatId: p.uatId,
|
||||
extractId: ids[i],
|
||||
})),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user