feat: implement payment verification error component and update checkout flow

This commit is contained in:
2026-07-28 17:02:12 -03:00
parent c233845ce0
commit 4cb81ed70d
13 changed files with 243 additions and 212 deletions

View File

@@ -189,7 +189,7 @@ describe('CheckoutPageComponent payment validation', () => {
expect(checkoutServiceStub.getPurchase).not.toHaveBeenCalled();
});
it('checks a transfer once and redirects to purchase status while pending', async () => {
it('shows the verification error without redirecting while a transfer is pending', async () => {
const { component } = createComponent();
component.selectedPaymentMethod.set('transfer');
@@ -197,13 +197,13 @@ describe('CheckoutPageComponent payment validation', () => {
expect(checkoutServiceStub.getPurchase).toHaveBeenCalledTimes(1);
expect(component.transferValidationStatus()).toBe('pending');
expect(cartServiceStub.clearCart).not.toHaveBeenCalled();
expect(routerStub.navigate).toHaveBeenCalledWith(['/checkout/status', 25]);
expect(routerStub.navigate).not.toHaveBeenCalled();
await vi.advanceTimersByTimeAsync(30_000);
expect(checkoutServiceStub.getPurchase).toHaveBeenCalledTimes(1);
await component.onComplete();
expect(checkoutServiceStub.getPurchase).toHaveBeenCalledTimes(1);
expect(checkoutServiceStub.getPurchase).toHaveBeenCalledTimes(2);
});
it('navigates after a transfer is confirmed as paid', async () => {
@@ -360,11 +360,7 @@ describe('CheckoutPageComponent payment validation', () => {
expect(component.checkoutStepIndex()).toBe(1);
expect(component.selectedPaymentMethod()).toBe('qr');
expect(checkoutServiceStub.generatePaymentIntent).toHaveBeenCalledWith(
'tenant-test',
25,
'qr',
);
expect(checkoutServiceStub.generatePaymentIntent).toHaveBeenCalledWith('tenant-test', 25, 'qr');
expect(component.qrData()).toBe('qr-value');
expect(component.qrPaymentStatus()).toBe('waiting');
});

View File

@@ -447,7 +447,6 @@ export class CheckoutPageComponent implements OnInit, OnDestroy {
if (purchase.status === 'pending_payment') {
this.transferValidationStatus.set('pending');
this.navigateToPurchaseStatus(purchaseId);
return;
}

View File

@@ -1,14 +1,13 @@
<div class="checkout-payment">
<div class="checkout-payment__content">
<section class="payment-methods" aria-labelledby="payment-methods-title">
<h2 id="payment-methods-title" class="payment-methods__title">Selecciona el metodo de pago</h2>
<h2 id="payment-methods-title" class="payment-methods__title">
Selecciona el metodo de pago
</h2>
<div class="payment-methods__list" role="radiogroup" aria-label="Metodo de pago">
@for (method of paymentMethods(); track method.id) {
<label
class="payment-method"
[class.is-selected]="selectedPaymentMethod() === method.id"
>
<label class="payment-method" [class.is-selected]="selectedPaymentMethod() === method.id">
<input
class="payment-method__radio"
type="radio"
@@ -21,7 +20,8 @@
<span class="payment-method__label">
@if (method.id === 'telepagos') {
<span class="telepagos-logo" aria-label="TelePagos">
<span class="telepagos-logo__tele">tele</span><span class="telepagos-logo__pagos">pagos</span>
<span class="telepagos-logo__tele">tele</span
><span class="telepagos-logo__pagos">pagos</span>
</span>
} @else {
{{ method.label }}
@@ -36,7 +36,7 @@
<section class="payment-panel d-flex justify-content-end" aria-live="polite">
@if (isGeneratingIntent()) {
<div class="payment-panel__card" style="text-align: center; padding: 2rem;">
<div class="payment-panel__card" style="text-align: center; padding: 2rem">
<h3 class="payment-panel__title">Cargando información de pago...</h3>
</div>
} @else if (selectedPaymentMethod() === 'qr') {
@@ -53,6 +53,8 @@
[transferDni]="transferDni()"
[copiedTransferField]="copiedTransferField()"
[validationStatus]="transferValidationStatus()"
[paymentAmount]="qrPaymentAmount()"
[whatsappUrl]="whatsappUrl()"
(copyTransferValue)="requestCopy($event.field, $event.value)"
(submitDni)="generateTransferIntent.emit($event)"
(completePurchase)="complete.emit()"
@@ -63,4 +65,3 @@
</section>
</div>
</div>

View File

@@ -1,22 +1,9 @@
<div class="payment-panel__card">
@if (paymentStatus() === 'timed_out') {
<div class="payment-timeout" role="alert">
<div class="payment-timeout__icon" aria-hidden="true">
<i class="fa-solid fa-xmark"></i>
</div>
<h4 class="payment-timeout__title">No pudimos verificar el pago de {{ formattedAmount() }}.</h4>
<p class="payment-timeout__message">Por favor contactate con nosotros para resolverlo.</p>
@if (whatsappUrl()) {
<app-button
type="button"
variant="primary"
buttonClass="d-inline-flex align-items-center justify-content-center gap-2"
(click)="openWhatsApp()"
>
<span>WhatsApp</span>
</app-button>
}
</div>
<app-payment-verification-error
[paymentAmount]="paymentAmount()"
[whatsappUrl]="whatsappUrl()"
/>
} @else {
<h3 class="payment-panel__title">Ingresa a tu billetera y escanea el siguiente QR</h3>
<div class="payment-panel__divider"></div>

View File

@@ -57,7 +57,9 @@
rgba(17, 17, 17, 0.95) 84% 100%
);
background-size: 18px 18px;
background-position: 0 0, 9px 9px;
background-position:
0 0,
9px 9px;
display: flex;
justify-content: center;
align-items: center;
@@ -86,7 +88,9 @@
height: 38px;
border: 5px solid #111111;
background: #ffffff;
box-shadow: inset 0 0 0 8px #ffffff, inset 0 0 0 14px #111111;
box-shadow:
inset 0 0 0 8px #ffffff,
inset 0 0 0 14px #111111;
&--tl {
top: 10px;
@@ -116,43 +120,6 @@
}
}
.payment-timeout {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
padding-top: 0.85rem;
&__icon {
display: grid;
width: 84px;
height: 84px;
place-items: center;
border: 1px solid var(--tenant-danger, #dc3545);
border-radius: 50%;
color: var(--tenant-danger, #dc3545);
font-size: 2.7rem;
}
&__title {
max-width: 250px;
margin: 1.35rem 0 0;
color: var(--tenant-danger, #dc3545);
font-size: 1.05rem;
font-weight: 700;
line-height: 1.3;
}
&__message {
max-width: 250px;
margin: 2rem 0 1.75rem;
color: #666666;
font-size: 1rem;
line-height: 1.25;
}
}
.payment-verification {
position: absolute;
inset: 0;

View File

@@ -40,10 +40,12 @@ describe('CheckoutPaymentQrComponent', () => {
fixture.detectChanges();
const element = fixture.nativeElement as HTMLElement;
const whatsapp = element.querySelector<HTMLAnchorElement>('.payment-timeout__whatsapp');
const whatsapp = Array.from(element.querySelectorAll('button')).find((button) =>
button.textContent?.includes('WhatsApp'),
);
expect(element.textContent).toMatch(/No pudimos verificar el pago de \$\s*300\.000\./);
expect(element.textContent).toContain('Por favor contactate con nosotros para resolverlo.');
expect(whatsapp?.href).toBe('https://wa.me/543412602222');
expect(whatsapp).toBeDefined();
expect(element.textContent).not.toContain('Volver a verificar');
});
});

View File

@@ -1,15 +1,15 @@
import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core';
import { ButtonComponent } from '../../../../../../shared/components/button/button.component';
import { ChangeDetectionStrategy, Component, input } from '@angular/core';
import { QRCodeComponent } from '../../../../../../shared/components/qrcode/qrcode.component';
import { QrPaymentStatus } from '../../checkout-page.models';
import { PaymentVerificationErrorComponent } from '../payment-verification-error/payment-verification-error.component';
@Component({
selector: 'app-checkout-payment-qr',
standalone: true,
imports: [ButtonComponent, QRCodeComponent],
imports: [PaymentVerificationErrorComponent, QRCodeComponent],
templateUrl: './checkout-payment-qr.component.html',
styleUrl: './checkout-payment-qr.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CheckoutPaymentQrComponent {
readonly qrData = input<string | null>(null);
@@ -17,19 +17,4 @@ export class CheckoutPaymentQrComponent {
readonly isCheckingPayment = input<boolean>(false);
readonly paymentAmount = input<number>(0);
readonly whatsappUrl = input<string | null>(null);
protected readonly formattedAmount = computed(() =>
new Intl.NumberFormat('es-AR', {
style: 'currency',
currency: 'ARS',
maximumFractionDigits: 0,
}).format(this.paymentAmount()),
);
protected openWhatsApp(): void {
const url = this.whatsappUrl();
if (url) {
window.open(url, '_blank', 'noopener,noreferrer');
}
}
}

View File

@@ -1,105 +1,106 @@
<div class="payment-panel__card">
<div class="dni-form-container">
<h3 class="dni-form-title">Ingresá DNI de quién va a transferir</h3>
<form class="dni-form row gx-2" (submit)="$event.preventDefault(); onSubmitDni()">
<div class="col-8">
<app-input
type="text"
[value]="dniControl.value"
(valueChange)="dniControl.setValue($event.toString()); dniControl.markAsDirty()"
[disabled]="isDniDisabled()"
[invalid]="dniControl.invalid && (dniControl.dirty || dniControl.touched)"
/>
</div>
<div class="col-4">
@if (isDniDisabled()) {
<app-button
type="button"
variant="secondary"
hostClass="w-100 h-100"
buttonClass="w-100 h-100 px-0"
(click)="enableEditing()"
>
Modificar
</app-button>
} @else {
<app-button
type="submit"
variant="primary"
hostClass="w-100 h-100"
buttonClass="w-100 h-100 px-0"
[disabled]="dniControl.invalid"
>
Continuar
</app-button>
}
</div>
</form>
</div>
@if (transferAccount() && !isEditing()) {
<div class="payment-panel__divider"></div>
<div class="payment-panel__account">
<p class="payment-panel__eyebrow">DATOS DE CUENTA:</p>
<div class="payment-detail">
<span class="payment-detail__label">Titular:</span>
<span class="payment-detail__value">{{ transferAccount()?.titular }}</span>
</div>
<div class="payment-detail">
<span class="payment-detail__label">Entidad:</span>
<span class="payment-detail__value">{{ transferAccount()?.entidad }}</span>
</div>
<div class="payment-detail payment-detail--copy">
<span class="payment-detail__label">CVU:</span>
<span class="payment-detail__value">{{ transferAccount()?.cvu }}</span>
<app-icon-button
variant="copy"
ariaLabel="Copiar CVU"
(click)="requestCopy('cvu', transferAccount()!.cvu)"
/>
@if (copiedTransferField() === 'cvu') {
<span class="payment-detail__feedback" style="grid-column: 1 / -1; text-align: center;">¡Copiado!</span>
}
</div>
<div class="payment-detail payment-detail--copy">
<span class="payment-detail__label">Alias:</span>
<span class="payment-detail__value">{{ transferAccount()?.alias }}</span>
<app-icon-button
variant="copy"
ariaLabel="Copiar Alias"
(click)="requestCopy('alias', transferAccount()!.alias)"
/>
@if (copiedTransferField() === 'alias') {
<span class="payment-detail__feedback" style="grid-column: 1 / -1; text-align: center;">¡Copiado!</span>
}
</div>
@if (validationStatus() === 'pending' || validationStatus() === 'error') {
<app-payment-verification-error
[paymentAmount]="paymentAmount()"
[whatsappUrl]="whatsappUrl()"
/>
} @else {
<div class="dni-form-container">
<h3 class="dni-form-title">Ingresá DNI de quién va a transferir</h3>
<form class="dni-form row gx-2" (submit)="$event.preventDefault(); onSubmitDni()">
<div class="col-8">
<app-input
type="text"
[value]="dniControl.value"
(valueChange)="dniControl.setValue($event.toString()); dniControl.markAsDirty()"
[disabled]="isDniDisabled()"
[invalid]="dniControl.invalid && (dniControl.dirty || dniControl.touched)"
/>
</div>
<div class="col-4">
@if (isDniDisabled()) {
<app-button
type="button"
variant="secondary"
hostClass="w-100 h-100"
buttonClass="w-100 h-100 px-0"
(click)="enableEditing()"
>
Modificar
</app-button>
} @else {
<app-button
type="submit"
variant="primary"
hostClass="w-100 h-100"
buttonClass="w-100 h-100 px-0"
[disabled]="dniControl.invalid"
>
Continuar
</app-button>
}
</div>
</form>
</div>
<div class="mt-4">
<app-button
type="button"
variant="primary"
hostClass="w-100"
buttonClass="w-100"
[disabled]="validationStatus() === 'checking'"
(click)="completePurchase.emit()"
>
{{ validationStatus() === 'checking' ? 'Validando pago...' : 'Ya transferí' }}
</app-button>
@if (transferAccount() && !isEditing()) {
<div class="payment-panel__divider"></div>
<div class="payment-panel__account">
<p class="payment-panel__eyebrow">DATOS DE CUENTA:</p>
@if (validationStatus() === 'pending') {
<p class="payment-validation payment-validation--pending" role="status">
Todavía no recibimos la transferencia. Podés volver a verificar.
</p>
} @else if (validationStatus() === 'error') {
<p class="payment-validation payment-validation--error" role="alert">
No pudimos validar la transferencia. Intentá nuevamente.
</p>
}
</div>
<div class="payment-detail">
<span class="payment-detail__label">Titular:</span>
<span class="payment-detail__value">{{ transferAccount()?.titular }}</span>
</div>
<div class="payment-detail">
<span class="payment-detail__label">Entidad:</span>
<span class="payment-detail__value">{{ transferAccount()?.entidad }}</span>
</div>
<div class="payment-detail payment-detail--copy">
<span class="payment-detail__label">CVU:</span>
<span class="payment-detail__value">{{ transferAccount()?.cvu }}</span>
<app-icon-button
variant="copy"
ariaLabel="Copiar CVU"
(click)="requestCopy('cvu', transferAccount()!.cvu)"
/>
@if (copiedTransferField() === 'cvu') {
<span class="payment-detail__feedback" style="grid-column: 1 / -1; text-align: center"
>¡Copiado!</span
>
}
</div>
<div class="payment-detail payment-detail--copy">
<span class="payment-detail__label">Alias:</span>
<span class="payment-detail__value">{{ transferAccount()?.alias }}</span>
<app-icon-button
variant="copy"
ariaLabel="Copiar Alias"
(click)="requestCopy('alias', transferAccount()!.alias)"
/>
@if (copiedTransferField() === 'alias') {
<span class="payment-detail__feedback" style="grid-column: 1 / -1; text-align: center"
>¡Copiado!</span
>
}
</div>
</div>
<div class="mt-4">
<app-button
type="button"
variant="primary"
hostClass="w-100"
buttonClass="w-100"
[disabled]="validationStatus() === 'checking'"
(click)="completePurchase.emit()"
>
{{ validationStatus() === 'checking' ? 'Validando pago...' : 'Ya transferí' }}
</app-button>
</div>
}
}
</div>

View File

@@ -115,17 +115,3 @@
height: 100%;
}
}
.payment-validation {
margin: 0.75rem 0 0;
font-size: 0.8rem;
line-height: 1.35;
&--pending {
color: #8a681d;
}
&--error {
color: #b42318;
}
}

View File

@@ -1,23 +1,46 @@
import { ChangeDetectionStrategy, Component, computed, input, output, signal, OnInit, effect, untracked } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
computed,
input,
output,
signal,
OnInit,
effect,
untracked,
} from '@angular/core';
import { FormControl, ReactiveFormsModule, Validators } from '@angular/forms';
import { IconButtonComponent } from '../../../../../../shared/components/icon-button/icon-button.component';
import { ButtonComponent } from '../../../../../../shared/components/button/button.component';
import { InputComponent } from '../../../../../../shared/components/input/input.component';
import { TransferAccount, TransferField, TransferValidationStatus } from '../../checkout-page.models';
import {
TransferAccount,
TransferField,
TransferValidationStatus,
} from '../../checkout-page.models';
import { PaymentVerificationErrorComponent } from '../payment-verification-error/payment-verification-error.component';
@Component({
selector: 'app-checkout-payment-transfer',
standalone: true,
imports: [IconButtonComponent, ButtonComponent, InputComponent, ReactiveFormsModule],
imports: [
IconButtonComponent,
ButtonComponent,
InputComponent,
ReactiveFormsModule,
PaymentVerificationErrorComponent,
],
templateUrl: './checkout-payment-transfer.component.html',
styleUrl: './checkout-payment-transfer.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CheckoutPaymentTransferComponent implements OnInit {
readonly transferAccount = input<TransferAccount | null>(null);
readonly transferDni = input<string>('');
readonly copiedTransferField = input<TransferField | null>(null);
readonly validationStatus = input<TransferValidationStatus>('idle');
readonly paymentAmount = input<number>(0);
readonly whatsappUrl = input<string | null>(null);
readonly copyTransferValue = output<{ field: TransferField; value: string }>();
readonly submitDni = output<string>();
@@ -25,7 +48,7 @@ export class CheckoutPaymentTransferComponent implements OnInit {
protected readonly dniControl = new FormControl('', {
nonNullable: true,
validators: [Validators.required, Validators.pattern(/^\d{7,8}$/)]
validators: [Validators.required, Validators.pattern(/^\d{7,8}$/)],
});
protected readonly isEditing = signal<boolean>(false);

View File

@@ -0,0 +1,17 @@
<div class="payment-timeout" role="alert">
<div class="payment-timeout__icon" aria-hidden="true">
<i class="fa-solid fa-xmark"></i>
</div>
<h4 class="payment-timeout__title">No pudimos verificar el pago de {{ formattedAmount() }}.</h4>
<p class="payment-timeout__message">Por favor contactate con nosotros para resolverlo.</p>
@if (whatsappUrl()) {
<app-button
type="button"
variant="primary"
buttonClass="d-inline-flex align-items-center justify-content-center gap-2"
(click)="openWhatsApp()"
>
<span>WhatsApp</span>
</app-button>
}
</div>

View File

@@ -0,0 +1,35 @@
.payment-timeout {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
padding-top: 0.85rem;
&__icon {
display: grid;
width: 84px;
height: 84px;
place-items: center;
border: 1px solid var(--tenant-danger, #dc3545);
border-radius: 50%;
color: var(--tenant-danger, #dc3545);
font-size: 2.7rem;
}
&__title {
max-width: 250px;
margin: 1.35rem 0 0;
color: var(--tenant-danger, #dc3545);
font-size: 1.05rem;
font-weight: 700;
line-height: 1.3;
}
&__message {
max-width: 250px;
margin: 2rem 0 1.75rem;
color: #666666;
font-size: 1rem;
line-height: 1.25;
}
}

View File

@@ -0,0 +1,32 @@
import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core';
import { ButtonComponent } from '../../../../../../shared/components/button/button.component';
@Component({
selector: 'app-payment-verification-error',
standalone: true,
imports: [ButtonComponent],
templateUrl: './payment-verification-error.component.html',
styleUrl: './payment-verification-error.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PaymentVerificationErrorComponent {
readonly paymentAmount = input<number>(0);
readonly whatsappUrl = input<string | null>(null);
protected readonly formattedAmount = computed(() =>
new Intl.NumberFormat('es-AR', {
style: 'currency',
currency: 'ARS',
maximumFractionDigits: 0,
}).format(this.paymentAmount()),
);
protected openWhatsApp(): void {
const url = this.whatsappUrl();
if (url) {
window.open(url, '_blank', 'noopener,noreferrer');
}
}
}