This commit is contained in:
sdarbinyan
2026-06-02 02:12:08 +04:00
parent c6bc05560e
commit e53c8230e6
3 changed files with 31 additions and 97 deletions

View File

@@ -800,14 +800,6 @@ export const mockDataInterceptor: HttpInterceptorFn = (req, next) => {
}, 300); }, 300);
} }
// ── GET /qr/settings
if (url.endsWith('/qr/settings') && req.method === 'GET') {
return respond({
minAmount: 30,
maxAmount: 200000,
});
}
// ── POST /qr (create payment QR directly) // ── POST /qr (create payment QR directly)
if (url.endsWith('/qr') && req.method === 'POST') { if (url.endsWith('/qr') && req.method === 'POST') {
return respond({ return respond({
@@ -866,27 +858,7 @@ export const mockDataInterceptor: HttpInterceptorFn = (req, next) => {
}, 500); }, 500);
} }
// ── GET /qr/dynamic/:partnerID/:qrID (dynamic QR status) // ── GET /qr/payment/:qrId (payment status)
if (url.match(/\/qr\/dynamic\/[^/]+\/[^/]+$/) && req.method === 'GET') {
return respond({
status: 'APPROVED',
paymentStatus: 'COMPLETED',
code: 'SUCCESS',
amount: 0,
currency: 'RUB',
qrId: 'mock',
transactionId: 999,
transactionDate: new Date().toISOString(),
additionalInfo: '',
paymentPurpose: '',
createDate: new Date().toISOString(),
order: 'mock-order',
qrExpirationDate: new Date().toISOString(),
phoneNumber: '+70000000000'
}, 500);
}
// ── GET /qr/payment/:qrId (legacy/direct payment status)
if (url.match(/\/qr\/payment\/[^/]+$/) && req.method === 'GET') { if (url.match(/\/qr\/payment\/[^/]+$/) && req.method === 'GET') {
return respond({ return respond({
paymentStatus: 'COMPLETED', paymentStatus: 'COMPLETED',

View File

@@ -58,7 +58,6 @@ export class CartComponent implements OnDestroy {
maxChecks = PAYMENT_MAX_CHECKS; maxChecks = PAYMENT_MAX_CHECKS;
private pollingSubscription?: Subscription; private pollingSubscription?: Subscription;
private closeTimeout?: ReturnType<typeof setTimeout>; private closeTimeout?: ReturnType<typeof setTimeout>;
private qrPartnerId = '';
constructor( constructor(
private cartService: CartService, private cartService: CartService,
@@ -160,7 +159,6 @@ export class CartComponent implements OnDestroy {
openPaymentPopup(): void { openPaymentPopup(): void {
this.showPaymentPopup.set(true); this.showPaymentPopup.set(true);
this.paymentStatus.set('creating'); this.paymentStatus.set('creating');
this.qrPartnerId = '';
this.paymentId.set(''); this.paymentId.set('');
this.qrCodeUrl.set(''); this.qrCodeUrl.set('');
this.paymentUrl.set(''); this.paymentUrl.set('');
@@ -192,7 +190,6 @@ export class CartComponent implements OnDestroy {
} }
this.paymentStatus.set('creating'); this.paymentStatus.set('creating');
this.qrPartnerId = '';
this.paymentId.set(''); this.paymentId.set('');
this.qrCodeUrl.set(''); this.qrCodeUrl.set('');
this.paymentUrl.set(''); this.paymentUrl.set('');
@@ -202,12 +199,6 @@ export class CartComponent implements OnDestroy {
createPayment(): void { createPayment(): void {
const sessionId = this.authService.session()?.sessionId || ''; const sessionId = this.authService.session()?.sessionId || '';
const partnerQrId = this.getPartnerQrId();
if (!partnerQrId) {
this.setPaymentError();
return;
}
const cartItems = this.items().map((item: CartItem) => ({ const cartItems = this.items().map((item: CartItem) => ({
itemID: item.itemID, itemID: item.itemID,
quantity: item.quantity, quantity: item.quantity,
@@ -227,22 +218,26 @@ export class CartComponent implements OnDestroy {
) )
: of(null); : of(null);
const userIdValue = this.getUrlParam('userid-value') || undefined; const paymentPayload = {
const authorizationKey = this.getUrlParam('authorization-key') || undefined;
const qrPayload = {
qrtype: 'QRDynamic' as const,
amount: Number(this.totalPrice()), amount: Number(this.totalPrice()),
currency: 'RUB' as const, currency: this.currentCurrency,
partnerqrID: partnerQrId, siteuserID: this.getPaymentUserId(),
qrDescription: `Order ${this.generateOrderId()}, total: ${this.totalPrice().toFixed(2)} ${this.currentCurrency}`, siteorderID: this.generateOrderId(),
Userid: userIdValue ?? this.getPaymentUserId(), redirectUrl: '',
Reference: this.getUrlParam('ref') || (typeof window !== 'undefined' ? window.location.hostname : ''), telegramUsername: this.getTelegramUsername(),
RedirectUrl: typeof window !== 'undefined' ? window.location.origin : undefined, items: this.items().map((item: CartItem) => ({
itemID: item.itemID,
price: item.discount > 0
? item.price * (1 - item.discount / 100)
: item.price,
name: item.name,
quantity: item.quantity,
})),
}; };
syncCart$ syncCart$
.pipe( .pipe(
switchMap(() => this.apiService.createPayment(qrPayload, { authorizationKey, userIdValue })) switchMap(() => this.apiService.createPayment(paymentPayload))
) )
.subscribe({ .subscribe({
next: (response) => { next: (response) => {
@@ -256,7 +251,6 @@ export class CartComponent implements OnDestroy {
return; return;
} }
this.qrPartnerId = partnerQrId;
this.paymentId.set(qrId); this.paymentId.set(qrId);
this.qrCodeUrl.set(qrUrl); this.qrCodeUrl.set(qrUrl);
this.paymentUrl.set(paymentLink); this.paymentUrl.set(paymentLink);
@@ -278,7 +272,7 @@ export class CartComponent implements OnDestroy {
startPolling(): void { startPolling(): void {
this.stopPolling(); this.stopPolling();
if (!this.qrPartnerId || !this.paymentId()) { if (!this.paymentId()) {
this.setPaymentError(); this.setPaymentError();
return; return;
} }
@@ -287,7 +281,7 @@ export class CartComponent implements OnDestroy {
.pipe( .pipe(
take(this.maxChecks), // maximum 36 checks (3 minutes) take(this.maxChecks), // maximum 36 checks (3 minutes)
switchMap(() => { switchMap(() => {
return this.apiService.checkPaymentStatus(this.qrPartnerId, this.paymentId()).pipe( return this.apiService.checkPaymentStatus(this.paymentId()).pipe(
catchError((err) => { catchError((err) => {
console.error('Error checking payment status:', err); console.error('Error checking payment status:', err);
return of(null); return of(null);
@@ -348,7 +342,6 @@ export class CartComponent implements OnDestroy {
private setPaymentError(): void { private setPaymentError(): void {
this.paymentStatus.set('error'); this.paymentStatus.set('error');
this.stopPolling(); this.stopPolling();
this.qrPartnerId = '';
if (this.closeTimeout) { if (this.closeTimeout) {
clearTimeout(this.closeTimeout); clearTimeout(this.closeTimeout);
this.closeTimeout = undefined; this.closeTimeout = undefined;
@@ -452,24 +445,6 @@ export class CartComponent implements OnDestroy {
return this.getTelegramUserId() ?? `web_${Date.now()}`; return this.getTelegramUserId() ?? `web_${Date.now()}`;
} }
private getPartnerQrId(): string {
const fromQuery = this.getUrlParam('id');
if (fromQuery) {
return fromQuery;
}
const envValue = (environment as unknown as Record<string, unknown>)['partnerqrID'];
return typeof envValue === 'string' ? envValue : '';
}
private getUrlParam(name: string): string | null {
if (typeof window === 'undefined') {
return null;
}
return new URLSearchParams(window.location.search).get(name);
}
private generateOrderId(): string { private generateOrderId(): string {
const timestamp = Date.now(); const timestamp = Date.now();
const random = Math.random().toString(36).substring(2, 8); const random = Math.random().toString(36).substring(2, 8);

View File

@@ -1,19 +1,18 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable, timer } from 'rxjs'; import { Observable, timer } from 'rxjs';
import { map, retry } from 'rxjs/operators'; import { map, retry } from 'rxjs/operators';
import { Category, Item, Subcategory } from '../models'; import { Category, Item, Subcategory } from '../models';
import { environment } from '../../environments/environment'; import { environment } from '../../environments/environment';
export interface QrCreateRequest { export interface PaymentCreateRequest {
qrtype: 'QRDynamic';
amount: number; amount: number;
currency: 'RUB'; currency: string;
partnerqrID: string; siteuserID: string;
qrDescription?: string; siteorderID: string;
Userid?: string; redirectUrl: string;
Reference?: string; telegramUsername: string;
RedirectUrl?: string; items: Array<{ itemID: number; price: number; name: string; quantity?: number }>;
} }
export interface QrCreateResponse { export interface QrCreateResponse {
@@ -34,8 +33,7 @@ export interface QrCreateResponse {
PartnerID?: string | number; PartnerID?: string | number;
} }
export interface QrStatusResponse { export interface PaymentStatusResponse {
status?: string;
additionalInfo: string; additionalInfo: string;
paymentPurpose: string; paymentPurpose: string;
amount: number; amount: number;
@@ -393,23 +391,12 @@ export class ApiService {
return this.http.post<{ message: string }>(`${this.baseUrl}/items/${itemID}/questiion`, body); return this.http.post<{ message: string }>(`${this.baseUrl}/items/${itemID}/questiion`, body);
} }
createPayment(payload: QrCreateRequest, headers?: { authorizationKey?: string; userIdValue?: string }): Observable<QrCreateResponse> { createPayment(payload: PaymentCreateRequest): Observable<QrCreateResponse> {
let httpHeaders = new HttpHeaders(); return this.http.post<QrCreateResponse>(`${this.baseUrl}/cart`, payload);
if (headers?.authorizationKey) {
httpHeaders = httpHeaders.set('authorization-key', headers.authorizationKey);
}
if (headers?.userIdValue) {
httpHeaders = httpHeaders.set('userid-value', headers.userIdValue);
} }
return this.http.post<QrCreateResponse>(`${this.baseUrl}/qr`, payload, { headers: httpHeaders }); checkPaymentStatus(qrId: string): Observable<PaymentStatusResponse> {
} return this.http.get<PaymentStatusResponse>(`${this.baseUrl}/qr/payment/${encodeURIComponent(qrId)}`);
checkPaymentStatus(partnerQrId: string, qrId: string): Observable<QrStatusResponse> {
return this.http.get<QrStatusResponse>(
`${this.baseUrl}/qr/dynamic/${encodeURIComponent(partnerQrId)}/${encodeURIComponent(qrId)}`
);
} }
resolvePaymentQrId(response: QrCreateResponse): string { resolvePaymentQrId(response: QrCreateResponse): string {