- Updated API requests and responses to include time zone information. - Modified backend services to handle time zone for received and refunded dates. - Adjusted frontend components to use local date formatting based on the user's time zone. - Enhanced tests to validate time zone handling in rent payment and refund scenarios.
100 lines
2.5 KiB
TypeScript
100 lines
2.5 KiB
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { Injectable, inject } from '@angular/core';
|
|
import { Observable } from 'rxjs';
|
|
|
|
export type RentPaymentStatus = 'CONFIRMED' | 'REVERSED';
|
|
|
|
export interface PaymentAllocation {
|
|
id: string;
|
|
rentDueId: string;
|
|
amount: number;
|
|
allocatedAt: string;
|
|
}
|
|
|
|
export interface RentPaymentRefund {
|
|
id: string;
|
|
amount: number;
|
|
refundedAt: string;
|
|
version: number;
|
|
}
|
|
|
|
export interface RentPaymentReversal {
|
|
id: string;
|
|
reversedAt: string;
|
|
reason: string;
|
|
reversedAllocations: PaymentAllocation[];
|
|
}
|
|
|
|
export interface RentPayment {
|
|
id: string;
|
|
leaseId: string;
|
|
receivedAt: string;
|
|
amount: number;
|
|
status: RentPaymentStatus;
|
|
allocations: PaymentAllocation[];
|
|
allocatedAmount: number;
|
|
refundedAmount: number;
|
|
unallocatedBalance: number;
|
|
confirmedAt: string;
|
|
version: number;
|
|
refunds: RentPaymentRefund[];
|
|
reversal: RentPaymentReversal | null;
|
|
}
|
|
|
|
export interface RecordRentPaymentRequest {
|
|
operationId: string;
|
|
rentDueId: string;
|
|
rentDueVersion: number;
|
|
receivedAt: string;
|
|
amount: number;
|
|
timeZone: string;
|
|
}
|
|
|
|
export interface AllocateRentPaymentRequest {
|
|
operationId: string;
|
|
paymentVersion: number;
|
|
rentDueId: string;
|
|
rentDueVersion: number;
|
|
amount: number;
|
|
}
|
|
|
|
export interface RefundRentPaymentRequest {
|
|
operationId: string;
|
|
paymentVersion: number;
|
|
amount: number;
|
|
refundedAt: string;
|
|
timeZone: string;
|
|
}
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class RentPaymentService {
|
|
private readonly http = inject(HttpClient);
|
|
|
|
getRentPayments(): Observable<RentPayment[]> {
|
|
return this.http.get<RentPayment[]>('/api/rent-payments');
|
|
}
|
|
|
|
record(request: RecordRentPaymentRequest): Observable<RentPayment> {
|
|
return this.http.post<RentPayment>('/api/rent-payments', request);
|
|
}
|
|
|
|
allocate(paymentId: string, request: AllocateRentPaymentRequest): Observable<RentPayment> {
|
|
return this.http.post<RentPayment>(`/api/rent-payments/${paymentId}/allocations`, request);
|
|
}
|
|
|
|
refund(paymentId: string, request: RefundRentPaymentRequest): Observable<RentPayment> {
|
|
return this.http.post<RentPayment>(`/api/rent-payments/${paymentId}/refunds`, request);
|
|
}
|
|
|
|
reverse(paymentId: string, paymentVersion: number, reason: string): Observable<RentPayment> {
|
|
return this.http.post<RentPayment>(`/api/rent-payments/${paymentId}/reversal`, {
|
|
paymentVersion,
|
|
reason,
|
|
});
|
|
}
|
|
|
|
downloadReceipt(id: string): Observable<Blob> {
|
|
return this.http.get(`/api/rent-payments/${id}/receipt`, { responseType: 'blob' });
|
|
}
|
|
}
|