mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
refactor: ( payment ) increase timeout
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user