feat(checkout): refactor purchase completion flow and clear cart state

This commit is contained in:
2026-07-07 15:36:01 -03:00
parent 05ada5f613
commit e8d71bfd03
8 changed files with 41 additions and 14 deletions

View File

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

View File

@@ -241,13 +241,20 @@ export class CheckoutPageComponent implements OnInit {
}
}
protected async onFinalize(): Promise<void> {
protected async onComplete(): Promise<void> {
const purchaseId = this.createdPurchaseId();
const tenant = this.tenantService.tenant();
if (!purchaseId) {
if (!purchaseId || !tenant) {
return;
}
void this.router.navigate(['/checkout/status', purchaseId]);
try {
await this.checkoutService.completePurchase(tenant.codigo, purchaseId);
this.cartService.clearCart();
void this.router.navigate(['/checkout/status', purchaseId]);
} catch (error) {
console.error('Failed to complete purchase:', error);
}
}
}

View File

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

View File

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

View File

@@ -85,11 +85,11 @@ export class PurchaseStatusPageComponent implements OnInit, OnDestroy {
}
private resolveStatus(purchase: PurchaseStatusResponse): PurchaseStatusView {
if (purchase.payment_status === 'approved' || purchase.status === 'paid') {
if (purchase.status === 'paid') {
return 'approved';
}
if (purchase.payment_status === 'rejected' || purchase.status === 'cancelled') {
if (purchase.status === 'rejected' || purchase.status === 'cancelled') {
return 'rejected';
}