refactor: ( payment ) increase timeout

This commit is contained in:
Abubeker Yasin
2026-07-13 15:20:56 +03:00
parent 8424d3bc7f
commit d39bf43e45
6 changed files with 107 additions and 49 deletions

View File

@@ -14,6 +14,7 @@ export interface CacAuthConfig {
username: string;
password: string;
tokenTtlMs: number;
httpTimeoutMs: number;
}
/**
@@ -63,7 +64,7 @@ export class CacBankAuth {
const res = await firstValueFrom(
this.http.post<CacSigninResponse>(url, body, {
headers: { "Content-Type": "application/json" },
timeout: 10_000,
timeout: this.config.httpTimeoutMs,
}),
);
const token = res.data.accessToken;

View File

@@ -194,7 +194,10 @@ export class CacBankProvider implements PaymentProvider, OnModuleInit {
* Verify a payment via GetPaymentByReferenceRequest, keyed on the paymentRequestId. This
* is CAC's callback replacement: the bank sends no webhook, but the id is known from
* initiate and the lookup accepts it, so a lost/failed confirm can still be reconciled.
* A settled payment carries a transactionNo; anything else is still pending.
* A settled payment carries a transactionNo; anything else means the OTP hasn't been
* confirmed yet — that's REQUIRES_ACTION (still awaiting the payer), NOT PROCESSING.
* Returning PROCESSING would let a poll/sweep advance the intent out of REQUIRES_ACTION
* and block the confirm() call.
*/
async queryStatus(paymentRequestId: string): Promise<ProviderStatus> {
const requestBody: CacGetPaymentByReferenceRequest = {
@@ -218,13 +221,13 @@ export class CacBankProvider implements PaymentProvider, OnModuleInit {
}
return {
status: ProviderPaymentStatus.PROCESSING,
status: ProviderPaymentStatus.REQUIRES_ACTION,
rawResponse: response as unknown as Record<string, unknown>,
};
} catch (err) {
if (err instanceof AxiosError && err.response?.status === 404) {
return {
status: ProviderPaymentStatus.PROCESSING,
status: ProviderPaymentStatus.REQUIRES_ACTION,
rawResponse: { notFound: true, reference: paymentRequestId },
};
}
@@ -242,7 +245,7 @@ export class CacBankProvider implements PaymentProvider, OnModuleInit {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
timeout: 10_000,
timeout: this.httpTimeoutMs,
// Keep the raw response text — 17-digit ids would lose precision under axios's
// default JSON.parse. We parse losslessly with parseCacResponse.
transformResponse: [(data) => data],
@@ -294,6 +297,7 @@ export class CacBankProvider implements PaymentProvider, OnModuleInit {
username: this.username,
password: this.password,
tokenTtlMs: this.tokenTtlMs,
httpTimeoutMs: this.httpTimeoutMs,
});
}
return this.auth;
@@ -341,4 +345,7 @@ export class CacBankProvider implements PaymentProvider, OnModuleInit {
private get otpExpiryMs(): number {
return this.config.get<number>("cac.otpExpiryMs") ?? 10 * 60 * 1000;
}
private get httpTimeoutMs(): number {
return this.config.get<number>("cac.httpTimeoutMs") ?? 60_000;
}
}