fix(ancpi): GET CheckoutConfirmationSubmit after EditCartSubmit
EditCartSubmit returns 200 (not redirect) — Angular does client-side redirect to CheckoutConfirmationSubmit.action. Added this step to actually confirm the order before looking for the orderId. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -446,23 +446,39 @@ export class EpayClient {
|
|||||||
// No previous orders
|
// No previous orders
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Step 1: POST EditCartSubmit (Angular does this, gets 200 back)
|
||||||
const body = new URLSearchParams();
|
const body = new URLSearchParams();
|
||||||
body.set("goToCheckout", "true");
|
body.set("goToCheckout", "true");
|
||||||
|
|
||||||
const response = await this.client.post(
|
await this.client.post(
|
||||||
`${BASE_URL}/EditCartSubmit.action`,
|
`${BASE_URL}/EditCartSubmit.action`,
|
||||||
body.toString(),
|
body.toString(),
|
||||||
{
|
{
|
||||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||||
timeout: DEFAULT_TIMEOUT_MS,
|
timeout: DEFAULT_TIMEOUT_MS,
|
||||||
maxRedirects: 10,
|
|
||||||
validateStatus: () => true,
|
validateStatus: () => true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const finalUrl =
|
// Step 2: GET CheckoutConfirmationSubmit (Angular redirects here client-side)
|
||||||
response.request?.res?.responseUrl ?? response.config?.url ?? "";
|
const confirmResponse = await this.client.get(
|
||||||
console.log(`[epay] EditCartSubmit: finalUrl=${finalUrl.slice(0, 100)}`);
|
`${BASE_URL}/CheckoutConfirmationSubmit.action`,
|
||||||
|
{
|
||||||
|
timeout: DEFAULT_TIMEOUT_MS,
|
||||||
|
maxRedirects: 5,
|
||||||
|
validateStatus: () => true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const confirmHtml = String(confirmResponse.data ?? "");
|
||||||
|
const hasConfirmation =
|
||||||
|
confirmHtml.includes("mulțumim") ||
|
||||||
|
confirmHtml.includes("multumim") ||
|
||||||
|
confirmHtml.includes("confirmare");
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`[epay] Checkout confirmation: ${hasConfirmation ? "OK" : "uncertain"} (${confirmHtml.length} chars)`,
|
||||||
|
);
|
||||||
|
|
||||||
// Find the NEW orderId (different from previous + not in knownOrderIds)
|
// Find the NEW orderId (different from previous + not in knownOrderIds)
|
||||||
return this.findNewOrderId(previousOrderId, knownOrderIds);
|
return this.findNewOrderId(previousOrderId, knownOrderIds);
|
||||||
|
|||||||
Reference in New Issue
Block a user