feat(checkout): implement purchase creation and payment intent generation with QR code support
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user