status check

This commit is contained in:
2026-05-05 11:53:52 +04:00
parent b4ad6da49e
commit 5eb7b2dcba
3 changed files with 25 additions and 6 deletions

View File

@@ -22,12 +22,12 @@ interface CreateQrResponse {
Payload?: string; // per API doc (capital P)
nspkurl?: string; // actual field name in real responses
qrUrl?: string;
qrStatus?: string;
status?: string; // e.g. "REGISTERED"
[key: string]: unknown;
}
interface QrStatusResponse {
status?: string; // "NEW" | "APPROVED" | "REJECTED" | "COMPLETED"
status?: string; // "REGISTERED" | "NEW" | "APPROVED" | "REJECTED" | "COMPLETED"
nspkurl?: string;
nspkID?: string;
[key: string]: unknown;
@@ -88,6 +88,7 @@ export class CreatePage {
// QR display state
qrImageUrl = signal<string | null>(null);
qrPolling = signal<boolean>(false);
qrStatus = signal<string>('');
private pollHandle: ReturnType<typeof setInterval> | null = null;
private activeQrId = '';
@@ -160,6 +161,7 @@ export class CreatePage {
const qrId = res?.qrId ?? res?.nspkID ?? '';
// Real API uses 'nspkurl'; doc says 'Payload' — try both
const nspkUrl = res?.nspkurl ?? res?.Payload;
this.qrStatus.set(res?.status ?? '');
if (qrId || nspkUrl) {
this.activeQrId = qrId;
const qrData = nspkUrl
@@ -186,19 +188,21 @@ export class CreatePage {
this.http.get<QrStatusResponse>(`${QR_VITANOVA_API}/qr/dynamic/${qrId}`)
.subscribe({
next: (res) => {
// API returns status: "NEW" | "APPROVED" | "REJECTED" | "COMPLETED"
if (res?.status === 'COMPLETED' || res?.status === 'APPROVED') {
const st = res?.status ?? '';
this.qrStatus.set(st);
if (st === 'COMPLETED' || st === 'APPROVED') {
this.stopPolling();
this.createFastcheck();
} else if (res?.status === 'REJECTED') {
} else if (st === 'REJECTED') {
this.stopPolling();
this.error.set(this.t('errors.payment_failed'));
this.qrImageUrl.set(null);
}
// REGISTERED / NEW / '' — keep polling
},
error: () => undefined
});
}, 3000);
}, 5000);
}
private stopPolling(): void {
@@ -247,6 +251,7 @@ export class CreatePage {
closeQr(): void {
this.qrImageUrl.set(null);
this.qrPolling.set(false);
this.qrStatus.set('');
if (this.pollHandle !== null) {
clearInterval(this.pollHandle);
this.pollHandle = null;