66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
|
|
import { Component, inject, signal } from '@angular/core';
|
|||
|
|
import { FormsModule } from '@angular/forms';
|
|||
|
|
import { HttpClient } from '@angular/common/http';
|
|||
|
|
|
|||
|
|
const API_URL = 'https://qr.vitanova.network:567/qr';
|
|||
|
|
|
|||
|
|
@Component({
|
|||
|
|
selector: 'app-root',
|
|||
|
|
imports: [FormsModule],
|
|||
|
|
templateUrl: './app.html',
|
|||
|
|
styleUrl: './app.scss'
|
|||
|
|
})
|
|||
|
|
export class App {
|
|||
|
|
private http = inject(HttpClient);
|
|||
|
|
|
|||
|
|
amount = signal<number>(10);
|
|||
|
|
error = signal<string>('');
|
|||
|
|
loading = signal<boolean>(false);
|
|||
|
|
|
|||
|
|
private get paymentId(): string | null {
|
|||
|
|
const params = new URLSearchParams(window.location.search);
|
|||
|
|
return params.get('id');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
goToPayment(): void {
|
|||
|
|
const val = this.amount();
|
|||
|
|
if (!val || val <= 0) {
|
|||
|
|
this.error.set('Введите корректную сумму');
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const id = this.paymentId;
|
|||
|
|
if (id === null) {
|
|||
|
|
this.error.set('Не указан идентификатор платежа (параметр id)');
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.error.set('');
|
|||
|
|
this.loading.set(true);
|
|||
|
|
|
|||
|
|
this.http.post<{ qrId: string; qrStatus: string; qrExpirationDate: string; payload: string; qrUrl: string }>(API_URL, {
|
|||
|
|
payment: 'sbp',
|
|||
|
|
amount: val,
|
|||
|
|
currency: 'rub',
|
|||
|
|
id
|
|||
|
|
}).subscribe({
|
|||
|
|
next: (res) => {
|
|||
|
|
this.loading.set(false);
|
|||
|
|
if (res?.payload) {
|
|||
|
|
window.location.href = res.payload;
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
error: () => {
|
|||
|
|
this.loading.set(false);
|
|||
|
|
this.error.set('Ошибка при создании платежа. Попробуйте ещё раз.');
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
onAmountChange(value: number): void {
|
|||
|
|
this.amount.set(value);
|
|||
|
|
if (value > 0) this.error.set('');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|