feat(purchase-status): implement purchase status page with loading and error handling

This commit is contained in:
2026-07-07 11:21:27 -03:00
parent cb0d1e4d77
commit 910f367851
9 changed files with 237 additions and 0 deletions

View File

@@ -21,6 +21,7 @@
(paymentMethodChange)="selectPaymentMethod($event)"
(copyTransferValue)="copyTransferValue($event.field, $event.value)"
(cancelStep)="onCancel()"
(finalize)="onFinalize()"
/>
</app-step>
</app-stepper>

View File

@@ -240,4 +240,26 @@ export class CheckoutPageComponent implements OnInit {
this.copiedTransferField.set(null);
}
}
protected async onFinalize(): Promise<void> {
const purchaseId = this.createdPurchaseId();
const tenant = this.tenantService.tenant();
if (!purchaseId || !tenant) {
return;
}
try {
this.isGeneratingIntent.set(true); // Re-use this flag for loading state
await this.checkoutService.finalizePurchase(tenant.codigo, purchaseId);
void this.router.navigate(['/checkout/status', purchaseId]);
} catch (error) {
console.error('Failed to finalize purchase:', error);
// Even on failure, we probably want to navigate to the status page to show 'pending' or whatever state it is in.
// But maybe the endpoint returns error if not paid. For now, navigate anyway so the status page handles the state.
void this.router.navigate(['/checkout/status', purchaseId]);
} finally {
this.isGeneratingIntent.set(false);
}
}
}

View File

@@ -142,6 +142,7 @@
type="button"
hostClass="checkout-payment__action-btn"
[disabled]="isGeneratingIntent()"
(click)="finalize.emit()"
>
Finalizar compra
</app-button>

View File

@@ -25,6 +25,7 @@ export class CheckoutPaymentStepComponent {
readonly paymentMethodChange = output<PaymentMethod>();
readonly copyTransferValue = output<{ field: TransferField; value: string }>();
readonly cancelStep = output<void>();
readonly finalize = output<void>();
protected selectPaymentMethod(method: PaymentMethod): void {
this.paymentMethodChange.emit(method);