2026-04-30 01:17:17 +04:00
|
|
|
|
import { Component, inject, signal } from '@angular/core';
|
|
|
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
|
|
|
import { Router, RouterLink } from '@angular/router';
|
|
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
|
|
import { FastcheckService } from '../../fastcheck.service';
|
|
|
|
|
|
import { FASTCHECK_API } from '../../api';
|
|
|
|
|
|
|
|
|
|
|
|
interface CreateFastcheckResponse {
|
|
|
|
|
|
fastcheck: string;
|
|
|
|
|
|
expiration: string;
|
|
|
|
|
|
code: string;
|
|
|
|
|
|
Status: boolean;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type PaymentMethod = 'sbp' | 'wechat' | 'visa' | 'master';
|
|
|
|
|
|
type Currency = 'RUB' | 'CNY' | 'USD' | 'EUR' | 'AMD';
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
|
selector: 'app-create-page',
|
|
|
|
|
|
imports: [FormsModule, RouterLink],
|
|
|
|
|
|
templateUrl: './create-page.html',
|
|
|
|
|
|
styleUrl: './create-page.scss'
|
|
|
|
|
|
})
|
|
|
|
|
|
export class CreatePage {
|
|
|
|
|
|
private http = inject(HttpClient);
|
|
|
|
|
|
private store = inject(FastcheckService);
|
|
|
|
|
|
private router = inject(Router);
|
|
|
|
|
|
|
|
|
|
|
|
amount = signal<number>(10);
|
|
|
|
|
|
note = signal<string>('');
|
|
|
|
|
|
error = signal<string>('');
|
|
|
|
|
|
loading = signal<boolean>(false);
|
|
|
|
|
|
|
|
|
|
|
|
payment = signal<PaymentMethod>('sbp');
|
|
|
|
|
|
currency = signal<Currency>('RUB');
|
|
|
|
|
|
|
|
|
|
|
|
/** sessionID for the Authorization header. Comes from ?session=... or websession. */
|
|
|
|
|
|
private get sessionId(): string {
|
|
|
|
|
|
return new URLSearchParams(window.location.search).get('session') ?? '';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
selectPayment(method: PaymentMethod, enabled: boolean): void {
|
|
|
|
|
|
if (!enabled) return;
|
|
|
|
|
|
this.payment.set(method);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
selectCurrency(c: Currency, enabled: boolean): void {
|
|
|
|
|
|
if (!enabled) return;
|
|
|
|
|
|
this.currency.set(c);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
createCheck(): void {
|
|
|
|
|
|
const val = this.amount();
|
|
|
|
|
|
if (!val || val <= 0) {
|
|
|
|
|
|
this.error.set('Введите корректную сумму');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.error.set('');
|
|
|
|
|
|
this.loading.set(true);
|
|
|
|
|
|
|
|
|
|
|
|
const headers: Record<string, string> = {};
|
|
|
|
|
|
if (this.sessionId) {
|
|
|
|
|
|
headers['Authorization'] = JSON.stringify({ sessionID: this.sessionId });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.http
|
|
|
|
|
|
.post<CreateFastcheckResponse>(
|
|
|
|
|
|
`${FASTCHECK_API}/fastcheck`,
|
|
|
|
|
|
{ amount: val, currency: this.currency() },
|
|
|
|
|
|
{ headers }
|
|
|
|
|
|
)
|
|
|
|
|
|
.subscribe({
|
|
|
|
|
|
next: (res) => {
|
|
|
|
|
|
this.loading.set(false);
|
|
|
|
|
|
if (res?.fastcheck) {
|
|
|
|
|
|
this.store.setCreated({
|
|
|
|
|
|
fastcheck: res.fastcheck,
|
|
|
|
|
|
code: res.code,
|
|
|
|
|
|
amount: val,
|
|
|
|
|
|
expiration: res.expiration
|
|
|
|
|
|
});
|
|
|
|
|
|
this.router.navigate(['/']);
|
|
|
|
|
|
} else {
|
2026-04-30 14:51:32 +04:00
|
|
|
|
this.error.set('Не удалось создать платёж.');
|
2026-04-30 01:17:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
error: () => {
|
|
|
|
|
|
this.loading.set(false);
|
2026-04-30 14:51:32 +04:00
|
|
|
|
this.error.set('Ошибка при создании платежа. Попробуйте ещё раз.');
|
2026-04-30 01:17:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onAmountChange(value: number): void {
|
|
|
|
|
|
this.amount.set(value);
|
|
|
|
|
|
if (value > 0) this.error.set('');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onNoteChange(value: string): void {
|
|
|
|
|
|
this.note.set(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|