feat(purchase-status): remove mock data and implement actual purchase status fetching
This commit is contained in:
@@ -47,4 +47,14 @@ export class CheckoutService {
|
||||
}
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async getPurchase(tenantCode: string, purchaseId: string | number): Promise<{ payment_status: string }> {
|
||||
const response = await firstValueFrom(
|
||||
this.http.get<{ data: { payment_status: string } }>(`${environment.url}tenants/${tenantCode}/compras/${purchaseId}`)
|
||||
);
|
||||
if (!response?.data) {
|
||||
throw new Error('Error al obtener la compra.');
|
||||
}
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { ChangeDetectionStrategy, Component, inject, OnInit, signal } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
|
||||
import { environment } from '../../../../../environments/environment';
|
||||
import { TenantService } from '../../../../core/services/tenant.service';
|
||||
import { CheckoutService } from '../../../../core/services/checkout.service';
|
||||
import { ButtonComponent } from '../../../../shared/components/button/button.component';
|
||||
|
||||
@Component({
|
||||
@@ -18,7 +16,7 @@ import { ButtonComponent } from '../../../../shared/components/button/button.com
|
||||
export class PurchaseStatusPageComponent implements OnInit {
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly router = inject(Router);
|
||||
private readonly http = inject(HttpClient);
|
||||
private readonly checkoutService = inject(CheckoutService);
|
||||
private readonly tenantService = inject(TenantService);
|
||||
|
||||
protected readonly isLoading = signal(true);
|
||||
@@ -37,14 +35,18 @@ export class PurchaseStatusPageComponent implements OnInit {
|
||||
}
|
||||
|
||||
private async checkPurchaseStatus(tenantCode: string, purchaseId: string): Promise<void> {
|
||||
// MOCK DATA FOR DESIGN TESTING
|
||||
try {
|
||||
this.isLoading.set(true);
|
||||
// Simular un delay de red
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
const purchase = await this.checkoutService.getPurchase(tenantCode, purchaseId);
|
||||
const paymentStatus = purchase.payment_status;
|
||||
|
||||
this.status.set('approved'); // Cambiar a 'pending' o 'error' para probar otros estados
|
||||
if (paymentStatus === 'approved') {
|
||||
this.status.set('approved');
|
||||
} else {
|
||||
this.status.set('pending');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch purchase status:', error);
|
||||
this.status.set('error');
|
||||
} finally {
|
||||
this.isLoading.set(false);
|
||||
|
||||
Reference in New Issue
Block a user