feat(checkout): refactor purchase completion flow and clear cart state
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
(paymentMethodChange)="selectPaymentMethod($event)"
|
||||
(copyTransferValue)="copyTransferValue($event.field, $event.value)"
|
||||
(cancelStep)="onCancel()"
|
||||
(finalize)="onFinalize()"
|
||||
(complete)="onComplete()"
|
||||
/>
|
||||
</app-step>
|
||||
</app-stepper>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@
|
||||
type="button"
|
||||
hostClass="checkout-payment__action-btn"
|
||||
[disabled]="isGeneratingIntent()"
|
||||
(click)="finalize.emit()"
|
||||
(click)="complete.emit()"
|
||||
>
|
||||
Finalizar compra
|
||||
</app-button>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user