Implement eSIM profile reissue via PA05-41 API with enhanced error handling
- Updated reissueEsimProfile method to utilize the PA05-41 eSIM Account Activation API for reissuing profiles. - Added validation checks for eSIM type and EID presence, throwing appropriate exceptions for errors. - Improved logging for both successful operations and error responses from the API. - Introduced new interfaces for eSIM account activation requests and responses to support the API integration.
This commit is contained in:
parent
2325cf2753
commit
5c6057bf2e
65
apps/bff/src/vendors/freebit/freebit.service.ts
vendored
65
apps/bff/src/vendors/freebit/freebit.service.ts
vendored
@ -580,16 +580,67 @@ export class FreebititService {
|
|||||||
*/
|
*/
|
||||||
async reissueEsimProfile(account: string): Promise<void> {
|
async reissueEsimProfile(account: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const request: Omit<FreebititEsimReissueRequest, 'authKey'> = { account };
|
// Use PA05-41 eSIM Account Activation API (addAcct) for reissue
|
||||||
|
const authKey = await this.getAuthKey();
|
||||||
|
|
||||||
await this.makeAuthenticatedRequest<FreebititEsimReissueResponse>(
|
// Fetch details to get current EID and plan/network where available
|
||||||
'/esim/reissueProfile/',
|
const details = await this.getSimDetails(account);
|
||||||
request
|
if (details.simType !== 'esim') {
|
||||||
);
|
throw new BadRequestException('This operation is only available for eSIM subscriptions');
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.log(`Successfully reissued eSIM profile for account ${account}`, { account });
|
if (!details.eid) {
|
||||||
|
throw new BadRequestException('eSIM EID not found for this account');
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload: import('./interfaces/freebit.types').FreebititEsimAccountActivationRequest = {
|
||||||
|
authKey,
|
||||||
|
aladinOperated: '20',
|
||||||
|
createType: 'reissue',
|
||||||
|
eid: details.eid, // existing EID used for reissue
|
||||||
|
account,
|
||||||
|
simkind: 'esim',
|
||||||
|
addKind: 'R',
|
||||||
|
// Optional enrichments omitted to minimize validation mismatches
|
||||||
|
};
|
||||||
|
|
||||||
|
const url = `${this.config.baseUrl}/mvno/esim/addAcct/`;
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const text = await response.text().catch(() => '');
|
||||||
|
this.logger.error('Freebit PA05-41 HTTP error', { url, status: response.status, statusText: response.statusText, body: text?.slice(0, 500) });
|
||||||
|
throw new InternalServerErrorException(`HTTP ${response.status}: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json() as import('./interfaces/freebit.types').FreebititEsimAccountActivationResponse;
|
||||||
|
const rc = typeof data.resultCode === 'number' ? String(data.resultCode) : (data.resultCode || '');
|
||||||
|
if (rc !== '100') {
|
||||||
|
const message = data.message || 'Unknown error';
|
||||||
|
this.logger.error('Freebit PA05-41 API error response', {
|
||||||
|
endpoint: '/mvno/esim/addAcct/',
|
||||||
|
resultCode: data.resultCode,
|
||||||
|
statusCode: data.statusCode,
|
||||||
|
message,
|
||||||
|
});
|
||||||
|
throw new FreebititErrorImpl(
|
||||||
|
`API Error: ${message}`,
|
||||||
|
rc || '0',
|
||||||
|
data.statusCode || '0',
|
||||||
|
message
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.log(`Successfully reissued eSIM profile via PA05-41 for account ${account}`, { account });
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.error(`Failed to reissue eSIM profile for account ${account}`, {
|
if (error instanceof BadRequestException) throw error;
|
||||||
|
this.logger.error(`Failed to reissue eSIM profile via PA05-41 for account ${account}`, {
|
||||||
error: error.message,
|
error: error.message,
|
||||||
account,
|
account,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -230,6 +230,45 @@ export interface FreebititEsimAddAccountResponse {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PA05-41 eSIM Account Activation (addAcct)
|
||||||
|
export interface FreebititEsimAccountActivationRequest {
|
||||||
|
authKey: string;
|
||||||
|
aladinOperated: string; // '10' issue, '20' no-issue
|
||||||
|
masterAccount?: string;
|
||||||
|
masterPassword?: string;
|
||||||
|
createType: 'new' | 'reissue' | 'exchange' | string;
|
||||||
|
eid?: string; // required for reissue/exchange per business rules
|
||||||
|
account: string; // MSISDN
|
||||||
|
simkind: 'esim' | string;
|
||||||
|
repAccount?: string;
|
||||||
|
size?: string;
|
||||||
|
addKind?: 'N' | 'R' | string; // e.g., 'R' for reissue
|
||||||
|
oldEid?: string;
|
||||||
|
oldProductNumber?: string;
|
||||||
|
mnp?: {
|
||||||
|
reserveNumber: string;
|
||||||
|
reserveExpireDate: string; // YYYYMMDD
|
||||||
|
};
|
||||||
|
firstnameKanji?: string;
|
||||||
|
lastnameKanji?: string;
|
||||||
|
firstnameZenKana?: string;
|
||||||
|
lastnameZenKana?: string;
|
||||||
|
gender?: string; // 'M' | 'F' | etc
|
||||||
|
birthday?: string; // YYYYMMDD
|
||||||
|
shipDate?: string; // YYYYMMDD
|
||||||
|
planCode?: string;
|
||||||
|
deliveryCode?: string;
|
||||||
|
globalIp?: string; // '10' none, '20' with global IP (env-specific mapping)
|
||||||
|
contractLine?: string; // '4G' | '5G'
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FreebititEsimAccountActivationResponse {
|
||||||
|
resultCode: number | string;
|
||||||
|
status?: any;
|
||||||
|
statusCode?: string;
|
||||||
|
message?: string;
|
||||||
|
}
|
||||||
|
|
||||||
// Portal-specific types for SIM management
|
// Portal-specific types for SIM management
|
||||||
export interface SimDetails {
|
export interface SimDetails {
|
||||||
account: string;
|
account: string;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user