fix it
This commit is contained in:
parent
f87650dcc2
commit
3a0e3c466a
146
src/modules/challenge/adaptor/dtos/orange.challenge.dto.ts
Normal file
146
src/modules/challenge/adaptor/dtos/orange.challenge.dto.ts
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
/**
|
||||||
|
* Structure de la requête pour l'API Orange DCB Challenge v2
|
||||||
|
*/
|
||||||
|
export interface OrangeChallengeRequest {
|
||||||
|
country: string;
|
||||||
|
method: string;
|
||||||
|
service: string;
|
||||||
|
partnerId: string;
|
||||||
|
identifier: {
|
||||||
|
type: string;
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
confirmationCode: string;
|
||||||
|
message: string;
|
||||||
|
otpLength: number;
|
||||||
|
senderName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Structure de la réponse de l'API Orange DCB Challenge
|
||||||
|
*/
|
||||||
|
export interface OrangeChallengeResponse {
|
||||||
|
challengeId?: string;
|
||||||
|
message?: string;
|
||||||
|
expiresIn?: number;
|
||||||
|
sessionId?: string;
|
||||||
|
error?: {
|
||||||
|
code: number | string;
|
||||||
|
message: string;
|
||||||
|
description?: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder pour construire des requêtes Orange Challenge
|
||||||
|
*/
|
||||||
|
export class OrangeChallengeRequestBuilder {
|
||||||
|
private request: Partial<OrangeChallengeRequest> = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Définir le pays
|
||||||
|
*/
|
||||||
|
withCountry(country: string): this {
|
||||||
|
this.request.country = country;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Définir la méthode d'authentification
|
||||||
|
*/
|
||||||
|
withMethod(method: string): this {
|
||||||
|
this.request.method = method;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Définir le service
|
||||||
|
*/
|
||||||
|
withService(service: string): this {
|
||||||
|
this.request.service = service;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Définir l'ID du partenaire
|
||||||
|
*/
|
||||||
|
withPartnerId(partnerId: string): this {
|
||||||
|
this.request.partnerId = partnerId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Définir l'identifiant (numéro de téléphone, etc.)
|
||||||
|
*/
|
||||||
|
withIdentifier(type: string, value: string): this {
|
||||||
|
this.request.identifier = {
|
||||||
|
type,
|
||||||
|
value
|
||||||
|
};
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Définir le code de confirmation (OTP)
|
||||||
|
*/
|
||||||
|
withConfirmationCode(code: string): this {
|
||||||
|
this.request.confirmationCode = code;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Définir le message OTP
|
||||||
|
*/
|
||||||
|
withMessage(message: string): this {
|
||||||
|
this.request.message = message;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Définir la longueur de l'OTP
|
||||||
|
*/
|
||||||
|
withOtpLength(length: number): this {
|
||||||
|
this.request.otpLength = length;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Définir le nom de l'expéditeur
|
||||||
|
*/
|
||||||
|
withSenderName(senderName: string): this {
|
||||||
|
this.request.senderName = senderName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construire la requête finale
|
||||||
|
*/
|
||||||
|
build(): OrangeChallengeRequest {
|
||||||
|
// Validation des champs obligatoires
|
||||||
|
if (!this.request.country) {
|
||||||
|
throw new Error('Country is required');
|
||||||
|
}
|
||||||
|
if (!this.request.method) {
|
||||||
|
throw new Error('Method is required');
|
||||||
|
}
|
||||||
|
if (!this.request.service) {
|
||||||
|
throw new Error('Service is required');
|
||||||
|
}
|
||||||
|
if (!this.request.partnerId) {
|
||||||
|
throw new Error('Partner ID is required');
|
||||||
|
}
|
||||||
|
if (!this.request.identifier) {
|
||||||
|
throw new Error('Identifier is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.request as OrangeChallengeRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Réinitialiser le builder
|
||||||
|
*/
|
||||||
|
reset(): this {
|
||||||
|
this.request = {};
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,15 +3,17 @@ import {
|
|||||||
OrangeChallengeRequest,
|
OrangeChallengeRequest,
|
||||||
OrangeChallengeResponse,
|
OrangeChallengeResponse,
|
||||||
OrangeChallengeRequestBuilder
|
OrangeChallengeRequestBuilder
|
||||||
} from './dtos/orange-challenge.dto';
|
} from './dtos/orange.challenge.dto'
|
||||||
import {
|
import {
|
||||||
OrangeConfig,
|
OrangeConfig,
|
||||||
DEFAULT_ORANGE_CONFIG,
|
DEFAULT_ORANGE_CONFIG,
|
||||||
COUNTRY_CODE_MAPPING,
|
COUNTRY_CODE_MAPPING,
|
||||||
OTP_METHOD_MAPPING
|
OTP_METHOD_MAPPING
|
||||||
} from './config/orange.config';
|
} from './orange.config';
|
||||||
import { OtpChallengeRequestDto } from '../../dtos/otp-challenge-request.dto';
|
|
||||||
import { OtpChallengeResponseDto, OtpChallengeStatusEnum } from '../../dtos/otp-challenge-response.dto';
|
//import { OtpChallengeResponseDto, OtpChallengeStatusEnum } from '../../dtos/otp-challenge-response.dto';
|
||||||
|
import { OtpChallengeRequestDto } from '../dto/challenge.request.dto';
|
||||||
|
import { OtpChallengeResponseDto, OtpChallengeStatusEnum } from '../dto/challenge.response.dto';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adaptateur pour l'API Orange DCB v2
|
* Adaptateur pour l'API Orange DCB v2
|
||||||
@ -72,7 +74,7 @@ export class OrangeAdapter {
|
|||||||
const expiresIn = response.data.expires_in || 3600;
|
const expiresIn = response.data.expires_in || 3600;
|
||||||
this.tokenExpiresAt = Date.now() + (expiresIn * 1000);
|
this.tokenExpiresAt = Date.now() + (expiresIn * 1000);
|
||||||
|
|
||||||
return this.accessToken;
|
return this.accessToken as string;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Failed to obtain Orange access token: ${error.message}`);
|
throw new Error(`Failed to obtain Orange access token: ${error.message}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user