backend old version request

This commit is contained in:
2026-04-30 15:00:24 +04:00
parent d9b0c221f1
commit 678ab3773b
8 changed files with 367 additions and 17 deletions

View File

@@ -13,6 +13,13 @@ interface WebSessionResponse {
Status: boolean;
}
interface CheckFastcheckResponse {
fastcheck: string;
amount?: number;
expiration: string;
Status: boolean;
}
@Component({
selector: 'app-fastcheck-page',
imports: [FormsModule, RouterLink],
@@ -31,6 +38,7 @@ export class FastcheckPage {
fastcheckAmount = signal<number | null>(null);
fastcheckCode = signal<string>('');
error = signal<string>('');
amountLoading = signal<boolean>(false);
popupOpen = signal<boolean>(false);
popupLoading = signal<boolean>(false);
@@ -38,6 +46,13 @@ export class FastcheckPage {
webSessionId = signal<string>('');
paid = signal<boolean>(false);
private pollHandle: ReturnType<typeof setInterval> | null = null;
private lastLookedUpNumber = '';
canPay = computed(() => {
const digits = this.fastcheckNumber().replace(/\D/g, '');
const codeDigits = this.fastcheckCode().replace(/\D/g, '');
return digits.length === 12 && codeDigits.length === 5 && !this.amountLoading();
});
telegramLink = computed(() => {
const sid = this.webSessionId();
@@ -62,12 +77,7 @@ export class FastcheckPage {
}
pay(): void {
if (!this.fastcheckNumber().trim()) {
this.error.set('Введите номер');
return;
}
if (!this.fastcheckCode().trim()) {
this.error.set('Введите код');
if (!this.canPay()) {
return;
}
this.error.set('');
@@ -168,4 +178,64 @@ export class FastcheckPage {
onAmountChange(value: number | null): void {
this.fastcheckAmount.set(value);
}
/** Mask fastcheck number as XXXX-XXXX-XXXX, allow only digits. */
onNumberChange(raw: string): void {
const digits = (raw ?? '').replace(/\D/g, '').slice(0, 12);
const groups: string[] = [];
for (let i = 0; i < digits.length; i += 4) {
groups.push(digits.slice(i, i + 4));
}
const masked = groups.join('-');
this.fastcheckNumber.set(masked);
this.error.set('');
// If number became incomplete, drop the previously fetched amount so the
// user doesn't see a stale value tied to a different (now-edited) number.
if (digits.length < 12 && this.lastLookedUpNumber) {
this.fastcheckAmount.set(null);
this.lastLookedUpNumber = '';
}
// Auto-lookup when 12 digits are entered (and we haven't already looked it up).
if (digits.length === 12 && masked !== this.lastLookedUpNumber) {
this.lookupFastcheck(masked);
}
}
/** Allow only digits, max 5, in the code field. */
onCodeChange(raw: string): void {
const digits = (raw ?? '').replace(/\D/g, '').slice(0, 5);
this.fastcheckCode.set(digits);
this.error.set('');
}
private lookupFastcheck(number: string): void {
this.lastLookedUpNumber = number;
this.amountLoading.set(true);
this.fastcheckAmount.set(null);
// GET /fastcheck — body in GET is non-standard; many HTTP libs strip it.
// The backend should accept ?fastcheck= as a query param too. We send both.
this.http
.request<CheckFastcheckResponse>('GET', `${FASTCHECK_API}/fastcheck`, {
body: { fastcheck: number },
params: { fastcheck: number }
})
.subscribe({
next: (res) => {
this.amountLoading.set(false);
if (res?.Status && typeof res.amount === 'number') {
this.fastcheckAmount.set(res.amount);
} else if (res?.Status === false) {
this.error.set('Платёж не найден или просрочен.');
}
},
error: () => {
this.amountLoading.set(false);
this.error.set('Не удалось проверить номер. Попробуйте ещё раз.');
this.lastLookedUpNumber = '';
}
});
}
}