feat(checkout): implement authentication guard for checkout route and add bank account service
This commit is contained in:
23
src/app/core/services/checkout.service.ts
Normal file
23
src/app/core/services/checkout.service.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { BankAccount } from './tenant.interface';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CheckoutService {
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
async getSelectedBankAccount(tenantCode: string): Promise<BankAccount> {
|
||||
const response = await firstValueFrom(
|
||||
this.http.get<{ data: BankAccount }>(`${environment.url}tenants/${tenantCode}/bank-accounts/selected`)
|
||||
);
|
||||
if (!response?.data) {
|
||||
throw new Error('No se encontraron los datos de la cuenta bancaria seleccionada.');
|
||||
}
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,14 @@
|
||||
import { ApiResponse } from './api-response.interface';
|
||||
|
||||
export interface BankAccount {
|
||||
id: number;
|
||||
tenant_code: string;
|
||||
titular: string;
|
||||
entidad: string;
|
||||
alias: string;
|
||||
cvu: string;
|
||||
}
|
||||
|
||||
export interface Tenant {
|
||||
id: number;
|
||||
codigo: string;
|
||||
@@ -13,6 +22,8 @@ export interface Tenant {
|
||||
footer_bg_color: string;
|
||||
header_logo: string;
|
||||
footer_logo: string;
|
||||
selected_bank_account_id?: number | null;
|
||||
selected_bank_account?: BankAccount | null;
|
||||
}
|
||||
|
||||
export type TenantBootstrapResponse = ApiResponse<Tenant>;
|
||||
|
||||
Reference in New Issue
Block a user