feat(checkout): implement purchase creation and payment intent generation with QR code support

This commit is contained in:
2026-07-06 11:26:39 -03:00
parent 1df6964859
commit 69fee4e20a
9 changed files with 436 additions and 45 deletions

View File

@@ -11,13 +11,23 @@ import { BankAccount } from './tenant.interface';
export class CheckoutService {
private readonly http = inject(HttpClient);
async getSelectedBankAccount(tenantCode: string): Promise<BankAccount> {
async createPurchase(tenantCode: string, payload: any): Promise<{ id: number }> {
const response = await firstValueFrom(
this.http.get<{ data: BankAccount }>(`${environment.url}tenants/${tenantCode}/bank-accounts/selected`)
this.http.post<{ data: { id: number } }>(`${environment.url}tenants/${tenantCode}/compras`, payload)
);
if (!response?.data) {
throw new Error('No se encontraron los datos de la cuenta bancaria seleccionada.');
throw new Error('Error al crear la compra.');
}
return response.data;
}
async generatePaymentIntent(tenantCode: string, purchaseId: number, method: 'qr' | 'transfer' | 'telepagos'): Promise<any> {
const response = await firstValueFrom(
this.http.post<any>(`${environment.url}tenants/${tenantCode}/compras/${purchaseId}/payment-intent`, { method })
);
if (!response) {
throw new Error('Error al generar la intención de pago.');
}
return response;
}
}