diff --git a/.github/workflows/deploy-api-service-v2.yml b/.github/workflows/deploy-api-service-v2.yml index 199c644d..740c2271 100644 --- a/.github/workflows/deploy-api-service-v2.yml +++ b/.github/workflows/deploy-api-service-v2.yml @@ -2,13 +2,13 @@ name: Deploy Api Service on: workflow_dispatch: - push: - paths: - - "api-service/**" - - "mock-service/**" - branches: - - "draft-*" - - "release-*" + # push: + # paths: + # - "api-service/**" + # - "mock-service/**" + # branches: + # - "draft-*" + # - "release-*" jobs: @@ -310,4 +310,4 @@ jobs: docker run -d --name automation-api-service-${{ vars.CONTAINER_NAME }} \ --env-file $REPO_DIR/.env \ -p ${{ vars. API_SERVICE_PORT }}:${{ vars. API_SERVICE_PORT }} \ - $IMAGE_NAME:stable \ No newline at end of file + $IMAGE_NAME:stable diff --git a/api-service/src/config/build.yaml b/api-service/src/config/build.yaml index ff70f95a..5453a503 100644 --- a/api-service/src/config/build.yaml +++ b/api-service/src/config/build.yaml @@ -2,7 +2,8 @@ openapi: 3.0.0 info: title: ONDC Specification description: ONDC Specification - version: 2.0.0 + version: 2.1.0 + domain: ONDC:TRV11 security: - SubscriberAuth: [] paths: @@ -47210,13 +47211,6 @@ x-validations: useCode: - METRO _CONTINUE_: "!(useCasePath all in useCode)" - - _NAME_: REQUIRED_MESSAGE_NAME_212 - attr: "$.message.catalog.providers[*].fulfillments[*].stops[*].location.descriptor.code" - _RETURN_: attr are present - useCasePath: "$.message.catalog.providers[*].fulfillments[*].vehicle.category" - useCode: - - METRO - _CONTINUE_: "!(useCasePath all in useCode)" - _NAME_: REQUIRED_MESSAGE_ID_23 attr: "$.message.catalog.providers[*].fulfillments[*].id" _RETURN_: attr are present @@ -47481,6 +47475,7 @@ x-validations: validValues: - AC - NON_AC + _CONTINUE_: "!(subTags are present)" _RETURN_: subTags all in validValues - _NAME_: VALID_ITEM_DESCRIPTOR_CODE _SCOPE_: "$.message.catalog.providers[*].items[*]" @@ -47658,6 +47653,7 @@ x-validations: - ROUTE - TRIP - TICKET + - PASS useCasePath: "$.message.order.fulfillments[*].vehicle.category" useCode: - METRO @@ -48213,6 +48209,7 @@ x-validations: - ROUTE - TRIP - TICKET + - PASS useCasePath: "$.message.order.fulfillments[*].vehicle.category" useCode: - METRO @@ -48882,6 +48879,7 @@ x-validations: - ROUTE - TRIP - TICKET + - PASS useCasePath: "$.message.order.fulfillments[*].vehicle.category" useCode: - METRO diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/confirm/confirm_agent_purchase/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/confirm/confirm_agent_purchase/default.yaml index a795ba33..4273abb2 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/confirm/confirm_agent_purchase/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/confirm/confirm_agent_purchase/default.yaml @@ -19,8 +19,8 @@ message: - type: "START" location: descriptor: - name: "kashmere gate" - code: "KASHMERE_GATE" + name: "MOCK_STATION_1" + code: "MOCK_STATION_1" gps: "28.666576, 77.233332" id: "1" - type: "INTERMEDIATE_STOP" @@ -28,8 +28,8 @@ message: name: "Stop 1" location: descriptor: - name: "Indira Gandhi Technical Unviversity" - code: "INDIRA_GANDHI_TECHNICAL_UNIV" + name: "MOCK_STATION_2" + code: "MOCK_STATION_2" gps: "28.624097, 77.204991" id: "2" parent_stop_id: "1" @@ -38,8 +38,8 @@ message: name: "Stop 2" location: descriptor: - name: "Yamuna Bazar" - code: "YAMUNA_BAZAR" + name: "MOCK_STATION_3" + code: "MOCK_STATION_3" gps: "28.625972,77.209917" id: "3" parent_stop_id: "2" @@ -48,8 +48,8 @@ message: name: "Stop 3" location: descriptor: - name: "dhaula kuan" - code: "DHAULA_KUAN" + name: "MOCK_STATION_4" + code: "MOCK_STATION_4" gps: "28.610972,77.201717" id: "4" parent_stop_id: "3" @@ -58,16 +58,16 @@ message: name: "Stop 4" location: descriptor: - name: "gpo" - code: "GPO" + name: "MOCK_STATION_5" + code: "MOCK_STATION_5" gps: "28.623097,77.209917" id: "5" parent_stop_id: "4" - type: "END" location: descriptor: - name: "Greater Kailash" - code: "GREATER_KAILASH" + name: "MOCK_STATION_6" + code: "MOCK_STATION_6" gps: "28.548230, 77.238039" id: "6" parent_stop_id: "5" diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/confirm/confirm_agent_purchase/generator.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/confirm/confirm_agent_purchase/generator.ts index 73b41763..2b16e619 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/confirm/confirm_agent_purchase/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/confirm/confirm_agent_purchase/generator.ts @@ -13,8 +13,8 @@ export async function confirmGenerator( type: "START", location: { descriptor: { - name: "kashmere gate", - code: "KASHMERE_GATE", + name: "MOCK_STATION_1", + code: "MOCK_STATION_1", }, gps: "28.666576, 77.233332", }, @@ -27,8 +27,8 @@ export async function confirmGenerator( }, location: { descriptor: { - name: "Indira Gandhi Technical Unviversity", - code: "INDIRA_GANDHI_TECHNICAL_UNIV", + name: "MOCK_STATION_2", + code: "MOCK_STATION_2", }, gps: "28.624097, 77.204991", }, @@ -42,8 +42,8 @@ export async function confirmGenerator( }, location: { descriptor: { - name: "Yamuna Bazar", - code: "YAMUNA_BAZAR", + name: "MOCK_STATION_3", + code: "MOCK_STATION_3", }, gps: "28.625972,77.209917", }, @@ -57,8 +57,8 @@ export async function confirmGenerator( }, location: { descriptor: { - name: "dhaula kuan", - code: "DHAULA_KUAN", + name: "MOCK_STATION_4", + code: "MOCK_STATION_4", }, gps: "28.610972,77.201717", }, @@ -72,8 +72,8 @@ export async function confirmGenerator( }, location: { descriptor: { - name: "gpo", - code: "GPO", + name: "MOCK_STATION_5", + code: "MOCK_STATION_5", }, gps: "28.623097,77.209917", }, @@ -84,8 +84,8 @@ export async function confirmGenerator( type: "END", location: { descriptor: { - name: "Greater Kailash", - code: "GREATER_KAILASH", + name: "MOCK_STATION_6", + code: "MOCK_STATION_6", }, gps: "28.548230, 77.238039", }, diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/confirm/confirm_veh_con_without/generator.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/confirm/confirm_veh_con_without/generator.ts index 98bde674..7087397a 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/confirm/confirm_veh_con_without/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/confirm/confirm_veh_con_without/generator.ts @@ -2,6 +2,12 @@ import { SessionData } from "../../../../session-types"; const { v4: uuidv4 } = require("uuid"); +function getRandomFourDigitInt() { + const min = 1000; + const max = 9999; + return Math.floor(Math.random() * (max - min + 1)) + min; +} + const transformPaymentsToPaid = ( payments: any[], amount: any, @@ -37,8 +43,28 @@ export async function confirmVehConWithoutUpdateGenerator( existingPayload.message.order.provider.id = sessionData.provider_id; } - existingPayload.message.order.fulfillments = - existingPayload.message.order.fulfillments; + if (sessionData.fulfillments) { + existingPayload.message.order.fulfillments = sessionData.fulfillments + ?.flat() + ?.map((f: any) => { + if (f.type === "TRIP") { + return { + id: f.id, + type: f.type, + }; + } + if (f.type === "TICKET") { + const randomInt = getRandomFourDigitInt(); + return { + id: f.id, + type: f.type, + vehicle: { + registration: `TX${randomInt}`, + }, + }; + } + }); + } if (sessionData.payments) { existingPayload.message.order.payments = transformPaymentsToPaid( diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/init/init_agent_activation/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/init/init_agent_activation/default.yaml index b356d6f4..09e2ea3c 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/init/init_agent_activation/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/init/init_agent_activation/default.yaml @@ -24,9 +24,6 @@ message: - descriptor: code: "BUYER_FINDER_FEES_PERCENTAGE" value: "1" - - descriptor: - code: "SETTLEMENT_AMOUNT" - value: "5" - descriptor: code: "SETTLEMENT_TYPE" value: "NEFT" diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/init/init_agent_login/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/init/init_agent_login/default.yaml index e6a1d281..11c8f5f1 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/init/init_agent_login/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/init/init_agent_login/default.yaml @@ -18,9 +18,6 @@ message: - descriptor: code: "BUYER_FINDER_FEES_PERCENTAGE" value: "1" - - descriptor: - code: "SETTLEMENT_AMOUNT" - value: "5" - descriptor: code: "SETTLEMENT_TYPE" value: "NEFT" diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm/generator.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm/generator.ts index 74aac80d..0b8d23ae 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm/generator.ts @@ -27,7 +27,7 @@ function updateOrderTimestamps(payload: any) { } function updateFulfillmentsWithParentInfo(fulfillments: any[],sessionData:SessionData): void { - const validTo = new Date(Date.now()+ 6*60*60*60).toISOString(); + const validTo = new Date(Date.now() + 2 * 24 * 60 * 60 * 1000).toISOString(); fulfillments.forEach((fulfillment) => { // Generate a random QR token diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_activation/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_activation/default.yaml index b8b57224..53d2af63 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_activation/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_activation/default.yaml @@ -20,7 +20,7 @@ message: value: "0" time: label: "Validity" - duration: "PT2D" + duration: "P2D" timestamp: "2025-03-23T11:01:40.065Z" provider: id: "P1" diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_login/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_login/default.yaml index b8b57224..53d2af63 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_login/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_login/default.yaml @@ -20,7 +20,7 @@ message: value: "0" time: label: "Validity" - duration: "PT2D" + duration: "P2D" timestamp: "2025-03-23T11:01:40.065Z" provider: id: "P1" diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_purchase/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_purchase/default.yaml index 9adf2b58..50f04b67 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_purchase/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_purchase/default.yaml @@ -24,7 +24,7 @@ message: count: 2 time: label: "Validity" - duration: "PT2D" + duration: "P2D" timestamp: "2025-03-23T11:01:40.065Z" provider: id: "P1" @@ -40,8 +40,8 @@ message: - type: "START" location: descriptor: - name: "kashmere gate" - code: "KASHMERE_GATE" + name: "MOCK_STATION_1" + code: "MOCK_STATION_1" gps: "28.666576, 77.233332" id: "1" - type: "INTERMEDIATE_STOP" @@ -49,8 +49,8 @@ message: name: "Stop 1" location: descriptor: - name: "Indira Gandhi Technical Unviversity" - code: "INDIRA_GANDHI_TECHNICAL_UNIV" + name: "MOCK_STATION_2" + code: "MOCK_STATION_2" gps: "28.624097, 77.204991" id: "2" parent_stop_id: "1" @@ -59,8 +59,8 @@ message: name: "Stop 2" location: descriptor: - name: "Yamuna Bazar" - code: "YAMUNA_BAZAR" + name: "MOCK_STATION_3" + code: "MOCK_STATION_3" gps: "28.625972,77.209917" id: "3" parent_stop_id: "2" @@ -69,8 +69,8 @@ message: name: "Stop 3" location: descriptor: - name: "dhaula kuan" - code: "DHAULA_KUAN" + name: "MOCK_STATION_4" + code: "MOCK_STATION_4" gps: "28.610972,77.201717" id: "4" parent_stop_id: "3" @@ -79,16 +79,16 @@ message: name: "Stop 4" location: descriptor: - name: "gpo" - code: "GPO" + name: "MOCK_STATION_5" + code: "MOCK_STATION_5" gps: "28.623097,77.209917" id: "5" parent_stop_id: "4" - type: "END" location: descriptor: - name: "Greater Kailash" - code: "GREATER_KAILASH" + name: "MOCK_STATION_6" + code: "MOCK_STATION_6" gps: "28.548230, 77.238039" id: "6" parent_stop_id: "5" diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_purchase/generator.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_purchase/generator.ts index a9c8e229..03d26b54 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_purchase/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_agent_purchase/generator.ts @@ -95,7 +95,7 @@ export async function onConfirmGenerator( price: item?.price ?? {}, quantity: item?.quantity ?? {}, time: (() => { - const duration = "PT2D"; + const duration = "P2D"; let validityEndDate = new Date(); const daysMatch = duration.match(/P(?:T)?(\d+)D/); if (daysMatch) { diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_delayed/generator.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_delayed/generator.ts index 2956ed63..84de08b3 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_delayed/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_delayed/generator.ts @@ -41,7 +41,7 @@ function updateOrderTimestamps(payload: any) { } function updateFulfillmentsWithParentInfo(fulfillments: any[]): void { - const validTo = new Date(Date.now()+ 6*60*60*60).toISOString(); + const validTo = new Date(Date.now() + 2 * 24 * 60 * 60 * 1000).toISOString(); fulfillments.forEach((fulfillment) => { // Generate a random QR token diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_user_confirmation/generator.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_user_confirmation/generator.ts index 1d6953b7..b21aa33d 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_user_confirmation/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_user_confirmation/generator.ts @@ -60,7 +60,7 @@ function updateFulfillmentsWithParentInfo(fulfillments: any[], sessionData: Sess type: "VEHICLE_NUMBER", status: authStatus, token:"bPOPw0KGgoAAAANSUhEUgAAAH0AAAB9AQAAAACn", - valid_to: new Date(Date.now()+3*60*60*30).toISOString() + valid_to: new Date(Date.now() + 2 * 24 * 60 * 60 * 1000).toISOString() }; } else { fulfillment.stops.push({ @@ -69,7 +69,7 @@ function updateFulfillmentsWithParentInfo(fulfillments: any[], sessionData: Sess type: "VEHICLE_NUMBER", status: authStatus, token:"bPOPw0KGgoAAAANSUhEUgAAAH0AAAB9AQAAAACn", - valid_to: new Date(Date.now()+3*60*60*30).toISOString() + valid_to: new Date(Date.now() + 2 * 24 * 60 * 60 * 1000).toISOString() }, }); } diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle/generator.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle/generator.ts index aba9b855..cfc796bb 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle/generator.ts @@ -62,7 +62,7 @@ function updateFulfillmentsWithParentInfo( const m = istNow.getMonth(); const d = istNow.getDate(); const endIST = new Date(Date.UTC(y, m, d + 1, 4 - 5, 30 - 30, 0)); - const validTo = endIST.toISOString(); + const validTo = new Date(Date.now() + 2 * 24 * 60 * 60 * 1000).toISOString(); // If a stop exists, modify the first stop; otherwise, create a new one if (fulfillment.stops.length > 0) { diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle/generatorQr.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle/generatorQr.ts index fff2739b..ef297d36 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle/generatorQr.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle/generatorQr.ts @@ -62,7 +62,7 @@ function updateFulfillmentsWithParentInfo( const m = istNow.getMonth(); const d = istNow.getDate(); const endIST = new Date(Date.UTC(y, m, d + 1, 4 - 5, 30 - 30, 0)); - const validTo = endIST.toISOString(); + const validTo = new Date(Date.now() + 2 * 24 * 60 * 60 * 1000).toISOString(); // If a stop exists, modify the first stop; otherwise, create a new one if (fulfillment.stops.length > 0) { diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle_without_update/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle_without_update/default.yaml index b39a3258..82199bbe 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle_without_update/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle_without_update/default.yaml @@ -1,7 +1,7 @@ message: order: id: "O1" - status: "ACTIVE" + status: "COMPLETED" items: - id: "I1" diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle_without_update/generator.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle_without_update/generator.ts index 576b5d45..588ea884 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle_without_update/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_confirm/on_confirm_vehicle_without_update/generator.ts @@ -4,7 +4,7 @@ function enhancePayments(payments: any) { const additionalParams = { bank_code: "XXXXXXXX", bank_account_number: "xxxxxxxxxxxxxx", - virtual_payment_address: "9988199772@okicic" + virtual_payment_address: "9988199772@okicic", }; return payments.map((payment: any) => ({ @@ -27,12 +27,15 @@ function updateOrderTimestamps(payload: any) { return payload; } -function updateFulfillmentsWithParentInfo(fulfillments: any[], sessionData: SessionData): void { +function updateFulfillmentsWithParentInfo( + fulfillments: any[], + sessionData: SessionData, +): void { const validTo = "2024-07-23T23:59:59.999Z"; // Build a Map from fulfillment ID → buyer side fulfillment object const buyerFulfillmentMap = new Map( - (sessionData.buyer_side_fulfillment_ids || []).map((f: any) => [f.id, f]) + (sessionData.buyer_side_fulfillment_ids || []).map((f: any) => [f.id, f]), ); fulfillments.forEach((fulfillment) => { @@ -55,12 +58,12 @@ function updateFulfillmentsWithParentInfo(fulfillments: any[], sessionData: Sess // fulfillment.vehicle= buyerEntry?.vehicle // If a stop exists, modify the first stop; otherwise, create a new one if (fulfillment.stops.length > 0) { - fulfillment.stops[0].type ="START" + fulfillment.stops[0].type = "START"; fulfillment.stops[0].authorization = { type: "QR_AND_VEHICLE_NUMBER", status: "CLAIMED", - token:"bPOPw0KGgoAAAANSUhEUgAAAH0AAAB9AQAAAACn", - valid_to: new Date(Date.now()+3*60*60*30).toISOString() + token: "bPOPw0KGgoAAAANSUhEUgAAAH0AAAB9AQAAAACn", + valid_to: new Date(Date.now() + 2 * 24 * 60 * 60 * 1000).toISOString(), }; } else { fulfillment.stops.push({ @@ -68,26 +71,28 @@ function updateFulfillmentsWithParentInfo(fulfillments: any[], sessionData: Sess authorization: { type: "QR_AND_VEHICLE_NUMBER", status: "CLAIMED", - token:"bPOPw0KGgoAAAANSUhEUgAAAH0AAAB9AQAAAACn", - valid_to: new Date(Date.now()+3*60*60*30).toISOString() + token: "bPOPw0KGgoAAAANSUhEUgAAAH0AAAB9AQAAAACn", + valid_to: new Date( + Date.now() + 2 * 24 * 60 * 60 * 1000, + ).toISOString(), }, }); } }); } - export async function onConfirmVehConfGenerator( existingPayload: any, - sessionData: SessionData + sessionData: SessionData, ) { const randomId = Math.random().toString(36).substring(2, 15); const order_id = randomId; existingPayload.message.order.payments = enhancePayments( - sessionData.updated_payments + sessionData.updated_payments, ); - existingPayload.message.order.billing=sessionData.billing - existingPayload.message.order.cancellation_terms=sessionData.cancellation_terms[0] + existingPayload.message.order.billing = sessionData.billing; + existingPayload.message.order.cancellation_terms = + sessionData.cancellation_terms[0]; // Check if items is a non-empty array if (sessionData.items.length > 0) { existingPayload.message.order.items = sessionData.items; @@ -95,19 +100,27 @@ export async function onConfirmVehConfGenerator( // Check if fulfillments is a non-empty array if (sessionData.fulfillments.length > 0) { + let index = 0; + const fulfillments = sessionData?.buyer_side_fulfillment_ids + ?.flat() + ?.filter((f: any) => f?.type === "TICKET" && f?.vehicle?.registration) + ?.map((f: any) => f.vehicle.registration); + existingPayload.message.order.fulfillments = sessionData.fulfillments.map( (fulfillment) => { if (fulfillment.type === "TICKET") { + const registration = fulfillments[index]; + index++; return { ...fulfillment, vehicle: { - registration: "GL90", + registration: registration ?? "GL90", }, }; } - return fulfillment + return fulfillment; }, - ) + ); } updateFulfillmentsWithParentInfo(sessionData.fulfillments, sessionData); @@ -116,6 +129,6 @@ export async function onConfirmVehConfGenerator( } existingPayload.message.order.id = order_id; existingPayload = updateOrderTimestamps(existingPayload); - existingPayload.message.order.tags = sessionData.tags.flat() + existingPayload.message.order.tags = sessionData.tags.flat(); return existingPayload; } diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/default.yaml index fa4447bc..a697f141 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/default.yaml @@ -20,7 +20,7 @@ message: count: 2 time: label: "Validity" - duration: "PT2D" + duration: "P2D" timestamp: "2021-03-23T11:01:40.065Z" provider: id: "P1" diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/generator.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/generator.ts index 352fe333..50a2937d 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/generator.ts @@ -51,6 +51,12 @@ export async function onInitGenerator( display: false, list: [ ...bap_tags_list.list, + { + descriptor: { + code: "SETTLEMENT_WINDOW", + }, + value: "PT60M", + }, { descriptor: { code: "SETTLEMENT_BANK_CODE", diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/on_init_agent_activation/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/on_init_agent_activation/default.yaml index 0e2a4799..4b3e674b 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/on_init_agent_activation/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/on_init_agent_activation/default.yaml @@ -18,7 +18,7 @@ message: value: "0" time: label: "Validity" - duration: "PT2D" + duration: "P2D" provider: id: "P1" descriptor: diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/on_init_agent_activation/generator.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/on_init_agent_activation/generator.ts index b51d1f55..f46a07d3 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/on_init_agent_activation/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/on_init_agent_activation/generator.ts @@ -14,7 +14,7 @@ export async function onInitGenerator(existingPayload: any, sessionData: any) { fulfillment_ids, time: { label: "Validity", - duration: "PT2D", + duration: "P2D", }, }; }); diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/on_init_agent_login/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/on_init_agent_login/default.yaml index 0e2a4799..bbb7855f 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/on_init_agent_login/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_init/on_init_agent_login/default.yaml @@ -18,7 +18,7 @@ message: value: "0" time: label: "Validity" - duration: "PT2D" + duration: "P2D" provider: id: "P1" descriptor: @@ -33,47 +33,47 @@ message: - type: "START" location: descriptor: - name: "kashmere gate" - code: "KASHMERE_GATE" + name: "MOCK_STATION_1" + code: "MOCK_STATION_1" gps: "28.666576, 77.233332" id: "1" - type: "INTERMEDIATE_STOP" location: descriptor: - name: "Indira Gandhi Technical Unviversity" - code: "INDIRA_GANDHI_TECHNICAL_UNIV" + name: "MOCK_STATION_2" + code: "MOCK_STATION_2" gps: "28.624097, 77.204991" id: "2" parent_stop_id: "1" - type: "INTERMEDIATE_STOP" location: descriptor: - name: "Yamuna Bazar" - code: "YAMUNA_BAZAR" + name: "MOCK_STATION_3" + code: "MOCK_STATION_3" gps: "28.625972,77.209917" id: "3" parent_stop_id: "2" - type: "INTERMEDIATE_STOP" location: descriptor: - name: "dhaula kuan" - code: "DHAULA_KUAN" + name: "MOCK_STATION_4" + code: "MOCK_STATION_4" gps: "28.610972,77.201717" id: "4" parent_stop_id: "3" - type: "INTERMEDIATE_STOP" location: descriptor: - name: "gpo" - code: "GPO" + name: "MOCK_STATION_5" + code: "MOCK_STATION_5" gps: "28.623097,77.209917" id: "5" parent_stop_id: "4" - type: "END" location: descriptor: - name: "Greater Kailash" - code: "GREATER_KAILASH" + name: "MOCK_STATION_6" + code: "MOCK_STATION_6" gps: "28.548230, 77.238039" id: "6" parent_stop_id: "5" diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search/default.yaml index 13960684..42a882d5 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search/default.yaml @@ -32,7 +32,7 @@ message: count: 1 time: label: "Validity" - duration: "PT2D" + duration: "P2D" timestamp: "2021-03-23T11:01:40.065Z" - id: "I2" descriptor: diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search/generator.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search/generator.ts index c3616b86..732bb87d 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search/generator.ts @@ -179,7 +179,7 @@ export async function onSearchGenerator( return { ...item, time: { - duration: "PT2D", + duration: "P2D", label: "Validity", timestamp: twoDaysFromNow.toISOString(), }, @@ -201,86 +201,6 @@ export async function onSearchGenerator( }; }, ), - { - id: "F3", - type: "TRIP", - stops: [ - { - type: "START", - location: { - descriptor: { - name: "kashmere gate", - code: "KASHMERE_GATE", - }, - gps: "28.666576, 77.233332", - }, - id: "1", - }, - { - type: "INTERMEDIATE_STOP", - instructions: { - name: "Stop 1", - }, - location: { - descriptor: { - name: "Indira Gandhi Technical Unviversity", - code: "INDIRA_GANDHI_TECHNICAL_UNIV", - }, - gps: "28.624097, 77.204991", - }, - id: "2", - parent_stop_id: "1", - }, - { - type: "END", - location: { - descriptor: { - name: "Greater Kailash", - code: "GREATER_KAILASH", - }, - gps: "28.548230, 77.238039", - }, - id: "3", - parent_stop_id: "2", - }, - ], - vehicle: { - category: "BUS", - }, - tags: [ - { - descriptor: { - code: "ROUTE_INFO", - }, - list: [ - { - descriptor: { - code: "ROUTE_ID", - }, - value: crypto.randomUUID().slice(0, 4), - }, - { - descriptor: { - code: "ROUTE_DIRECTION", - }, - value: "UP", - }, - { - descriptor: { - code: "OPERATIONAL_START_TIME", - }, - value: operationalStartTime.toISOString(), - }, - { - descriptor: { - code: "OPERATIONAL_END_TIME", - }, - value: operationalEndTime.toISOString(), - }, - ], - }, - ], - }, ]; return existingPayload; } catch (err) { diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default1.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default1.yaml index 825360d3..dded525c 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default1.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default1.yaml @@ -85,7 +85,7 @@ message: size_type: "xs" time: label: "Validity" - duration: "PT2D" + duration: "P2D" timestamp: "2021-03-23T11:01:40.065Z" - id: "I2" descriptor: diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default2.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default2.yaml index 7d293382..3f931fcb 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default2.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default2.yaml @@ -171,46 +171,46 @@ message: - id: "1" location: descriptor: - name: "kashmere gate" - code: "KASHMERE_GATE" + name: "MOCK_STATION_1" + code: "MOCK_STATION_1" gps: "28.666576, 77.233332" - id: "2" instructions: name: "Stop 1" location: descriptor: - name: "Indira Gandhi Technical Unviversity" - code: "INDIRA_GANDHI_TECHNICAL_UNIV" + name: "MOCK_STATION_2" + code: "MOCK_STATION_2" gps: "28.624097, 77.204991" - id: "3" instructions: name: "Stop 2" location: descriptor: - name: "Yamuna Bazar" - code: "YAMUNA_BAZAR" + name: "MOCK_STATION_3" + code: "MOCK_STATION_3" gps: "28.625972,77.209917" - id: "4" instructions: name: "Stop 3" location: descriptor: - name: "dhaula kuan" - code: "DHAULA_KUAN" + name: "MOCK_STATION_4" + code: "MOCK_STATION_4" gps: "28.610972,77.201717" - id: "5" instructions: name: "Stop 4" location: descriptor: - name: "gpo" - code: "GPO" + name: "MOCK_STATION_5" + code: "MOCK_STATION_5" gps: "28.623097,77.209917" - id: "6" location: descriptor: - name: "Greater Kailash" - code: "GREATER_KAILASH" + name: "MOCK_STATION_6" + code: "MOCK_STATION_6" gps: "28.548230, 77.238039" - id: "FT9" type: "TICKET" @@ -237,7 +237,7 @@ message: size_type: "xs" time: label: "Validity" - duration: "PT2D" + duration: "P2D" timestamp: "2021-03-23T11:01:40.065Z" - id: "I2" descriptor: diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default3.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default3.yaml index fb2e1645..57421028 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default3.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default3.yaml @@ -26,7 +26,7 @@ message: size_type: "xs" time: label: "Validity" - duration: "PT2D" + duration: "P2D" timestamp: "2021-03-23T11:01:40.065Z" - id: "I2" descriptor: @@ -262,46 +262,46 @@ message: - id: "1" location: descriptor: - name: "kashmere gate" - code: "KASHMERE_GATE" + name: "MOCK_STATION_1" + code: "MOCK_STATION_1" gps: "28.666576, 77.233332" - id: "2" instructions: name: "Stop 1" location: descriptor: - name: "Indira Gandhi Technical Unviversity" - code: "INDIRA_GANDHI_TECHNICAL_UNIV" + name: "MOCK_STATION_2" + code: "MOCK_STATION_2" gps: "28.624097, 77.204991" - id: "3" instructions: name: "Stop 2" location: descriptor: - name: "Yamuna Bazar" - code: "YAMUNA_BAZAR" + name: "MOCK_STATION_3" + code: "MOCK_STATION_3" gps: "28.625972,77.209917" - id: "4" instructions: name: "Stop 3" location: descriptor: - name: "dhaula kuan" - code: "DHAULA_KUAN" + name: "MOCK_STATION_4" + code: "MOCK_STATION_4" gps: "28.610972,77.201717" - id: "5" instructions: name: "Stop 4" location: descriptor: - name: "gpo" - code: "GPO" + name: "MOCK_STATION_5" + code: "MOCK_STATION_5" gps: "28.623097,77.209917" - id: "6" location: descriptor: - name: "Greater Kailash" - code: "GREATER_KAILASH" + name: "MOCK_STATION_6" + code: "MOCK_STATION_6" gps: "28.548230, 77.238039" - id: "FT9" type: "TICKET" diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default4.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default4.yaml index b9f06b10..811a6634 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default4.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_search/on_search_catalog/default4.yaml @@ -26,7 +26,7 @@ message: size_type: "xs" time: label: "Validity" - duration: "PT2D" + duration: "P2D" timestamp: "2021-03-23T11:01:40.065Z" - id: "I2" descriptor: @@ -262,46 +262,46 @@ message: - id: "1" location: descriptor: - name: "kashmere gate" - code: "KASHMERE_GATE" + name: "MOCK_STATION_1" + code: "MOCK_STATION_1" gps: "28.666576, 77.233332" - id: "2" instructions: name: "Stop 1" location: descriptor: - name: "Indira Gandhi Technical Unviversity" - code: "INDIRA_GANDHI_TECHNICAL_UNIV" + name: "MOCK_STATION_2" + code: "MOCK_STATION_2" gps: "28.624097, 77.204991" - id: "3" instructions: name: "Stop 2" location: descriptor: - name: "Yamuna Bazar" - code: "YAMUNA_BAZAR" + name: "MOCK_STATION_3" + code: "MOCK_STATION_3" gps: "28.625972,77.209917" - id: "4" instructions: name: "Stop 3" location: descriptor: - name: "dhaula kuan" - code: "DHAULA_KUAN" + name: "MOCK_STATION_4" + code: "MOCK_STATION_4" gps: "28.610972,77.201717" - id: "5" instructions: name: "Stop 4" location: descriptor: - name: "gpo" - code: "GPO" + name: "MOCK_STATION_5" + code: "MOCK_STATION_5" gps: "28.623097,77.209917" - id: "6" location: descriptor: - name: "Greater Kailash" - code: "GREATER_KAILASH" + name: "MOCK_STATION_6" + code: "MOCK_STATION_6" gps: "28.548230, 77.238039" - id: "FT9" type: "TICKET" diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_select/on_select_agent_activation/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_select/on_select_agent_activation/default.yaml index 262b4bb6..141cb14b 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_select/on_select_agent_activation/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_select/on_select_agent_activation/default.yaml @@ -27,47 +27,47 @@ message: - type: "START" location: descriptor: - name: "kashmere gate" - code: "KASHMERE_GATE" + name: "MOCK_STATION_1" + code: "MOCK_STATION_1" gps: "28.666576, 77.233332" id: "1" - type: "INTERMEDIATE_STOP" location: descriptor: - name: "Indira Gandhi Technical Unviversity" - code: "INDIRA_GANDHI_TECHNICAL_UNIV" + name: "MOCK_STATION_2" + code: "MOCK_STATION_2" gps: "28.624097, 77.204991" id: "2" parent_stop_id: "1" - type: "INTERMEDIATE_STOP" location: descriptor: - name: "Yamuna Bazar" - code: "YAMUNA_BAZAR" + name: "MOCK_STATION_3" + code: "MOCK_STATION_3" gps: "28.625972,77.209917" id: "3" parent_stop_id: "2" - type: "INTERMEDIATE_STOP" location: descriptor: - name: "dhaula kuan" - code: "DHAULA_KUAN" + name: "MOCK_STATION_4" + code: "MOCK_STATION_4" gps: "28.610972,77.201717" id: "4" parent_stop_id: "3" - type: "INTERMEDIATE_STOP" location: descriptor: - name: "gpo" - code: "GPO" + name: "MOCK_STATION_5" + code: "MOCK_STATION_5" gps: "28.623097,77.209917" id: "5" parent_stop_id: "4" - type: "END" location: descriptor: - name: "Greater Kailash" - code: "GREATER_KAILASH" + name: "MOCK_STATION_6" + code: "MOCK_STATION_6" gps: "28.548230, 77.238039" id: "6" parent_stop_id: "5" @@ -88,23 +88,23 @@ message: id: "1" location: descriptor: - name: "kashmere gate" - code: "KASHMERE_GATE" + name: "MOCK_STATION_1" + code: "MOCK_STATION_1" gps: "28.666576, 77.233332" - type: "INTERMEDIATE_STOP" id: "2" location: descriptor: - name: "Indira Gandhi Technical Unviversity" - code: "INDIRA_GANDHI_TECHNICAL_UNIV" + name: "MOCK_STATION_2" + code: "MOCK_STATION_2" gps: "28.624097, 77.204991" parent_stop_id: "1" - type: "END" - id: "6" + id: "3" location: descriptor: - name: "Greater Kailash" - code: "GREATER_KAILASH" + name: "MOCK_STATION_3" + code: "MOCK_STATION_3" gps: "28.548230, 77.238039" parent_stop_id: "2" vehicle: diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_base_order_update/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_base_order_update/default.yaml index 9f9de2f7..11cd4891 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_base_order_update/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_base_order_update/default.yaml @@ -20,7 +20,7 @@ message: value: "0" time: label: "Validity" - duration: "PT2D" + duration: "P2D" timestamp: "2021-03-23T11:01:40.065Z" provider: id: "P1" @@ -36,47 +36,47 @@ message: - type: "START" location: descriptor: - name: "kashmere gate" - code: "KASHMERE_GATE" + name: "MOCK_STATION_1" + code: "MOCK_STATION_1" gps: "28.666576, 77.233332" id: "1" - type: "INTERMEDIATE_STOP" location: descriptor: - name: "Indira Gandhi Technical Unviversity" - code: "INDIRA_GANDHI_TECHNICAL_UNIV" + name: "MOCK_STATION_2" + code: "MOCK_STATION_2" gps: "28.624097, 77.204991" id: "2" parent_stop_id: "1" - type: "INTERMEDIATE_STOP" location: descriptor: - name: "Yamuna Bazar" - code: "YAMUNA_BAZAR" + name: "MOCK_STATION_3" + code: "MOCK_STATION_3" gps: "28.625972,77.209917" id: "3" parent_stop_id: "2" - type: "INTERMEDIATE_STOP" location: descriptor: - name: "dhaula kuan" - code: "DHAULA_KUAN" + name: "MOCK_STATION_4" + code: "MOCK_STATION_4" gps: "28.610972,77.201717" id: "4" parent_stop_id: "3" - type: "INTERMEDIATE_STOP" location: descriptor: - name: "gpo" - code: "GPO" + name: "MOCK_STATION_5" + code: "MOCK_STATION_5" gps: "28.623097,77.209917" id: "5" parent_stop_id: "4" - type: "END" location: descriptor: - name: "Greater Kailash" - code: "GREATER_KAILASH" + name: "MOCK_STATION_6" + code: "MOCK_STATION_6" gps: "28.548230, 77.238039" id: "6" parent_stop_id: "5" diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_base_order_update/generator.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_base_order_update/generator.ts index 6e84d495..96f4fabd 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_base_order_update/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_base_order_update/generator.ts @@ -5,7 +5,7 @@ export async function onUpdateGenerator( sessionData: any, ) { const routeFulfillmentId = "F1"; - const duration = "PT2D"; + const duration = "P2D"; let validityEndDate = new Date(); const daysMatch = duration.match(/P(?:T)?(\d+)D/); if (daysMatch) { @@ -86,8 +86,8 @@ export async function onUpdateGenerator( type: "START", location: { descriptor: { - name: "kashmere gate", - code: "KASHMERE_GATE", + name: "MOCK_STATION_1", + code: "MOCK_STATION_1", }, gps: "28.666576, 77.233332", }, @@ -97,8 +97,8 @@ export async function onUpdateGenerator( type: "INTERMEDIATE_STOP", location: { descriptor: { - name: "Indira Gandhi Technical Unviversity", - code: "INDIRA_GANDHI_TECHNICAL_UNIV", + name: "MOCK_STATION_2", + code: "MOCK_STATION_2", }, gps: "28.624097, 77.204991", }, @@ -109,8 +109,8 @@ export async function onUpdateGenerator( type: "INTERMEDIATE_STOP", location: { descriptor: { - name: "Yamuna Bazar", - code: "YAMUNA_BAZAR", + name: "MOCK_STATION_3", + code: "MOCK_STATION_3", }, gps: "28.625972,77.209917", }, @@ -121,8 +121,8 @@ export async function onUpdateGenerator( type: "INTERMEDIATE_STOP", location: { descriptor: { - name: "dhaula kuan", - code: "DHAULA_KUAN", + name: "MOCK_STATION_4", + code: "MOCK_STATION_4", }, gps: "28.610972,77.201717", }, @@ -133,8 +133,8 @@ export async function onUpdateGenerator( type: "INTERMEDIATE_STOP", location: { descriptor: { - name: "gpo", - code: "GPO", + name: "MOCK_STATION_5", + code: "MOCK_STATION_5", }, gps: "28.623097,77.209917", }, @@ -145,8 +145,8 @@ export async function onUpdateGenerator( type: "END", location: { descriptor: { - name: "Greater Kailash", - code: "GREATER_KAILASH", + name: "MOCK_STATION_6", + code: "MOCK_STATION_6", }, gps: "28.548230, 77.238039", }, diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_vehicle/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_vehicle/default.yaml index b2d82c44..edb79d32 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_vehicle/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_vehicle/default.yaml @@ -1,7 +1,7 @@ message: order: id: O1 - status: ACTIVE + status: COMPLETED items: - id: I1 descriptor: diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_vehicle/generator.ts b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_vehicle/generator.ts index 36c459d4..6b6c48fb 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_vehicle/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_vehicle/generator.ts @@ -58,7 +58,7 @@ function transformFulfillments(fulfillments: any[], sessionData: any): any[] { descriptor: { code: "NUMBER", }, - value: buyerSideFulfillment.vehicle.registration || ticketNumber, + value: ticketNumber, }; if (ticketInfoTagIndex !== -1) { @@ -99,18 +99,28 @@ export async function onUpdateVehConGenerator( } if (sessionData.fulfillments.length > 0) { + let index = 0; + const updateFulfillment = sessionData?.update_fulfillment + ?.flat() + ?.map((f: any) => { + if (f.vehicle.registration) { + return f.vehicle.registration; + } + }); existingPayload.message.order.fulfillments = sessionData.fulfillments.map( (fulfillment) => { if (fulfillment.type === "TICKET") { + const registration = updateFulfillment[index] ?? "GL90"; + index++; return { ...fulfillment, vehicle: { category: "BUS", - registration: "GL90", + registration: registration ?? "GL90", }, }; } - return fulfillment + return fulfillment; }, ); existingPayload.message.order.fulfillments = transformFulfillments( diff --git a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_vehicle_qr/default.yaml b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_vehicle_qr/default.yaml index 772fc547..7f1c7ffd 100644 --- a/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_vehicle_qr/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/BUS/2.1.0/on_update/on_update_vehicle_qr/default.yaml @@ -1,7 +1,7 @@ message: order: id: O1 - status: ACTIVE + status: COMPLETED items: - id: I1 descriptor: diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/cancel/cancel_tech/class.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/cancel/cancel_tech/class.ts index 2e4d3dd5..bf3a8029 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/cancel/cancel_tech/class.ts +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/cancel/cancel_tech/class.ts @@ -46,7 +46,7 @@ export class MockCancelTechMetro210Class extends MockAction { }; } - if (descriptor?.code !== "CONFIRM_CANCEL") { + if (descriptor?.code !== "SOFT_CANCEL") { return { valid: false, message: "Incorrect descriptor code in the payload", diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/cancel/cancel_tech/default.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/cancel/cancel_tech/default.yaml index c6433d81..d35060d1 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/cancel/cancel_tech/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/cancel/cancel_tech/default.yaml @@ -2,5 +2,5 @@ message: cancellation_reason_id: '000' descriptor: name: Ride Cancellation - code: CONFIRM_CANCEL + code: SOFT_CANCEL order_id: O1 diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/confirm/confirm_unlimitedpass/class.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/confirm/confirm_unlimitedpass/class.ts new file mode 100644 index 00000000..af69e3ac --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/confirm/confirm_unlimitedpass/class.ts @@ -0,0 +1,108 @@ +import { readFileSync } from "fs"; +import yaml from "js-yaml"; +import path from "path"; +import { MockAction, MockOutput, saveType } from "../../../../classes/mock-action"; +import { confirmUnlimitedPassGenerator } from "./generator"; +import { SessionData } from "../../../../session-types"; + +export class MockConfirmMetroUnlimitedPass210Class extends MockAction { + get saveData(): saveType { + return yaml.load( + readFileSync(path.resolve(__dirname, "../save-data.yaml"), "utf8") + ) as saveType; + } + get defaultData(): any { + return yaml.load( + readFileSync(path.resolve(__dirname, "./default.yaml"), "utf8") + ); + } + get inputs(): any { + return {}; + } + name(): string { + return "confirm_METRO_UNLIMITEDPASS_210"; + } + get description(): string { + return "Mock for confirm_METRO_UNLIMITEDPASS_210"; + } + generator(existingPayload: any, sessionData: SessionData): Promise { + return confirmUnlimitedPassGenerator(existingPayload, sessionData); + } + async validate( + targetPayload: any, + sessionData: SessionData + ): Promise { + const items = targetPayload?.message?.order?.items || []; + const fulfillments = targetPayload?.message?.order?.fulfillments || []; + + // Extract all fulfillment ids from payload + const payloadFulfillmentIds = fulfillments.map((f: any) => f.id); + + for (const item of items) { + // 1. check item id in sessionData.selected_item_ids + if (!sessionData.selected_item_ids.includes(item.id)) { + return { + valid: false, + message: `Item id ${item.id} not found in sessionData.selected_item_ids: ${sessionData.selected_item_ids}`, + }; + } + + // 2. check item.fulfillment_ids are present in payload.fulfillments + const itemFulfillmentIds = item.fulfillment_ids || []; + if ( + !itemFulfillmentIds.every((fid: string) => + payloadFulfillmentIds.includes(fid) + ) + ) { + return { + valid: false, + message: `Item ${item.id} has invalid fulfillment ids. Expected subset of ${payloadFulfillmentIds}, got ${itemFulfillmentIds}`, + }; + } + + // 3. check quantity within min and max for that item in sessionData.items + const sessionItem = sessionData.items?.find((i: any) => i.id === item.id); + const selectedCount = item?.quantity?.selected?.count; + + if (!sessionItem) { + return { + valid: false, + message: `Item ${item.id} not found in sessionData.items`, + }; + } + + const min = sessionItem?.quantity?.minimum?.count ?? 1; + const max = sessionItem?.quantity?.maximum?.count ?? Infinity; + + if (selectedCount < min || selectedCount > max) { + return { + valid: false, + message: `Item ${item.id} quantity out of range. Expected between ${min} and ${max}, got ${selectedCount}`, + }; + } + } + + return { valid: true }; + } + async meetRequirements(sessionData: SessionData): Promise { + // Check for items + if (!sessionData.items || sessionData.items.length === 0) { + return { + valid: false, + message: "No items available in session data", + code: "MISSING_ITEMS", + }; + } + // Check for provider_id + if (!sessionData.provider_id) { + return { + valid: false, + message: "No provider_id available in session data", + code: "MISSING_PROVIDER_ID", + }; + } + + // All requirements satisfied + return { valid: true }; +} +} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/confirm/confirm_unlimitedpass/default.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/confirm/confirm_unlimitedpass/default.yaml new file mode 100644 index 00000000..4e13fbbe --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/confirm/confirm_unlimitedpass/default.yaml @@ -0,0 +1,92 @@ +message: + order: + items: + - id: I5 + quantity: + selected: + count: 1 + fulfillments: + - id: F2 + type: PASS + customer: + person: + creds: + - type: AADHAAR + id: "1234 5678 9193" + provider: + id: P1 + billing: + name: John Doe + email: john.doe@example.com + phone: "+91-9897867564" + payments: + - id: PA1 + collected_by: BAP + status: PAID + type: PRE-ORDER + params: + transaction_id: 34cc9b0b-6887-4c63-8397-2f4fcf03e50d + currency: INR + amount: "50" + tags: + - descriptor: + code: BAP_TERMS + name: BAP Terms of Engagemen + display: false + list: + - descriptor: + code: BUYER_FINDER_FEES_PERCENTAGE + value: "1" + - descriptor: + code: SETTLEMENT_AMOUNT + value: "59" + - descriptor: + code: SETTLEMENT_TYPE + value: NEFT + - descriptor: + code: DELAY_INTEREST + value: "2.5" + - descriptor: + code: STATIC_TERMS + value: https://api.example-bap.com/booking/terms + - descriptor: + code: MANDATORY_ARBITRATION + value: "true" + - descriptor: + code: COURT_JURISDICTION + value: New Delhi + - descriptor: + code: BPP_TERMS + name: BPP Terms of Engagement + display: false + list: + - descriptor: + code: BUYER_FINDER_FEES_PERCENTAGE + value: "1" + - descriptor: + code: SETTLEMENT_WINDOW + value: P30D + - descriptor: + code: SETTLEMENT_BASIS + value: INVOICE_RECEIPT + - descriptor: + code: MANDATORY_ARBITRATION + value: "TRUE" + - descriptor: + code: COURT_JURISDICTION + value: New Delhi + - descriptor: + code: STATIC_TERMS + value: https://api.example-bpp.com/booking/terms + - descriptor: + code: SETTLEMENT_AMOUNT + value: "59" + - descriptor: + code: SETTLEMENT_TYPE + value: NEFT + - descriptor: + code: SETTLEMENT_BANK_CODE + value: XXXXXXXX + - descriptor: + code: SETTLEMENT_BANK_ACCOUNT_NUMBER + value: xxxxxxxxxxxxxx diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/confirm/confirm_unlimitedpass/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/confirm/confirm_unlimitedpass/generator.ts new file mode 100644 index 00000000..c505a574 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/confirm/confirm_unlimitedpass/generator.ts @@ -0,0 +1,52 @@ +import { v4 as uuidv4 } from "uuid"; + +const transformPaymentsToPaid = ( + payments: any, + amount: any, + currency = "INR", +) => { + return payments.map((payment: any) => ({ + ...payment, + status: "PAID", + params: { + transaction_id: uuidv4(), // Generates a UUID for transaction_id + currency, + amount, + }, + })); +}; +export async function confirmUnlimitedPassGenerator( + existingPayload: any, + sessionData: any, +) { + existingPayload.context.location.city.code = + sessionData?.select_city_code ?? "std:080"; + existingPayload.message.order.billing = sessionData.billing ?? {}; + + if (sessionData.selected_items && sessionData.selected_items.length > 0) { + existingPayload.message.order.items = sessionData?.init_items?.flat() ?? []; + } + if (sessionData.provider_id) { + existingPayload.message.order.provider.id = sessionData.provider_id; + } + if (sessionData.payments) { + existingPayload.message.order.payments = transformPaymentsToPaid( + sessionData.payments, + sessionData.price, + ); + } + + existingPayload.message.order.fulfillments = + sessionData?.buyer_side_fulfillment_ids?.flat() ?? []; + + const onlyBpp_terms = sessionData?.on_init_tags + ?.flat() + ?.filter((item: any) => { + return item.descriptor.code === "BPP_TERMS"; + }); + existingPayload.message.order.tags = [ + ...sessionData?.init_tags?.flat(), + ...onlyBpp_terms, + ]; + return existingPayload; +} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/confirm/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/confirm/generator.ts index 44a02089..0a35bd65 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/confirm/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/confirm/generator.ts @@ -41,6 +41,14 @@ export async function confirmGenerator(existingPayload: any, sessionData: any) { (tag: any) => tag?.descriptor?.code === "BAP_TERMS", ); + const onInitBapTerms = sessionData.on_init_tags.flat()?.find( + (tag: any) => tag?.descriptor?.code === "BPP_TERMS", + ); + + const settlementWindowValue = onInitBapTerms?.list?.find( + (item: any) => item?.descriptor?.code === "SETTLEMENT_WINDOW", + )?.value; + if (bapTermsTag && bapTermsTag.list) { const hasSettlementWindow = bapTermsTag.list.some( (item: any) => item?.descriptor?.code === "SETTLEMENT_WINDOW", @@ -52,7 +60,7 @@ export async function confirmGenerator(existingPayload: any, sessionData: any) { descriptor: { code: "SETTLEMENT_WINDOW", }, - value: "PT60M", + value: settlementWindowValue ?? "P30D", }, { descriptor: { diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/init/init_unlimitedpass/class.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/init/init_unlimitedpass/class.ts new file mode 100644 index 00000000..b9ce8779 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/init/init_unlimitedpass/class.ts @@ -0,0 +1,108 @@ +import { readFileSync } from "fs"; +import yaml from "js-yaml"; +import path from "path"; +import { MockAction, MockOutput, saveType } from "../../../../classes/mock-action"; +import { initUnlimitedPassGenerator } from "./generator"; +import { SessionData } from "../../../../session-types"; + +export class MockInitMetroUnlimitedPass210Class extends MockAction { + get saveData(): saveType { + return yaml.load( + readFileSync(path.resolve(__dirname, "../save-data.yaml"), "utf8") + ) as saveType; + } + get defaultData(): any { + return yaml.load( + readFileSync(path.resolve(__dirname, "./default.yaml"), "utf8") + ); + } + get inputs(): any { + return {}; + } + name(): string { + return "init_METRO_UNLIMITEDPASS_210"; + } + get description(): string { + return "Mock for init_METRO_UNLIMITEDPASS_210"; + } + generator(existingPayload: any, sessionData: SessionData): Promise { + return initUnlimitedPassGenerator(existingPayload, sessionData); + } + async validate( + targetPayload: any, + sessionData: SessionData + ): Promise { + const items = targetPayload?.message?.order?.items || []; + const fulfillments = targetPayload?.message?.order?.fulfillments || []; + + // Extract all fulfillment ids from payload + const payloadFulfillmentIds = fulfillments.map((f: any) => f.id); + + for (const item of items) { + // 1. check item id in sessionData.selected_item_ids + if (!sessionData.selected_item_ids.includes(item.id)) { + return { + valid: false, + message: `Item id ${item.id} not found in sessionData.selected_item_ids: ${sessionData.selected_item_ids}`, + }; + } + + // 2. check item.fulfillment_ids are present in payload.fulfillments + const itemFulfillmentIds = item.fulfillment_ids || []; + if ( + !itemFulfillmentIds.every((fid: string) => + payloadFulfillmentIds.includes(fid) + ) + ) { + return { + valid: false, + message: `Item ${item.id} has invalid fulfillment ids. Expected subset of ${payloadFulfillmentIds}, got ${itemFulfillmentIds}`, + }; + } + + // 3. check quantity within min and max for that item in sessionData.items + const sessionItem = sessionData.items?.find((i: any) => i.id === item.id); + const selectedCount = item?.quantity?.selected?.count; + + if (!sessionItem) { + return { + valid: false, + message: `Item ${item.id} not found in sessionData.items`, + }; + } + + const min = sessionItem?.quantity?.minimum?.count ?? 1; + const max = sessionItem?.quantity?.maximum?.count ?? Infinity; + + if (selectedCount < min || selectedCount > max) { + return { + valid: false, + message: `Item ${item.id} quantity out of range. Expected between ${min} and ${max}, got ${selectedCount}`, + }; + } + } + + return { valid: true }; + } + async meetRequirements(sessionData: SessionData): Promise { + // Check for items + if (!sessionData.items || sessionData.items.length === 0) { + return { + valid: false, + message: "No items available in session data", + code: "MISSING_ITEMS", + }; + } + // Check for provider_id + if (!sessionData.provider_id) { + return { + valid: false, + message: "No provider_id available in session data", + code: "MISSING_PROVIDER_ID", + }; + } + + // All requirements satisfied + return { valid: true }; +} +} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/init/init_unlimitedpass/default.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/init/init_unlimitedpass/default.yaml new file mode 100644 index 00000000..3cd5edfb --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/init/init_unlimitedpass/default.yaml @@ -0,0 +1,52 @@ +message: + order: + items: + - id: I5 + quantity: + selected: + count: 1 + fulfillments: + - id: F2 + type: PASS + customer: + person: + creds: + - type: AADHAAR + id: "1234 5678 9193" + provider: + id: P1 + billing: + name: John Doe + email: john.doe@example.com + phone: "+91-9897867564" + payments: + - collected_by: BAP + status: NOT-PAID + type: PRE-ORDER + tags: + - descriptor: + code: BAP_TERMS + name: BAP Terms of Engagemen + display: false + list: + - descriptor: + code: BUYER_FINDER_FEES_PERCENTAGE + value: "1" + - descriptor: + code: SETTLEMENT_AMOUNT + value: "59" + - descriptor: + code: SETTLEMENT_TYPE + value: NEFT + - descriptor: + code: DELAY_INTEREST + value: "2.5" + - descriptor: + code: STATIC_TERMS + value: https://api.example-bap.com/booking/terms + - descriptor: + code: MANDATORY_ARBITRATION + value: "true" + - descriptor: + code: COURT_JURISDICTION + value: New Delhi diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/init/init_unlimitedpass/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/init/init_unlimitedpass/generator.ts new file mode 100644 index 00000000..f43f497d --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/init/init_unlimitedpass/generator.ts @@ -0,0 +1,58 @@ +import { SessionData } from "../../../../session-types"; + +export async function initUnlimitedPassGenerator( + existingPayload: any, + sessionData: any, +) { + existingPayload.context.location.city.code = + sessionData?.select_city_code ?? "std:080"; + existingPayload.message.order.provider.id = + sessionData?.provider_id ?? "Provider1"; + existingPayload.message.order.items = + sessionData?.selected_unlimitedpass_item?.flat() ?? []; + existingPayload.message.order.fulfillments = + sessionData?.selected_unlimitedpass_fulfillments?.flat() ?? []; + existingPayload.message.order.payments[0].collected_by = + sessionData.collected_by; + + //______SETTLEMENT_AMOUNT____________ + const tags = existingPayload?.message?.order?.tags; + if (!tags) return; + + const collectedBy = sessionData?.collected_by; + const price = Number(sessionData?.quote?.price?.value ?? 0); + + const buyerFinderFeesTag = tags?.find( + (tag: any) => tag?.descriptor?.code === "BAP_TERMS", + ); + + const feePercentage = Number( + buyerFinderFeesTag?.list?.find( + (item: any) => item?.descriptor?.code === "BUYER_FINDER_FEES_PERCENTAGE", + )?.value ?? 0, + ); + + const feeAmount = (price * feePercentage) / 100; + + let settlementAmount = 0; + if (collectedBy === "BAP") { + settlementAmount = price - feeAmount; + } else if (collectedBy === "BPP") { + settlementAmount = feeAmount; + } else { + settlementAmount = price; + } + + const settlementTermsTag = tags?.find( + (tag: any) => tag?.descriptor?.code === "BAP_TERMS", + ); + + const settlementAmountItem = settlementTermsTag?.list?.find( + (item: any) => item?.descriptor?.code === "SETTLEMENT_AMOUNT", + ); + + if (settlementAmountItem) { + settlementAmountItem.value = settlementAmount.toString(); + } + return existingPayload; +} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/issue/issue_100/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/issue/issue_100/generator.ts index c9d93a27..cdbbf224 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/issue/issue_100/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/issue/issue_100/generator.ts @@ -20,7 +20,7 @@ export const issueStatusGenerator_100 = async ( case "issue_open": existingPayload.message.issue.id = "ISSUE-1"; existingPayload.message.issue.category = "FULFILLMENT"; - existingPayload.message.issue.sub_category = "FLM112"; + existingPayload.message.issue.sub_category = "FLM101"; existingPayload.message.issue.complainant_info = { person: { name: "John Doe", diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_cancel/on_cancel_soft_technical/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_cancel/on_cancel_soft_technical/generator.ts index 6392fd3f..69f736e7 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_cancel/on_cancel_soft_technical/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_cancel/on_cancel_soft_technical/generator.ts @@ -220,7 +220,7 @@ function applyCancellation(quote: Quote, cancellationCharges: number): Quote { function removeTicketStops(order: any) { if (!order.fulfillments || !Array.isArray(order.fulfillments)) return order; - order.fulfillments = order.fulfillments + order.fulfillments = order.fulfillments; return order; } @@ -239,7 +239,22 @@ export async function onCancelSoftTechnicalGenerator( if (sessionData.fulfillments.length > 0) { existingPayload.message.order.fulfillments = sessionData.fulfillments; - + if (sessionData?.flow_id === "TECHNICAL_CANCELLATION_FLOW") { + existingPayload.message.order.fulfillments = + existingPayload.message.order.fulfillments?.map((f: any) => { + if (f.type === "TICKET") { + return { + ...f, + state: { + descriptor: { + code: "INACTIVE", + }, + }, + }; + } + return f; + }); + } existingPayload.message.order = removeTicketStops( existingPayload.message.order, ); @@ -267,7 +282,7 @@ export async function onCancelSoftTechnicalGenerator( } const now = new Date().toISOString(); existingPayload.message.order.created_at = sessionData.created_at; - existingPayload.message.order.tags = sessionData?.tags?.flat() + existingPayload.message.order.tags = sessionData?.tags?.flat(); //______SETTLEMENT_AMOUNT____________ const tags = existingPayload?.message?.order?.tags; @@ -320,7 +335,7 @@ export async function onCancelSoftTechnicalGenerator( if (settlementAmountItemBpp) { settlementAmountItemBpp.value = settlementAmount.toString(); } - + existingPayload.message.order.updated_at = now; return existingPayload; } diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_confirm/on_confirm_unlimitedpass/class.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_confirm/on_confirm_unlimitedpass/class.ts new file mode 100644 index 00000000..ce02fb71 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_confirm/on_confirm_unlimitedpass/class.ts @@ -0,0 +1,108 @@ +import { readFileSync } from "fs"; +import yaml from "js-yaml"; +import path from "path"; +import { MockAction, MockOutput, saveType } from "../../../../classes/mock-action"; +import { onConfirmUnlimitedPassGenerator } from "./generator"; +import { SessionData } from "../../../../session-types"; + +export class MockOnConfirmMetroUnlimitedPass210Class extends MockAction { + get saveData(): saveType { + return yaml.load( + readFileSync(path.resolve(__dirname, "../save-data.yaml"), "utf8") + ) as saveType; + } + get defaultData(): any { + return yaml.load( + readFileSync(path.resolve(__dirname, "./default.yaml"), "utf8") + ); + } + get inputs(): any { + return {}; + } + name(): string { + return "on_confirm_METRO_UNLIMITEDPASS_210"; + } + get description(): string { + return "Mock for on_confirm_METRO_UNLIMITEDPASS_210"; + } + generator(existingPayload: any, sessionData: SessionData): Promise { + return onConfirmUnlimitedPassGenerator(existingPayload, sessionData); + } + async validate( + targetPayload: any, + sessionData: SessionData + ): Promise { + const items = targetPayload?.message?.order?.items || []; + const fulfillments = targetPayload?.message?.order?.fulfillments || []; + + // Extract all fulfillment ids from payload + const payloadFulfillmentIds = fulfillments.map((f: any) => f.id); + + for (const item of items) { + // 1. check item id in sessionData.selected_item_ids + if (!sessionData.selected_item_ids.includes(item.id)) { + return { + valid: false, + message: `Item id ${item.id} not found in sessionData.selected_item_ids: ${sessionData.selected_item_ids}`, + }; + } + + // 2. check item.fulfillment_ids are present in payload.fulfillments + const itemFulfillmentIds = item.fulfillment_ids || []; + if ( + !itemFulfillmentIds.every((fid: string) => + payloadFulfillmentIds.includes(fid) + ) + ) { + return { + valid: false, + message: `Item ${item.id} has invalid fulfillment ids. Expected subset of ${payloadFulfillmentIds}, got ${itemFulfillmentIds}`, + }; + } + + // 3. check quantity within min and max for that item in sessionData.items + const sessionItem = sessionData.items?.find((i: any) => i.id === item.id); + const selectedCount = item?.quantity?.selected?.count; + + if (!sessionItem) { + return { + valid: false, + message: `Item ${item.id} not found in sessionData.items`, + }; + } + + const min = sessionItem?.quantity?.minimum?.count ?? 1; + const max = sessionItem?.quantity?.maximum?.count ?? Infinity; + + if (selectedCount < min || selectedCount > max) { + return { + valid: false, + message: `Item ${item.id} quantity out of range. Expected between ${min} and ${max}, got ${selectedCount}`, + }; + } + } + + return { valid: true }; + } + async meetRequirements(sessionData: SessionData): Promise { + // Check for items + if (!sessionData.items || sessionData.items.length === 0) { + return { + valid: false, + message: "No items available in session data", + code: "MISSING_ITEMS", + }; + } + // Check for provider_id + if (!sessionData.provider_id) { + return { + valid: false, + message: "No provider_id available in session data", + code: "MISSING_PROVIDER_ID", + }; + } + + // All requirements satisfied + return { valid: true }; +} +} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_confirm/on_confirm_unlimitedpass/default.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_confirm/on_confirm_unlimitedpass/default.yaml new file mode 100644 index 00000000..75f45945 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_confirm/on_confirm_unlimitedpass/default.yaml @@ -0,0 +1,407 @@ +message: + order: + id: 077b248f + status: ACTIVE + items: + - id: I5 + descriptor: + name: Daily Pass + code: PASS + images: + - url: "https://delhimetrorail.com/logos/logo.ico'" + size_type: xs + category_ids: + - C2 + fulfillment_ids: + - F2 + price: + currency: INR + value: "50" + quantity: + selected: + count: 1 + time: + label: Validity + duration: P1D + timestamp: "2026-01-23T11:01:40.065Z" + range: + start: "2026-01-23T11:01:40.065Z" + end: "2026-01-24T11:01:40.065Z" + provider: + id: P1 + descriptor: + name: Delhi Metro Rail Limited + images: + - url: https://delhimetrorail.com/logos/logo.ico + time: + range: + start: "2026-01-14T05:30:00.000Z" + end: "2026-01-14T23:30:00.000Z" + fulfillments: + - id: F2 + type: PASS + customer: + person: + creds: + - type: AADHAAR + id: "1234 5678 9193" + stops: + - type: START + location: + descriptor: + name: Shaheed Sthal(New Bus Adda) + code: SHAHEED_STHAL + gps: "28.686576, 77.441632" + id: "1" + authorization: + type: QR + token: aMOPw0KGgoAAAANSUhEUgAAAH0AAAB9AQAAAACn+1GINAAApklEQVR4Xu2UMQ4EMQgD/QP+/0vK6zjsvayUMmavWxQpMAUBkwS12wcveAAkgNSCD3rR5Lkgoai3GUCMgWqbAEYR3HxAkZlzU/0MyBisYRsgI1ERFfcpBpA+ze6k56Cj7KTdXNigFWZvSOpsgqLfd18i2aAukXh9TXBNmdWt5gzA/oqzWkkN8HtA7G8CNOwYAiZt3wZixUfkA32OHNQq7Bxs9oI/gC/9fV8AVCkPjQAAAABJRU5ErkJggg== + valid_to: "2024-07-23T23:59:59.999Z" + status: UNCLAIMED + - type: INTERMEDIATE_STOP + instructions: + name: Stop 1 + location: + descriptor: + name: Hindon River + code: HINDON_RIVER + gps: "28.686176, 77.442632" + id: "2" + parent_stop_id: "1" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 2 + location: + descriptor: + name: Arthala + gps: "28.181276, 77.442332" + id: "3" + parent_stop_id: "2" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 3 + location: + descriptor: + name: Mohan Nagar + gps: "28.981276, 77.772332" + id: "4" + parent_stop_id: "3" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 4 + location: + descriptor: + name: Shyam Park + gps: "28.620976, 77.046732" + id: "5" + parent_stop_id: "4" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 5 + location: + descriptor: + name: Major Mohit Sharma Rajendra Nagar + gps: "28.120976, 77.946732" + id: "6" + parent_stop_id: "5" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 6 + location: + descriptor: + name: Raj Bagh + gps: "28.677076, 77.346632" + id: "7" + parent_stop_id: "6" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 7 + location: + descriptor: + name: Shaheed Nagar + gps: "28.617076, 77.146632" + id: "8" + parent_stop_id: "7" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 8 + location: + descriptor: + name: Dilshad Garden + gps: "28.917076, 77.146632" + id: "9" + parent_stop_id: "8" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 9 + location: + descriptor: + name: Jhilmil + gps: "28.897076, 77.146632" + id: "10" + parent_stop_id: "9" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 10 + location: + descriptor: + name: Mansarovar Park + gps: "28.117076, 77.116632" + id: "11" + parent_stop_id: "10" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 11 + location: + descriptor: + name: Shahdara + gps: "28.127076, 77.416632" + id: "12" + parent_stop_id: "11" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 12 + location: + descriptor: + name: Welcome + gps: "28.217076, 77.216632" + id: "13" + parent_stop_id: "12" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 13 + location: + descriptor: + name: Seelampur + gps: "28.327076, 77.416632" + id: "14" + parent_stop_id: "13" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 14 + location: + descriptor: + name: Shastri Park + gps: "28.427076, 77.446632" + id: "15" + parent_stop_id: "14" + - type: TRANSIT_STOP + instructions: + name: Stop 15 + short_desc: Please Change here for Yellow Line + location: + descriptor: + name: Kashmere Gate + gps: "28.738426, 77.139922" + id: "16" + parent_stop_id: "15" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 16 + location: + descriptor: + name: Civil Lines + gps: "28.627076, 77.646632" + id: "17" + parent_stop_id: "16" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 17 + location: + descriptor: + name: Vidhan Sabha + gps: "28.727076, 77.746632" + id: "18" + parent_stop_id: "17" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 18 + location: + descriptor: + name: Vishwavidyalaya + gps: "28.827076, 77.846632" + id: "19" + parent_stop_id: "18" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 19 + location: + descriptor: + name: Guru Tegh Bahadur Nagar + gps: "28.927076, 77.946632" + id: "20" + parent_stop_id: "19" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 20 + location: + descriptor: + name: Model Town + gps: "28.217076, 77.496632" + id: "21" + parent_stop_id: "20" + - type: END + location: + descriptor: + name: Azadpur + code: AZADPUR + gps: "28.707358, 77.180910" + id: "22" + parent_stop_id: "21" + vehicle: + category: METRO + tags: + - descriptor: + code: ROUTE_INFO + list: + - descriptor: + code: ROUTE_ID + value: "242" + - descriptor: + code: ROUTE_NAME + value: Yellow Line + billing: + name: John Doe + email: john.doe@example.com + phone: "+91-9897867564" + payments: + - id: PA1 + collected_by: BAP + status: PAID + type: PRE-ORDER + params: + transaction_id: 34cc9b0b-6887-4c63-8397-2f4fcf03e50d + currency: INR + amount: "50" + cancellation_terms: + - external_ref: + mimetype: text/html + url: https://transitsolutions.com/mf/tnc.html + quote: + price: + value: "50" + currency: INR + breakup: + - title: BASE_FARE + item: + id: I5 + price: + currency: INR + value: "50" + quantity: + selected: + count: 1 + price: + currency: INR + value: "50" + - title: TAX + price: + currency: INR + value: "0" + item: + tags: + - descriptor: + code: TAX + list: + - descriptor: + code: CGST + value: "0" + - descriptor: + code: SGST + value: "0" + - title: OTHER_CHARGES + price: + currency: INR + value: "0" + item: + tags: + - descriptor: + code: OTHER_CHARGES + list: + - descriptor: + code: SURCHARGE + value: "0" + tags: + - descriptor: + code: BAP_TERMS + name: BAP Terms of Engagemen + display: false + list: + - descriptor: + code: BUYER_FINDER_FEES_PERCENTAGE + value: "1" + - descriptor: + code: SETTLEMENT_WINDOW + value: PT60M + - descriptor: + code: SETTLEMENT_BASIS + value: Delivery + - descriptor: + code: SETTLEMENT_TYPE + value: NEFT + - descriptor: + code: MANDATORY_ARBITRATION + value: "true" + - descriptor: + code: COURT_JURISDICTION + value: New Delhi + - descriptor: + code: DELAY_INTEREST + value: "2.5" + - descriptor: + code: STATIC_TERMS + value: https://www.abc.com/settlement-terms/ + - descriptor: + code: SETTLEMENT_AMOUNT + value: "59" + - descriptor: + code: BPP_TERMS + name: BPP Terms of Engagement + display: false + list: + - descriptor: + code: BUYER_FINDER_FEES_PERCENTAGE + value: "1" + - descriptor: + code: SETTLEMENT_WINDOW + value: P30D + - descriptor: + code: SETTLEMENT_BASIS + value: INVOICE_RECEIPT + - descriptor: + code: MANDATORY_ARBITRATION + value: "TRUE" + - descriptor: + code: COURT_JURISDICTION + value: New Delhi + - descriptor: + code: STATIC_TERMS + value: https://api.example-bpp.com/booking/terms + - descriptor: + code: SETTLEMENT_AMOUNT + value: "59" + - descriptor: + code: SETTLEMENT_TYPE + value: NEFT + - descriptor: + code: SETTLEMENT_BANK_CODE + value: XXXXXXXX + - descriptor: + code: SETTLEMENT_BANK_ACCOUNT_NUMBER + value: xxxxxxxxxxxxxx + - descriptor: + code: ADDITIONAL_APIS + display: false + list: + - descriptor: + code: GTFS_RT + value: https://metro-transit/gtfs-realtime + - descriptor: + code: GTFS_ST + value: https://metro-transit/gtfs-static + - descriptor: + code: WALLET_BALANCE_CHECK + name: The CARD_NUMBER represents the Metro card number and is used to check the wallet balance via the API. + value: https://metro-transit/wallet/balance/{CARD_NUMBER} + created_at: "2026-01-23T10:00:40.065Z" + updated_at: "2026-01-23T10:00:40.065Z" diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_confirm/on_confirm_unlimitedpass/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_confirm/on_confirm_unlimitedpass/generator.ts new file mode 100644 index 00000000..8742c7c8 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_confirm/on_confirm_unlimitedpass/generator.ts @@ -0,0 +1,92 @@ +import { randomBytes } from "crypto"; +import { SessionData } from "../../../../session-types"; + +function generateQrToken(): string { + return randomBytes(32).toString("base64"); +} + +export async function onConfirmUnlimitedPassGenerator( + existingPayload: any, + sessionData: SessionData, +) { + existingPayload.context.location.city.code = + sessionData?.select_city_code ?? "std:080"; + const qrToken = generateQrToken(); + const now = new Date(); + const istOffset = 5.5 * 60 * 60 * 1000; + const istNow = new Date(now.getTime() + istOffset); + const y = istNow.getFullYear(); + const m = istNow.getMonth(); + const d = istNow.getDate(); + const currentDate = new Date().toISOString(); + const endIST = new Date(Date.UTC(y, m, d + 1, 4 - 5, 30 - 30, 0)); + const validTo = endIST.toISOString(); + const orderId = Math.random().toString(36).substring(2, 15); + existingPayload.message.order.id = orderId; + existingPayload.message.order.provider = sessionData.provider; + existingPayload.message.order.items = sessionData?.items.flat() ?? []; + existingPayload.message.order.fulfillments = + sessionData?.fulfillments?.map((fulfillment: any) => { + return { + ...fulfillment, + stops: fulfillment?.stops?.map((stop: any) => { + if (stop.type === "START") { + return { + ...stop, + authorization: { + type: "QR", + token: qrToken, + valid_to: validTo, + status: "UNCLAIMED", + }, + }; + } + return stop; + }), + }; + }) ?? []; + + existingPayload.message.order.cancellation_terms = + sessionData?.cancellation_terms?.flat() ?? []; + existingPayload.message.order.quote = sessionData?.quote ?? {}; + existingPayload.message.order.billing = sessionData?.billing ?? {}; + existingPayload.message.order.payments = + sessionData?.updated_payments?.flat() ?? []; + existingPayload.message.order.created_at = currentDate; + existingPayload.message.order.updated_at = currentDate; + const allTags = [ + ...(sessionData?.init_tags?.flat() ?? []), + ...(sessionData?.on_init_tags?.flat() ?? []), + ]; + + const bppTerms = allTags.find( + (tag: any) => tag?.descriptor?.code === "BPP_TERMS", + ); + + const settlementWindowObj = bppTerms?.list?.find( + (item: any) => item?.descriptor?.code === "SETTLEMENT_WINDOW", + ); + + const updatedTags = allTags.map((tag: any) => { + if (tag?.descriptor?.code === "BAP_TERMS" && settlementWindowObj) { + return { + ...tag, + list: [ + ...tag.list, + settlementWindowObj, + { + descriptor: { + code: "SETTLEMENT_BASIS", + }, + value: "Delivery", + }, + ], + }; + } + return tag; + }); + + existingPayload.message.order.tags = updatedTags; + + return existingPayload; +} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/generator.ts index 79799d07..496041fb 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/generator.ts @@ -70,7 +70,11 @@ export async function onInitGenerator( }, display: false, list: [ - ...sessionData?.init_tags?.flat()[0]?.list, + ...(sessionData?.init_tags + ?.flat()[0] + ?.list?.filter( + (item: any) => item?.descriptor?.code !== "DELAY_INTEREST", + ) || []), { descriptor: { code: "SETTLEMENT_WINDOW", @@ -89,6 +93,12 @@ export async function onInitGenerator( }, value: "xxxxxxxxxxxxxx", }, + { + descriptor: { + code: "SETTLEMENT_BASIS", + }, + value: "INVOICE_RECEIPT", + }, ], }, ...sessionData.select_tags.flat(), diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/on_init_recharge/default.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/on_init_recharge/default.yaml index acfa1e1c..28cbea48 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/on_init_recharge/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/on_init_recharge/default.yaml @@ -118,7 +118,7 @@ message: value: 7 INR - descriptor: code: SETTLEMENT_TYPE - value: upi + value: NEFT - descriptor: code: SETTLEMENT_BANK_CODE value: XXXXXXXX diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/on_init_unlimitedpass/class.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/on_init_unlimitedpass/class.ts new file mode 100644 index 00000000..04178b75 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/on_init_unlimitedpass/class.ts @@ -0,0 +1,108 @@ +import { readFileSync } from "fs"; +import yaml from "js-yaml"; +import path from "path"; +import { MockAction, MockOutput, saveType } from "../../../../classes/mock-action"; +import { onInitUnlimitedPassGenerator } from "./generator"; +import { SessionData } from "../../../../session-types"; + +export class MockOnInitMetroUnlimitedPass210Class extends MockAction { + get saveData(): saveType { + return yaml.load( + readFileSync(path.resolve(__dirname, "../save-data.yaml"), "utf8") + ) as saveType; + } + get defaultData(): any { + return yaml.load( + readFileSync(path.resolve(__dirname, "./default.yaml"), "utf8") + ); + } + get inputs(): any { + return {}; + } + name(): string { + return "on_init_METRO_UNLIMITEDPASS_210"; + } + get description(): string { + return "Mock for on_init_METRO_UNLIMITEDPASS_210"; + } + generator(existingPayload: any, sessionData: SessionData): Promise { + return onInitUnlimitedPassGenerator(existingPayload, sessionData); + } + async validate( + targetPayload: any, + sessionData: SessionData + ): Promise { + const items = targetPayload?.message?.order?.items || []; + const fulfillments = targetPayload?.message?.order?.fulfillments || []; + + // Extract all fulfillment ids from payload + const payloadFulfillmentIds = fulfillments.map((f: any) => f.id); + + for (const item of items) { + // 1. check item id in sessionData.selected_item_ids + if (!sessionData.selected_item_ids.includes(item.id)) { + return { + valid: false, + message: `Item id ${item.id} not found in sessionData.selected_item_ids: ${sessionData.selected_item_ids}`, + }; + } + + // 2. check item.fulfillment_ids are present in payload.fulfillments + const itemFulfillmentIds = item.fulfillment_ids || []; + if ( + !itemFulfillmentIds.every((fid: string) => + payloadFulfillmentIds.includes(fid) + ) + ) { + return { + valid: false, + message: `Item ${item.id} has invalid fulfillment ids. Expected subset of ${payloadFulfillmentIds}, got ${itemFulfillmentIds}`, + }; + } + + // 3. check quantity within min and max for that item in sessionData.items + const sessionItem = sessionData.items?.find((i: any) => i.id === item.id); + const selectedCount = item?.quantity?.selected?.count; + + if (!sessionItem) { + return { + valid: false, + message: `Item ${item.id} not found in sessionData.items`, + }; + } + + const min = sessionItem?.quantity?.minimum?.count ?? 1; + const max = sessionItem?.quantity?.maximum?.count ?? Infinity; + + if (selectedCount < min || selectedCount > max) { + return { + valid: false, + message: `Item ${item.id} quantity out of range. Expected between ${min} and ${max}, got ${selectedCount}`, + }; + } + } + + return { valid: true }; + } + async meetRequirements(sessionData: SessionData): Promise { + // Check for items + if (!sessionData.items || sessionData.items.length === 0) { + return { + valid: false, + message: "No items available in session data", + code: "MISSING_ITEMS", + }; + } + // Check for provider_id + if (!sessionData.provider_id) { + return { + valid: false, + message: "No provider_id available in session data", + code: "MISSING_PROVIDER_ID", + }; + } + + // All requirements satisfied + return { valid: true }; +} +} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/on_init_unlimitedpass/default.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/on_init_unlimitedpass/default.yaml new file mode 100644 index 00000000..a12e3fcd --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/on_init_unlimitedpass/default.yaml @@ -0,0 +1,362 @@ +message: + order: + items: + - id: I5 + descriptor: + name: Daily Pass + code: PASS + images: + - url: "https://delhimetrorail.com/logos/logo.ico'" + size_type: xs + category_ids: + - C2 + fulfillment_ids: + - F2 + price: + currency: INR + value: "50" + quantity: + selected: + count: 1 + time: + label: Validity + duration: P1D + timestamp: "2026-01-23T11:01:40.065Z" + range: + start: "2026-01-23T11:01:40.065Z" + end: "2026-01-24T11:01:40.065Z" + provider: + id: P1 + descriptor: + name: Delhi Metro Rail Limited + images: + - url: https://delhimetrorail.com/logos/logo.ico + time: + range: + start: "2026-01-14T05:30:00.000Z" + end: "2026-01-14T23:30:00.000Z" + fulfillments: + - id: F2 + type: PASS + customer: + person: + creds: + - type: AADHAAR + id: "1234 5678 9193" + stops: + - type: START + location: + descriptor: + name: Shaheed Sthal(New Bus Adda) + code: SHAHEED_STHAL + gps: "28.686576, 77.441632" + id: "1" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 1 + location: + descriptor: + name: Hindon River + code: HINDON_RIVER + gps: "28.686176, 77.442632" + id: "2" + parent_stop_id: "1" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 2 + location: + descriptor: + name: Arthala + gps: "28.181276, 77.442332" + id: "3" + parent_stop_id: "2" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 3 + location: + descriptor: + name: Mohan Nagar + gps: "28.981276, 77.772332" + id: "4" + parent_stop_id: "3" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 4 + location: + descriptor: + name: Shyam Park + gps: "28.620976, 77.046732" + id: "5" + parent_stop_id: "4" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 5 + location: + descriptor: + name: Major Mohit Sharma Rajendra Nagar + gps: "28.120976, 77.946732" + id: "6" + parent_stop_id: "5" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 6 + location: + descriptor: + name: Raj Bagh + gps: "28.677076, 77.346632" + id: "7" + parent_stop_id: "6" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 7 + location: + descriptor: + name: Shaheed Nagar + gps: "28.617076, 77.146632" + id: "8" + parent_stop_id: "7" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 8 + location: + descriptor: + name: Dilshad Garden + gps: "28.917076, 77.146632" + id: "9" + parent_stop_id: "8" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 9 + location: + descriptor: + name: Jhilmil + gps: "28.897076, 77.146632" + id: "10" + parent_stop_id: "9" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 10 + location: + descriptor: + name: Mansarovar Park + gps: "28.117076, 77.116632" + id: "11" + parent_stop_id: "10" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 11 + location: + descriptor: + name: Shahdara + gps: "28.127076, 77.416632" + id: "12" + parent_stop_id: "11" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 12 + location: + descriptor: + name: Welcome + gps: "28.217076, 77.216632" + id: "13" + parent_stop_id: "12" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 13 + location: + descriptor: + name: Seelampur + gps: "28.327076, 77.416632" + id: "14" + parent_stop_id: "13" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 14 + location: + descriptor: + name: Shastri Park + gps: "28.427076, 77.446632" + id: "15" + parent_stop_id: "14" + - type: TRANSIT_STOP + instructions: + name: Stop 15 + short_desc: Please Change here for Yellow Line + location: + descriptor: + name: Kashmere Gate + gps: "28.738426, 77.139922" + id: "16" + parent_stop_id: "15" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 16 + location: + descriptor: + name: Civil Lines + gps: "28.627076, 77.646632" + id: "17" + parent_stop_id: "16" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 17 + location: + descriptor: + name: Vidhan Sabha + gps: "28.727076, 77.746632" + id: "18" + parent_stop_id: "17" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 18 + location: + descriptor: + name: Vishwavidyalaya + gps: "28.827076, 77.846632" + id: "19" + parent_stop_id: "18" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 19 + location: + descriptor: + name: Guru Tegh Bahadur Nagar + gps: "28.927076, 77.946632" + id: "20" + parent_stop_id: "19" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 20 + location: + descriptor: + name: Model Town + gps: "28.217076, 77.496632" + id: "21" + parent_stop_id: "20" + - type: END + location: + descriptor: + name: Azadpur + code: AZADPUR + gps: "28.707358, 77.180910" + id: "22" + parent_stop_id: "21" + vehicle: + category: METRO + tags: + - descriptor: + code: ROUTE_INFO + list: + - descriptor: + code: ROUTE_ID + value: "242" + - descriptor: + code: ROUTE_NAME + value: Yellow Line + billing: + name: John Doe + email: john.doe@example.com + phone: "+91-9897867564" + payments: + - id: PA1 + collected_by: BAP + status: NOT-PAID + type: PRE-ORDER + cancellation_terms: + - external_ref: + mimetype: text/html + url: https://transitsolutions.com/mf/tnc.html + quote: + price: + value: "50" + currency: INR + breakup: + - title: BASE_FARE + item: + id: I5 + price: + currency: INR + value: "50" + quantity: + selected: + count: 1 + price: + currency: INR + value: "50" + - title: TAX + price: + currency: INR + value: "0" + item: + tags: + - descriptor: + code: TAX + list: + - descriptor: + code: CGST + value: "0" + - descriptor: + code: SGST + value: "0" + - title: OTHER_CHARGES + price: + currency: INR + value: "0" + item: + tags: + - descriptor: + code: OTHER_CHARGES + list: + - descriptor: + code: SURCHARGE + value: "0" + tags: + - descriptor: + code: BPP_TERMS + name: BPP Terms of Engagement + display: false + list: + - descriptor: + code: BUYER_FINDER_FEES_PERCENTAGE + value: "1" + - descriptor: + code: SETTLEMENT_WINDOW + value: P30D + - descriptor: + code: SETTLEMENT_BASIS + value: INVOICE_RECEIPT + - descriptor: + code: MANDATORY_ARBITRATION + value: "TRUE" + - descriptor: + code: COURT_JURISDICTION + value: New Delhi + - descriptor: + code: STATIC_TERMS + value: https://api.example-bpp.com/booking/terms + - descriptor: + code: SETTLEMENT_AMOUNT + value: "59" + - descriptor: + code: SETTLEMENT_TYPE + value: NEFT + - descriptor: + code: SETTLEMENT_BANK_CODE + value: XXXXXXXX + - descriptor: + code: SETTLEMENT_BANK_ACCOUNT_NUMBER + value: xxxxxxxxxxxxxx + - descriptor: + code: ADDITIONAL_APIS + display: false + list: + - descriptor: + code: GTFS_RT + value: https://metro-transit/gtfs-realtime + - descriptor: + code: GTFS_ST + value: https://metro-transit/gtfs-static + - descriptor: + code: WALLET_BALANCE_CHECK + name: The CARD_NUMBER represents the Metro card number and is used to check the wallet balance via the API. + value: https://metro-transit/wallet/balance/{CARD_NUMBER} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/on_init_unlimitedpass/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/on_init_unlimitedpass/generator.ts new file mode 100644 index 00000000..8bdf5028 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_init/on_init_unlimitedpass/generator.ts @@ -0,0 +1,60 @@ +import { v4 as uuidv4 } from "uuid"; +export async function onInitUnlimitedPassGenerator( + existingPayload: any, + sessionData: any, +) { + existingPayload.context.location.city.code = + sessionData?.select_city_code ?? "std:080"; + console.log(sessionData?.items, sessionData?.fulfillments); + existingPayload.message.order.provider = sessionData.provider; + existingPayload.message.order.items = sessionData?.items ?? []; + existingPayload.message.order.fulfillments = sessionData?.fulfillments ?? []; + existingPayload.message.order.cancellation_terms = + sessionData?.cancellation_terms?.flat() ?? []; + existingPayload.message.order.quote = sessionData?.quote ?? {}; + existingPayload.message.order.billing = sessionData?.billing ?? {}; + existingPayload.message.order.payments = + sessionData?.payments?.flat()?.map((item: any) => { + return { + id: uuidv4(), + ...item, + }; + }) ?? []; + + existingPayload.message.order.tags = [ + { + descriptor: { + code: "BPP_TERMS", + name: "BPP Terms of Engagement", + }, + display: false, + list: [ + ...(sessionData?.init_tags + ?.flat()[0] + ?.list?.filter( + (item: any) => item?.descriptor?.code !== "DELAY_INTEREST", + ) || []), + + { + descriptor: { code: "SETTLEMENT_WINDOW" }, + value: "P30D", + }, + { + descriptor: { code: "SETTLEMENT_BASIS" }, + value: "INVOICE_RECEIPT", + }, + { + descriptor: { code: "SETTLEMENT_BANK_CODE" }, + value: "XXXXXXXX", + }, + { + descriptor: { code: "SETTLEMENT_BANK_ACCOUNT_NUMBER" }, + value: "xxxxxxxxxxxxxx", + }, + ], + }, + ...sessionData?.select_tags?.flat(), + ]; + + return existingPayload; +} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search2/default.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search2/default.yaml index 908b0808..ddcb994f 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search2/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search2/default.yaml @@ -42,7 +42,7 @@ message: - F1 time: label: Validity - duration: PT2D + duration: P2D timestamp: "2021-03-23T11:01:40.065Z" - id: I2 category_ids: @@ -62,7 +62,7 @@ message: - F1 time: label: Validity - duration: PT2D + duration: P2D timestamp: "2021-03-23T11:01:40.065Z" fulfillments: - id: F1 diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search2/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search2/generator.ts index c8104f20..f0c47bf5 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search2/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search2/generator.ts @@ -182,7 +182,7 @@ export async function onSearch2Generator( if (item.time && item.time.duration) { // Parse duration (e.g., PT2D = 2 days) - const durationMatch = item.time.duration.match(/PT(\d+)D/); + const durationMatch = item.time.duration.match(/P(\d+)D/); if (durationMatch) { const days = parseInt(durationMatch[1], 10); const futureDate = new Date(today); diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_purchase/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_purchase/generator.ts index 1cb4ad1d..b0de9af1 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_purchase/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_purchase/generator.ts @@ -37,7 +37,7 @@ export async function onSearch1Generator( provider.items?.map((item: any) => { if (item.time && item.time.duration) { // Parse duration (e.g., PT2D = 2 days) - const durationMatch = item.time.duration.match(/PT(\d+)D/); + const durationMatch = item.time.duration.match(/P(\d+)D/); if (durationMatch) { const days = parseInt(durationMatch[1], 10); const futureDate = new Date(today); diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_recharge/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_recharge/generator.ts index 1cb4ad1d..b0de9af1 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_recharge/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_recharge/generator.ts @@ -37,7 +37,7 @@ export async function onSearch1Generator( provider.items?.map((item: any) => { if (item.time && item.time.duration) { // Parse duration (e.g., PT2D = 2 days) - const durationMatch = item.time.duration.match(/PT(\d+)D/); + const durationMatch = item.time.duration.match(/P(\d+)D/); if (durationMatch) { const days = parseInt(durationMatch[1], 10); const futureDate = new Date(today); diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_unlimitedpass/class.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_unlimitedpass/class.ts new file mode 100644 index 00000000..cf08bb75 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_unlimitedpass/class.ts @@ -0,0 +1,44 @@ +import { readFileSync } from "fs"; +import yaml from "js-yaml"; +import path from "path"; +import { + MockAction, + MockOutput, + saveType, +} from "../../../../classes/mock-action"; +import { onSearchUnlimitedPassGenerator } from "./generator"; +import { SessionData } from "../../../../session-types"; + +export class MockOnSearchMetro_UnlimitedPass210Class extends MockAction { + get saveData(): saveType { + return yaml.load( + readFileSync(path.resolve(__dirname, "../save-data.yaml"), "utf8"), + ) as saveType; + } + get defaultData(): any { + return yaml.load( + readFileSync(path.resolve(__dirname, "./default.yaml"), "utf8"), + ); + } + get inputs(): any { + return {}; + } + name(): string { + return "on_search_Metro_unlimitedpass_210"; + } + get description(): string { + return "Mock for on_search_Metro_unlimitedpass_210"; + } + generator(existingPayload: any, sessionData: SessionData): Promise { + return onSearchUnlimitedPassGenerator(existingPayload, sessionData); + } + async validate( + targetPayload: any, + sessionData: SessionData, + ): Promise { + return { valid: true }; + } + async meetRequirements(sessionData: SessionData): Promise { + return { valid: true }; + } +} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_unlimitedpass/default.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_unlimitedpass/default.yaml new file mode 100644 index 00000000..7c6b5392 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_unlimitedpass/default.yaml @@ -0,0 +1,328 @@ +message: + catalog: + descriptor: + name: Transit Solutions + images: + - url: https://transitsolutions.in/logos/logo.ico + providers: + - id: P1 + categories: + - descriptor: + name: Pass + code: PASS + id: C2 + locations: + - id: L1 + city: + code: "std:011" + time: + range: + start: "2023-09-14T05:30:00.000Z" + end: "2023-09-14T23:30:00.000Z" + descriptor: + name: Delhi Metro Rail Limited + images: + - url: https://delhimetrorail.com/logos/logo.ico + items: + - id: I5 + descriptor: + name: Daily Pass + code: PASS + images: + - url: "https://delhimetrorail.com/logos/logo.ico'" + size_type: xs + category_ids: + - C2 + fulfillment_ids: + - F2 + price: + currency: INR + value: "50" + quantity: + maximum: + count: 1 + minimum: + count: 1 + time: + label: Validity + duration: P1D + fulfillments: + - id: F2 + type: PASS + customer: + person: + creds: + - type: PAN + - type: AADHAAR + - type: DL + - type: VOTER_ID + stops: + - type: START + location: + descriptor: + name: mock_station_1 + code: MOCK_STATION_1 + gps: "28.686576, 77.441632" + id: "1" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 1 + location: + descriptor: + name: mock_station_2 + code: MOCK_STATION_2 + gps: "28.686176, 77.442632" + id: "2" + parent_stop_id: "1" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 2 + location: + descriptor: + name: mock_station_3 + code: MOCK_STATION_3 + gps: "28.181276, 77.442332" + id: "3" + parent_stop_id: "2" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 3 + location: + descriptor: + name: mock_station_4 + code: MOCK_STATION_4 + gps: "28.981276, 77.772332" + id: "4" + parent_stop_id: "3" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 4 + location: + descriptor: + name: mock_station_5 + code: MOCK_STATION_5 + gps: "28.620976, 77.046732" + id: "5" + parent_stop_id: "4" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 5 + location: + descriptor: + name: mock_station_6 + code: MOCK_STATION_6 + gps: "28.120976, 77.946732" + id: "6" + parent_stop_id: "5" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 6 + location: + descriptor: + name: mock_station_7 + code: MOCK_STATION_7 + gps: "28.677076, 77.346632" + id: "7" + parent_stop_id: "6" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 7 + location: + descriptor: + name: mock_station_8 + code: MOCK_STATION_8 + gps: "28.617076, 77.146632" + id: "8" + parent_stop_id: "7" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 8 + location: + descriptor: + name: mock_station_9 + code: MOCK_STATION_9 + gps: "28.917076, 77.146632" + id: "9" + parent_stop_id: "8" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 9 + location: + descriptor: + name: mock_station_10 + code: MOCK_STATION_10 + gps: "28.897076, 77.146632" + id: "10" + parent_stop_id: "9" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 10 + location: + descriptor: + name: mock_station_11 + code: MOCK_STATION_11 + gps: "28.117076, 77.116632" + id: "11" + parent_stop_id: "10" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 11 + location: + descriptor: + name: mock_station_12 + code: MOCK_STATION_12 + gps: "28.127076, 77.416632" + id: "12" + parent_stop_id: "11" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 12 + location: + descriptor: + name: mock_station_13 + code: MOCK_STATION_13 + gps: "28.217076, 77.216632" + id: "13" + parent_stop_id: "12" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 13 + location: + descriptor: + name: mock_station_14 + code: MOCK_STATION_14 + gps: "28.327076, 77.416632" + id: "14" + parent_stop_id: "13" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 14 + location: + descriptor: + name: mock_station_15 + code: MOCK_STATION_15 + gps: "28.427076, 77.446632" + id: "15" + parent_stop_id: "14" + - type: TRANSIT_STOP + instructions: + name: Stop 15 + short_desc: Please Change here for Yellow Line + location: + descriptor: + name: mock_station_16 + code: MOCK_STATION_16 + gps: "28.738426, 77.139922" + id: "16" + parent_stop_id: "15" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 16 + location: + descriptor: + name: mock_station_17 + code: MOCK_STATION_17 + gps: "28.627076, 77.646632" + id: "17" + parent_stop_id: "16" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 17 + location: + descriptor: + name: mock_station_18 + code: MOCK_STATION_18 + gps: "28.727076, 77.746632" + id: "18" + parent_stop_id: "17" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 18 + location: + descriptor: + name: mock_station_19 + code: MOCK_STATION_19 + gps: "28.827076, 77.846632" + id: "19" + parent_stop_id: "18" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 19 + location: + descriptor: + name: mock_station_20 + code: MOCK_STATION_20 + gps: "28.927076, 77.946632" + id: "20" + parent_stop_id: "19" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 20 + location: + descriptor: + name: mock_station_21 + code: MOCK_STATION_21 + gps: "28.217076, 77.496632" + id: "21" + parent_stop_id: "20" + - type: END + location: + descriptor: + name: mock_station_22 + code: MOCK_STATION_22 + gps: "28.707358, 77.180910" + id: "22" + parent_stop_id: "21" + vehicle: + category: METRO + tags: + - descriptor: + code: ROUTE_INFO + list: + - descriptor: + code: ROUTE_ID + value: "242" + - descriptor: + code: ROUTE_NAME + value: Yellow Line + payments: + - collected_by: BPP + tags: + - descriptor: + code: ADDITIONAL_APIS + display: false + list: + - descriptor: + code: GTFS_RT + value: https://metro-transit/gtfs-realtime + - descriptor: + code: GTFS_ST + value: https://metro-transit/gtfs-static + - descriptor: + code: WALLET_BALANCE_CHECK + name: The CARD_NUMBER represents the Metro card number and is used to check the wallet balance via the API. + value: https://metro-transit/wallet/balance/{CARD_NUMBER} + tags: + - descriptor: + code: BPP_TERMS + name: BPP Terms of Engagement + display: false + list: + - descriptor: + code: BUYER_FINDER_FEES_PERCENTAGE + value: "1" + - descriptor: + code: SETTLEMENT_WINDOW + value: P30D + - descriptor: + code: SETTLEMENT_BASIS + value: INVOICE_RECEIPT + - descriptor: + code: MANDATORY_ARBITRATION + value: "TRUE" + - descriptor: + code: COURT_JURISDICTION + value: New Delhi + - descriptor: + code: STATIC_TERMS + value: https://api.example-bpp.com/booking/terms diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_unlimitedpass/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_unlimitedpass/generator.ts new file mode 100644 index 00000000..d075915d --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_search_unlimitedpass/generator.ts @@ -0,0 +1,78 @@ +import { SessionData } from "../../../../session-types"; +import { createFullfillment } from "../fullfillment-generator"; + +// Helper function to format date as local ISO string with Z suffix +function toLocalISOStringWithZ(date: Date): string { + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, "0"); + const day = String(date.getDate()).padStart(2, "0"); + const hours = String(date.getHours()).padStart(2, "0"); + const minutes = String(date.getMinutes()).padStart(2, "0"); + const seconds = String(date.getSeconds()).padStart(2, "0"); + const milliseconds = String(date.getMilliseconds()).padStart(3, "0"); + + return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}Z`; +} + +export async function onSearchUnlimitedPassGenerator( + existingPayload: any, + sessionData: any, +) { + delete existingPayload.context.location.city.code + // Get current date + const today = new Date(); + + // Create start time at 5:30 AM of current date (local time) + const startTime = new Date(today); + startTime.setHours(5, 30, 0, 0); + + // Create end time at 11:30 PM of current date (local time) + const endTime = new Date(today); + endTime.setHours(23, 30, 0, 0); + + existingPayload.message.catalog.providers = + existingPayload.message.catalog.providers.map((provider: any) => { + // Process items and update timestamp based on duration + const updatedItems = + provider.items?.map((item: any) => { + if (item.time && item.time.duration) { + // Parse duration (e.g., PT2D = 2 days) + const durationMatch = item.time.duration.match(/P(\d+)D/); + if (durationMatch) { + const days = parseInt(durationMatch[1], 10); + const futureDate = new Date(today); + futureDate.setDate(futureDate.getDate() + days); + return { + ...item, + time: { + ...item.time, + timestamp: toLocalISOStringWithZ(futureDate), + }, + }; + } + } + return item; + }) || provider.items; + + return { + ...provider, + items: updatedItems, + payments: [{ collected_by: sessionData?.collected_by ?? "BPP" }], + locations: [ + { + id: "L1", + city: { + code: sessionData?.city_code ?? "std:011", + }, + }, + ], + time: { + range: { + start: toLocalISOStringWithZ(startTime), + end: toLocalISOStringWithZ(endTime), + }, + }, + }; + }); + return existingPayload; +} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_searchmaster/default.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_searchmaster/default.yaml index 450e3c70..3d03603e 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_searchmaster/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_searchmaster/default.yaml @@ -47,7 +47,7 @@ message: - F1 time: label: Validity - duration: PT2D + duration: P2D timestamp: "2021-03-23T11:01:40.065Z" - id: I2 category_ids: @@ -64,7 +64,7 @@ message: - F1 time: label: Validity - duration: PT2D + duration: P2D timestamp: "2021-03-23T11:01:40.065Z" - id: I3 category_ids: @@ -96,6 +96,72 @@ message: maximum_value: "500" fulfillment_ids: - F3 + - id: I5 + descriptor: + name: Daily Pass + code: PASS + images: + - url: "https://delhimetrorail.com/logos/logo.ico'" + size_type: xs + category_ids: + - C2 + fulfillment_ids: + - F2 + price: + currency: INR + value: "50" + quantity: + maximum: + count: 1 + minimum: + count: 1 + time: + label: Validity + duration: P1D + - id: I6 + descriptor: + name: Weekly Pass + code: PASS + images: + - url: "https://delhimetrorail.com/logos/logo.ico'" + size_type: xs + fulfillment_ids: + - F4 + category_ids: + - C2 + price: + currency: INR + value: "100" + quantity: + maximum: + count: 1 + minimum: + count: 1 + time: + label: Validity + duration: P7D + - id: I7 + descriptor: + name: Monthly Pass + code: PASS + images: + - url: "https://delhimetrorail.com/logos/logo.ico'" + size_type: xs + fulfillment_ids: + - F4 + category_ids: + - C2 + price: + currency: INR + value: "200" + quantity: + maximum: + count: 1 + minimum: + count: 1 + time: + label: Validity + duration: P1M fulfillments: - id: F1 type: TRIP @@ -330,11 +396,223 @@ message: value: Yellow Line - id: F2 type: PASS + customer: + person: + creds: + - type: PAN + - type: AADHAAR + - type: DL + - type: VOTER_ID stops: - - instructions: - name: How to use? - short_desc: short description about how to use? - long_desc: description about how to use? + - type: START + location: + descriptor: + name: Shaheed Sthal(New Bus Adda) + code: SHAHEED_STHAL + gps: "28.686576, 77.441632" + id: "1" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 1 + location: + descriptor: + name: Hindon River + code: HINDON_RIVER + gps: "28.686176, 77.442632" + id: "2" + parent_stop_id: "1" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 2 + location: + descriptor: + name: Arthala + gps: "28.181276, 77.442332" + id: "3" + parent_stop_id: "2" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 3 + location: + descriptor: + name: Mohan Nagar + gps: "28.981276, 77.772332" + id: "4" + parent_stop_id: "3" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 4 + location: + descriptor: + name: Shyam Park + gps: "28.620976, 77.046732" + id: "5" + parent_stop_id: "4" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 5 + location: + descriptor: + name: Major Mohit Sharma Rajendra Nagar + gps: "28.120976, 77.946732" + id: "6" + parent_stop_id: "5" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 6 + location: + descriptor: + name: Raj Bagh + gps: "28.677076, 77.346632" + id: "7" + parent_stop_id: "6" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 7 + location: + descriptor: + name: Shaheed Nagar + gps: "28.617076, 77.146632" + id: "8" + parent_stop_id: "7" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 8 + location: + descriptor: + name: Dilshad Garden + gps: "28.917076, 77.146632" + id: "9" + parent_stop_id: "8" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 9 + location: + descriptor: + name: Jhilmil + gps: "28.897076, 77.146632" + id: "10" + parent_stop_id: "9" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 10 + location: + descriptor: + name: Mansarovar Park + gps: "28.117076, 77.116632" + id: "11" + parent_stop_id: "10" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 11 + location: + descriptor: + name: Shahdara + gps: "28.127076, 77.416632" + id: "12" + parent_stop_id: "11" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 12 + location: + descriptor: + name: Welcome + gps: "28.217076, 77.216632" + id: "13" + parent_stop_id: "12" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 13 + location: + descriptor: + name: Seelampur + gps: "28.327076, 77.416632" + id: "14" + parent_stop_id: "13" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 14 + location: + descriptor: + name: Shastri Park + gps: "28.427076, 77.446632" + id: "15" + parent_stop_id: "14" + - type: TRANSIT_STOP + instructions: + name: Stop 15 + short_desc: Please Change here for Yellow Line + location: + descriptor: + name: Kashmere Gate + gps: "28.738426, 77.139922" + id: "16" + parent_stop_id: "15" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 16 + location: + descriptor: + name: Civil Lines + gps: "28.627076, 77.646632" + id: "17" + parent_stop_id: "16" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 17 + location: + descriptor: + name: Vidhan Sabha + gps: "28.727076, 77.746632" + id: "18" + parent_stop_id: "17" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 18 + location: + descriptor: + name: Vishwavidyalaya + gps: "28.827076, 77.846632" + id: "19" + parent_stop_id: "18" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 19 + location: + descriptor: + name: Guru Tegh Bahadur Nagar + gps: "28.927076, 77.946632" + id: "20" + parent_stop_id: "19" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 20 + location: + descriptor: + name: Model Town + gps: "28.217076, 77.496632" + id: "21" + parent_stop_id: "20" + - type: END + location: + descriptor: + name: Azadpur + code: AZADPUR + gps: "28.707358, 77.180910" + id: "22" + parent_stop_id: "21" + vehicle: + category: METRO + tags: + - descriptor: + code: ROUTE_INFO + list: + - descriptor: + code: ROUTE_ID + value: "242" + - descriptor: + code: ROUTE_NAME + value: Yellow Line - id: F3 type: ONLINE stops: @@ -342,6 +620,242 @@ message: name: How to use? short_desc: short description about how to use? long_desc: description about how to use? + - id: F4 + type: PASS + customer: + person: + creds: + - type: PAN + - type: DL + stops: + - type: START + location: + descriptor: + name: mock_station_1 + code: MOCK_STATION_1 + gps: "28.686576, 77.441632" + id: "1" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 1 + location: + descriptor: + name: mock_station_2 + code: MOCK_STATION_2 + gps: "28.686176, 77.442632" + id: "2" + parent_stop_id: "1" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 2 + location: + descriptor: + name: mock_station_3 + code: MOCK_STATION_3 + gps: "28.181276, 77.442332" + id: "3" + parent_stop_id: "2" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 3 + location: + descriptor: + name: mock_station_4 + code: MOCK_STATION_4 + gps: "28.981276, 77.772332" + id: "4" + parent_stop_id: "3" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 4 + location: + descriptor: + name: mock_station_5 + code: MOCK_STATION_5 + gps: "28.620976, 77.046732" + id: "5" + parent_stop_id: "4" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 5 + location: + descriptor: + name: mock_station_6 + code: MOCK_STATION_6 + gps: "28.120976, 77.946732" + id: "6" + parent_stop_id: "5" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 6 + location: + descriptor: + name: mock_station_7 + code: MOCK_STATION_7 + gps: "28.677076, 77.346632" + id: "7" + parent_stop_id: "6" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 7 + location: + descriptor: + name: mock_station_8 + code: MOCK_STATION_8 + gps: "28.617076, 77.146632" + id: "8" + parent_stop_id: "7" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 8 + location: + descriptor: + name: mock_station_9 + code: MOCK_STATION_9 + gps: "28.917076, 77.146632" + id: "9" + parent_stop_id: "8" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 9 + location: + descriptor: + name: mock_station_10 + code: MOCK_STATION_10 + gps: "28.897076, 77.146632" + id: "10" + parent_stop_id: "9" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 10 + location: + descriptor: + name: mock_station_11 + code: MOCK_STATION_11 + gps: "28.117076, 77.116632" + id: "11" + parent_stop_id: "10" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 11 + location: + descriptor: + name: mock_station_12 + code: MOCK_STATION_12 + gps: "28.127076, 77.416632" + id: "12" + parent_stop_id: "11" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 12 + location: + descriptor: + name: mock_station_13 + code: MOCK_STATION_13 + gps: "28.217076, 77.216632" + id: "13" + parent_stop_id: "12" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 13 + location: + descriptor: + name: mock_station_14 + code: MOCK_STATION_14 + gps: "28.327076, 77.416632" + id: "14" + parent_stop_id: "13" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 14 + location: + descriptor: + name: mock_station_15 + code: MOCK_STATION_15 + gps: "28.427076, 77.446632" + id: "15" + parent_stop_id: "14" + - type: TRANSIT_STOP + instructions: + name: Stop 15 + short_desc: Please Change here for Yellow Line + location: + descriptor: + name: mock_station_16 + code: MOCK_STATION_16 + gps: "28.738426, 77.139922" + id: "16" + parent_stop_id: "15" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 16 + location: + descriptor: + name: mock_station_17 + code: MOCK_STATION_17 + gps: "28.627076, 77.646632" + id: "17" + parent_stop_id: "16" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 17 + location: + descriptor: + name: mock_station_18 + code: MOCK_STATION_18 + gps: "28.727076, 77.746632" + id: "18" + parent_stop_id: "17" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 18 + location: + descriptor: + name: mock_station_19 + code: MOCK_STATION_19 + gps: "28.827076, 77.846632" + id: "19" + parent_stop_id: "18" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 19 + location: + descriptor: + name: mock_station_20 + code: MOCK_STATION_20 + gps: "28.927076, 77.946632" + id: "20" + parent_stop_id: "19" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 20 + location: + descriptor: + name: mock_station_21 + code: MOCK_STATION_21 + gps: "28.217076, 77.496632" + id: "21" + parent_stop_id: "20" + - type: END + location: + descriptor: + name: mock_station_22 + code: MOCK_STATION_22 + gps: "28.707358, 77.180910" + id: "22" + parent_stop_id: "21" + vehicle: + category: METRO + tags: + - descriptor: + code: ROUTE_INFO + list: + - descriptor: + code: ROUTE_ID + value: "242" + - descriptor: + code: ROUTE_NAME + value: Yellow Line payments: - collected_by: BPP tags: diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_searchmaster/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_searchmaster/generator.ts index d0134064..8227eb73 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_searchmaster/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/on_searchmaster/generator.ts @@ -37,7 +37,7 @@ export async function onSearchMasterGenerator( provider.items?.map((item: any) => { if (item.time && item.time.duration) { // Parse duration (e.g., PT2D = 2 days) - const durationMatch = item.time.duration.match(/PT(\d+)D/); + const durationMatch = item.time.duration.match(/P(\d+)D/); if (durationMatch) { const days = parseInt(durationMatch[1], 10); const futureDate = new Date(today); diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/save-data.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/save-data.yaml index 540bb279..814fdaa0 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/save-data.yaml +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_search/save-data.yaml @@ -21,3 +21,4 @@ save-data: bpp_id: "$.context.bpp_id" bpp_uri: "$.context.bpp_uri" city_code: "$.context.location.city.code" + on_search_unlimited_pass_provider: "$.message.catalog.providers" diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_select/on_select_unlimitedpass/class.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_select/on_select_unlimitedpass/class.ts new file mode 100644 index 00000000..951e2331 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_select/on_select_unlimitedpass/class.ts @@ -0,0 +1,108 @@ +import { readFileSync } from "fs"; +import yaml from "js-yaml"; +import path from "path"; +import { MockAction, MockOutput, saveType } from "../../../../classes/mock-action"; +import { onSelectUnlimitedPassGenerator } from "./generator"; +import { SessionData } from "../../../../session-types"; + +export class MockOnSelectMetroUnlimitedPass210Class extends MockAction { + get saveData(): saveType { + return yaml.load( + readFileSync(path.resolve(__dirname, "../save-data.yaml"), "utf8") + ) as saveType; + } + get defaultData(): any { + return yaml.load( + readFileSync(path.resolve(__dirname, "./default.yaml"), "utf8") + ); + } + get inputs(): any { + return {}; + } + name(): string { + return "on_select_METRO_UNLIMITEDPASS_210"; + } + get description(): string { + return "Mock for on_select_METRO_UNLIMITEDPASS_210"; + } + generator(existingPayload: any, sessionData: SessionData): Promise { + return onSelectUnlimitedPassGenerator(existingPayload, sessionData); + } + async validate( + targetPayload: any, + sessionData: SessionData + ): Promise { + const items = targetPayload?.message?.order?.items || []; + const fulfillments = targetPayload?.message?.order?.fulfillments || []; + + // Extract all fulfillment ids from payload + const payloadFulfillmentIds = fulfillments.map((f: any) => f.id); + + for (const item of items) { + // 1. check item id in sessionData.selected_item_ids + if (!sessionData.selected_item_ids.includes(item.id)) { + return { + valid: false, + message: `Item id ${item.id} not found in sessionData.selected_item_ids: ${sessionData.selected_item_ids}`, + }; + } + + // 2. check item.fulfillment_ids are present in payload.fulfillments + const itemFulfillmentIds = item.fulfillment_ids || []; + if ( + !itemFulfillmentIds.every((fid: string) => + payloadFulfillmentIds.includes(fid) + ) + ) { + return { + valid: false, + message: `Item ${item.id} has invalid fulfillment ids. Expected subset of ${payloadFulfillmentIds}, got ${itemFulfillmentIds}`, + }; + } + + // 3. check quantity within min and max for that item in sessionData.items + const sessionItem = sessionData.items?.find((i: any) => i.id === item.id); + const selectedCount = item?.quantity?.selected?.count; + + if (!sessionItem) { + return { + valid: false, + message: `Item ${item.id} not found in sessionData.items`, + }; + } + + const min = sessionItem?.quantity?.minimum?.count ?? 1; + const max = sessionItem?.quantity?.maximum?.count ?? Infinity; + + if (selectedCount < min || selectedCount > max) { + return { + valid: false, + message: `Item ${item.id} quantity out of range. Expected between ${min} and ${max}, got ${selectedCount}`, + }; + } + } + + return { valid: true }; + } + async meetRequirements(sessionData: SessionData): Promise { + // Check for items + if (!sessionData.items || sessionData.items.length === 0) { + return { + valid: false, + message: "No items available in session data", + code: "MISSING_ITEMS", + }; + } + // Check for provider_id + if (!sessionData.provider_id) { + return { + valid: false, + message: "No provider_id available in session data", + code: "MISSING_PROVIDER_ID", + }; + } + + // All requirements satisfied + return { valid: true }; +} +} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_select/on_select_unlimitedpass/default.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_select/on_select_unlimitedpass/default.yaml new file mode 100644 index 00000000..9f50bcc6 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_select/on_select_unlimitedpass/default.yaml @@ -0,0 +1,318 @@ +message: + order: + items: + - id: I5 + descriptor: + name: Daily Pass + code: PASS + images: + - url: "https://delhimetrorail.com/logos/logo.ico'" + size_type: xs + category_ids: + - C2 + fulfillment_ids: + - F2 + price: + currency: INR + value: "50" + quantity: + selected: + count: 1 + time: + label: Validity + duration: P1D + timestamp: "2026-01-23T11:01:40.065Z" + range: + start: "2026-01-23T11:01:40.065Z" + end: "2026-01-24T11:01:40.065Z" + provider: + id: P1 + descriptor: + name: Delhi Metro Rail Limited + images: + - url: https://delhimetrorail.com/logos/logo.ico + time: + range: + start: "2026-01-14T05:30:00.000Z" + end: "2026-01-14T23:30:00.000Z" + fulfillments: + - id: F2 + type: PASS + customer: + person: + creds: + - type: AADHAAR + id: "1234 5678 9193" + stops: + - type: START + location: + descriptor: + name: Shaheed Sthal(New Bus Adda) + code: SHAHEED_STHAL + gps: "28.686576, 77.441632" + id: "1" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 1 + location: + descriptor: + name: Hindon River + code: HINDON_RIVER + gps: "28.686176, 77.442632" + id: "2" + parent_stop_id: "1" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 2 + location: + descriptor: + name: Arthala + gps: "28.181276, 77.442332" + id: "3" + parent_stop_id: "2" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 3 + location: + descriptor: + name: Mohan Nagar + gps: "28.981276, 77.772332" + id: "4" + parent_stop_id: "3" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 4 + location: + descriptor: + name: Shyam Park + gps: "28.620976, 77.046732" + id: "5" + parent_stop_id: "4" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 5 + location: + descriptor: + name: Major Mohit Sharma Rajendra Nagar + gps: "28.120976, 77.946732" + id: "6" + parent_stop_id: "5" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 6 + location: + descriptor: + name: Raj Bagh + gps: "28.677076, 77.346632" + id: "7" + parent_stop_id: "6" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 7 + location: + descriptor: + name: Shaheed Nagar + gps: "28.617076, 77.146632" + id: "8" + parent_stop_id: "7" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 8 + location: + descriptor: + name: Dilshad Garden + gps: "28.917076, 77.146632" + id: "9" + parent_stop_id: "8" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 9 + location: + descriptor: + name: Jhilmil + gps: "28.897076, 77.146632" + id: "10" + parent_stop_id: "9" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 10 + location: + descriptor: + name: Mansarovar Park + gps: "28.117076, 77.116632" + id: "11" + parent_stop_id: "10" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 11 + location: + descriptor: + name: Shahdara + gps: "28.127076, 77.416632" + id: "12" + parent_stop_id: "11" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 12 + location: + descriptor: + name: Welcome + gps: "28.217076, 77.216632" + id: "13" + parent_stop_id: "12" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 13 + location: + descriptor: + name: Seelampur + gps: "28.327076, 77.416632" + id: "14" + parent_stop_id: "13" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 14 + location: + descriptor: + name: Shastri Park + gps: "28.427076, 77.446632" + id: "15" + parent_stop_id: "14" + - type: TRANSIT_STOP + instructions: + name: Stop 15 + short_desc: Please Change here for Yellow Line + location: + descriptor: + name: Kashmere Gate + gps: "28.738426, 77.139922" + id: "16" + parent_stop_id: "15" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 16 + location: + descriptor: + name: Civil Lines + gps: "28.627076, 77.646632" + id: "17" + parent_stop_id: "16" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 17 + location: + descriptor: + name: Vidhan Sabha + gps: "28.727076, 77.746632" + id: "18" + parent_stop_id: "17" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 18 + location: + descriptor: + name: Vishwavidyalaya + gps: "28.827076, 77.846632" + id: "19" + parent_stop_id: "18" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 19 + location: + descriptor: + name: Guru Tegh Bahadur Nagar + gps: "28.927076, 77.946632" + id: "20" + parent_stop_id: "19" + - type: INTERMEDIATE_STOP + instructions: + name: Stop 20 + location: + descriptor: + name: Model Town + gps: "28.217076, 77.496632" + id: "21" + parent_stop_id: "20" + - type: END + location: + descriptor: + name: Azadpur + code: AZADPUR + gps: "28.707358, 77.180910" + id: "22" + parent_stop_id: "21" + vehicle: + category: METRO + tags: + - descriptor: + code: ROUTE_INFO + list: + - descriptor: + code: ROUTE_ID + value: "242" + - descriptor: + code: ROUTE_NAME + value: Yellow Line + quote: + price: + value: "50" + currency: INR + breakup: + - title: BASE_FARE + item: + id: I5 + price: + currency: INR + value: "50" + quantity: + selected: + count: 1 + price: + currency: INR + value: "50" + - title: TAX + price: + currency: INR + value: "0" + item: + tags: + - descriptor: + code: TAX + list: + - descriptor: + code: CGST + value: "0" + - descriptor: + code: SGST + value: "0" + - title: OTHER_CHARGES + price: + currency: INR + value: "0" + item: + tags: + - descriptor: + code: OTHER_CHARGES + list: + - descriptor: + code: SURCHARGE + value: "0" + cancellation_terms: + - external_ref: + mimetype: text/html + url: https://transitsolutions.com/mf/tnc.html + tags: + - descriptor: + code: ADDITIONAL_APIS + display: false + list: + - descriptor: + code: GTFS_RT + value: https://metro-transit/gtfs-realtime + - descriptor: + code: GTFS_ST + value: https://metro-transit/gtfs-static + - descriptor: + code: WALLET_BALANCE_CHECK + name: The CARD_NUMBER represents the Metro card number and is used to check the wallet balance via the API. + value: https://metro-transit/wallet/balance/{CARD_NUMBER} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_select/on_select_unlimitedpass/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_select/on_select_unlimitedpass/generator.ts new file mode 100644 index 00000000..79173b29 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_select/on_select_unlimitedpass/generator.ts @@ -0,0 +1,172 @@ +export async function onSelectUnlimitedPassGenerator( + existingPayload: any, + sessionData: any, +) { + existingPayload.context.location.city.code = + sessionData?.select_city_code ?? "std:080"; + const creds = sessionData?.selected_unlimitedpass_fulfillments + ?.flat() + ?.find((item: any) => { + return item.type === "PASS"; + }); + const selectedItemId = sessionData?.selected_item_ids?.[0]; + const selectedFulfillmentId = sessionData?.selected_fulfillment_ids; + + const items = (sessionData?.items ?? []).flat(); + const fulfillments = (sessionData?.fulfillments ?? []).flat(); + + existingPayload.message.order.items = selectedItemId + ? items.reduce((acc: any[], item: any) => { + if (item?.id === selectedItemId) { + acc.push({ + ...item, + quantity: + sessionData?.selected_unlimitedpass_item?.flat?.()?.[0] + ?.quantity ?? "0", + price: { + currency: item?.price?.currency, + value: item?.price?.value, + }, + time: { + ...item?.time, + range: + sessionData?.on_search_unlimited_pass_provider?.flat?.()?.[0] + ?.time?.range ?? {}, + }, + }); + } + return acc; + }, []) + : []; + + existingPayload.message.order.fulfillments = selectedFulfillmentId + ? fulfillments + .filter((f: any) => f?.id === selectedFulfillmentId) + .map((fulfillment: any) => { + if (fulfillment?.type === "PASS" && fulfillment?.customer) { + return { + ...fulfillment, + customer: creds?.customer ?? {}, + }; + } + return fulfillment; + }) + : []; + + existingPayload.message.order.provider = { + id: sessionData?.provider_id ?? "Provider1", + descriptor: sessionData?.provider_descriptor ?? {}, + time: sessionData?.on_search_unlimited_pass_provider?.flat()[0]?.time ?? {}, + }; + + const selectedQty = sessionData?.selected_unlimitedpass_item.flat()[0]; + + const baseFareBreakup = (existingPayload?.message?.order?.items || []).map( + (item: any) => { + const itemPrice = Number(item?.price?.value) || 200; + + return { + title: "BASE_FARE", + item: { + id: item?.id ?? "I1", + price: { + currency: "INR", + value: String(itemPrice), + }, + quantity: selectedQty?.quantity ?? {}, + }, + price: { + currency: "INR", + value: String( + itemPrice * Number(selectedQty?.quantity?.selected?.count), + ), + }, + }; + }, + ); + const getBreakupPrice = (breakupItem: any): number => + Number(breakupItem?.price?.value ?? breakupItem?.item?.price?.value ?? 0); + + const baseFareTotal = baseFareBreakup.reduce( + (sum: number, item: any) => sum + getBreakupPrice(item), + 0, + ); + + const CGST_PERCENT = 2; + const SGST_PERCENT = 2; + + const cgstAmount = (baseFareTotal * CGST_PERCENT) / 100; + const sgstAmount = (baseFareTotal * SGST_PERCENT) / 100; + const totalTax = cgstAmount + sgstAmount; + + const convenienceFee = 10; + const otherCharges = 0; + const offerDiscount = 0; + + const breakUp = [ + ...baseFareBreakup, + { + title: "TAX", + price: { + currency: "INR", + value: totalTax.toFixed(2), + }, + item: { + tags: [ + { + descriptor: { code: "TAX" }, + list: [ + { + descriptor: { code: "CGST" }, + value: `${CGST_PERCENT}%`, + }, + { + descriptor: { code: "SGST" }, + value: `${SGST_PERCENT}%`, + }, + ], + }, + ], + }, + }, + { + title: "OTHER_CHARGES", + price: { + currency: "INR", + value: String(otherCharges), + }, + item: { + tags: [ + { + descriptor: { + code: "OTHER_CHARGES", + }, + list: [ + { + descriptor: { + code: "SURCHARGE", + }, + value: "0", + }, + ], + }, + ], + }, + }, + ]; + + const totalQuoteValue = breakUp.reduce( + (sum: number, item: any) => sum + getBreakupPrice(item), + 0, + ); + + existingPayload.message.order.quote = { + price: { + value: totalQuoteValue.toFixed(2), + currency: "INR", + }, + breakup: breakUp, + }; + + return existingPayload; +} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_status/on_status_cancelled/default.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_status/on_status_cancelled/default.yaml index 20721b0d..0ad323a5 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_status/on_status_cancelled/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_status/on_status_cancelled/default.yaml @@ -389,7 +389,7 @@ message: cancelled_by: CONSUMER reason: descriptor: - code: "0" + code: "000" short_desc: Cancelled by the provider created_at: "2021-03-23T10:00:40.065Z" updated_at: "2021-03-23T10:05:49.061Z" diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_update/on_update_accepted/default.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_update/on_update_accepted/default.yaml index bcd3c7ad..7fd5aebd 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_update/on_update_accepted/default.yaml +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_update/on_update_accepted/default.yaml @@ -377,7 +377,7 @@ message: duration: PT60M cancellation_fee: percentage: '0' - - external_ref: + external_ref: mimetype: text/html url: https://transitsolutions.com/mf/tnc.html tags: diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_update/on_update_accepted/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_update/on_update_accepted/generator.ts index 59335f10..9b710b25 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_update/on_update_accepted/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_update/on_update_accepted/generator.ts @@ -104,6 +104,22 @@ export async function onUpdateAcceptedGenerator( if (sessionData.fulfillments.length > 0) { existingPayload.message.order.fulfillments = sessionData.fulfillments; + if (sessionData?.flow_id === "DELAYED_CANCELLATION_FLOW_ACCEPTED") { + existingPayload.message.order.fulfillments = + existingPayload.message.order.fulfillments?.map((f: any) => { + if (f.type === "TICKET") { + return { + ...f, + state: { + descriptor: { + code: "INACTIVE", + }, + }, + }; + } + return f; + }); + } } // existingPayload.message.order.fulfillments.forEach((fulfillment: any) => { diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_update/on_update_end_stop_1/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_update/on_update_end_stop_1/generator.ts index 59e54253..23efd219 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_update/on_update_end_stop_1/generator.ts +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/on_update/on_update_end_stop_1/generator.ts @@ -126,14 +126,21 @@ export async function onUpdateStopEndGenerator( } existingPayload.message.order.fulfillments = - existingPayload?.message?.order?.fulfillments?.map((fulfillment: any) => { - if (fulfillment?.type === "TRIP") { - return { - ...fulfillment, - stops: updatedStops, - }; - } else return fulfillment; - }); + existingPayload?.message?.order?.fulfillments?.map((fulfillment: any) => { + if (fulfillment?.type === "TRIP") { + return { + ...fulfillment, + stops: updatedStops?.map((stop: any) => { + if (stop?.type === "START") { + const { instructions, parent_stop_id, ...rest } = stop; + return rest; + } + return stop; + }), + }; + } + return fulfillment; + }); // Update item prices based on TRIP fulfillment stops length const tripFulfillment = existingPayload.message.order.fulfillments?.find( diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/select/save-data.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/select/save-data.yaml index c131596c..e42085bb 100644 --- a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/select/save-data.yaml +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/select/save-data.yaml @@ -6,3 +6,5 @@ save-data: buyer_side_fulfillment_ids: "$.message.order.fulfillments[*]" selected_fulfillment_ids: "$.message.order.fulfillments[*].id" select_city_code: "$.context.location.city.code" + selected_unlimitedpass_item: "$.message.order.items" + selected_unlimitedpass_fulfillments: "$.message.order.fulfillments" diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/select/select_unlimitedpass/class.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/select/select_unlimitedpass/class.ts new file mode 100644 index 00000000..0aaf7092 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/select/select_unlimitedpass/class.ts @@ -0,0 +1,108 @@ +import { readFileSync } from "fs"; +import yaml from "js-yaml"; +import path from "path"; +import { MockAction, MockOutput, saveType } from "../../../../classes/mock-action"; +import { selectUnlimitedPassGenerator } from "./generator"; +import { SessionData } from "../../../../session-types"; + +export class MockSelectMetroUnlimitedPass210Class extends MockAction { + get saveData(): saveType { + return yaml.load( + readFileSync(path.resolve(__dirname, "../save-data.yaml"), "utf8") + ) as saveType; + } + get defaultData(): any { + return yaml.load( + readFileSync(path.resolve(__dirname, "./default.yaml"), "utf8") + ); + } + get inputs(): any { + return {}; + } + name(): string { + return "select_METRO_UNLIMITEDPASS_210"; + } + get description(): string { + return "Mock for select_METRO_UNLIMITEDPASS_210"; + } + generator(existingPayload: any, sessionData: SessionData): Promise { + return selectUnlimitedPassGenerator(existingPayload, sessionData); + } + async validate( + targetPayload: any, + sessionData: SessionData + ): Promise { + const items = targetPayload?.message?.order?.items || []; + const fulfillments = targetPayload?.message?.order?.fulfillments || []; + + // Extract all fulfillment ids from payload + const payloadFulfillmentIds = fulfillments.map((f: any) => f.id); + + for (const item of items) { + // 1. check item id in sessionData.selected_item_ids + if (!sessionData.selected_item_ids.includes(item.id)) { + return { + valid: false, + message: `Item id ${item.id} not found in sessionData.selected_item_ids: ${sessionData.selected_item_ids}`, + }; + } + + // 2. check item.fulfillment_ids are present in payload.fulfillments + const itemFulfillmentIds = item.fulfillment_ids || []; + if ( + !itemFulfillmentIds.every((fid: string) => + payloadFulfillmentIds.includes(fid) + ) + ) { + return { + valid: false, + message: `Item ${item.id} has invalid fulfillment ids. Expected subset of ${payloadFulfillmentIds}, got ${itemFulfillmentIds}`, + }; + } + + // 3. check quantity within min and max for that item in sessionData.items + const sessionItem = sessionData.items?.find((i: any) => i.id === item.id); + const selectedCount = item?.quantity?.selected?.count; + + if (!sessionItem) { + return { + valid: false, + message: `Item ${item.id} not found in sessionData.items`, + }; + } + + const min = sessionItem?.quantity?.minimum?.count ?? 1; + const max = sessionItem?.quantity?.maximum?.count ?? Infinity; + + if (selectedCount < min || selectedCount > max) { + return { + valid: false, + message: `Item ${item.id} quantity out of range. Expected between ${min} and ${max}, got ${selectedCount}`, + }; + } + } + + return { valid: true }; + } + async meetRequirements(sessionData: SessionData): Promise { + // Check for items + if (!sessionData.items || sessionData.items.length === 0) { + return { + valid: false, + message: "No items available in session data", + code: "MISSING_ITEMS", + }; + } + // Check for provider_id + if (!sessionData.provider_id) { + return { + valid: false, + message: "No provider_id available in session data", + code: "MISSING_PROVIDER_ID", + }; + } + + // All requirements satisfied + return { valid: true }; +} +} diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/select/select_unlimitedpass/default.yaml b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/select/select_unlimitedpass/default.yaml new file mode 100644 index 00000000..3e074490 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/select/select_unlimitedpass/default.yaml @@ -0,0 +1,17 @@ +message: + order: + items: + - id: I5 + quantity: + selected: + count: 1 + fulfillments: + - id: F2 + type: PASS + customer: + person: + creds: + - type: AADHAAR + id: "1234 5678 9193" + provider: + id: P1 diff --git a/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/select/select_unlimitedpass/generator.ts b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/select/select_unlimitedpass/generator.ts new file mode 100644 index 00000000..f5f03c06 --- /dev/null +++ b/mock-service/src/config/mock-config/TRV11/METRO/2.1.0/select/select_unlimitedpass/generator.ts @@ -0,0 +1,44 @@ +export async function selectUnlimitedPassGenerator( + existingPayload: any, + sessionData: any, +) { + const metroPurchaseItem = sessionData?.items?.flat().find((item: any) => { + return item.descriptor.code === "PASS"; + }); + const metroPurchaseFulfillment = sessionData?.fulfillments + ?.flat() + .find((fulfillment: any) => { + return fulfillment.type === "PASS"; + }); + + existingPayload.message.order.provider.id = + sessionData?.provider_id ?? "PROVIDER01"; + existingPayload.message.order.items = [ + { + id: metroPurchaseItem?.id ?? "PurchaseItemIdI3", + quantity: { + selected: { + count: 1, + }, + }, + }, + ]; + existingPayload.message.order.fulfillments = [ + { + id: metroPurchaseFulfillment?.id ?? "PurchaseFulfillmentIdF3", + type: metroPurchaseFulfillment?.type ?? "unlimitedPass", + customer: { + person: { + creds: [ + { + type: "AADHAAR", + id: "1234 5678 9193", + }, + ], + }, + }, + }, + ]; + + return existingPayload; +} diff --git a/mock-service/src/config/mock-config/TRV11/action-factory.ts b/mock-service/src/config/mock-config/TRV11/action-factory.ts index 0c9e6fc4..18ba43fe 100644 --- a/mock-service/src/config/mock-config/TRV11/action-factory.ts +++ b/mock-service/src/config/mock-config/TRV11/action-factory.ts @@ -147,6 +147,13 @@ import { MockInitUnlimitedPassBus210Class } from "./BUS/2.1.0/init/init_unlimite import { MockOnInitUnlimitedPassBus210Class } from "./BUS/2.1.0/on_init/on_init_unlimited_pass/class"; import { MockConfirmUnlimitedPassBus210Class } from "./BUS/2.1.0/confirm/confirm_unlimited_pass/class"; import { MockOnConfirmUnlimitedPassBus210Class } from "./BUS/2.1.0/on_confirm/on_confirm_unlimited_pass/class"; +import { MockOnSearchMetro_UnlimitedPass210Class } from "./METRO/2.1.0/on_search/on_search_unlimitedpass/class"; +import { MockSelectMetroUnlimitedPass210Class } from "./METRO/2.1.0/select/select_unlimitedpass/class"; +import { MockOnSelectMetroUnlimitedPass210Class } from "./METRO/2.1.0/on_select/on_select_unlimitedpass/class"; +import { MockInitMetroUnlimitedPass210Class } from "./METRO/2.1.0/init/init_unlimitedpass/class"; +import { MockOnInitMetroUnlimitedPass210Class } from "./METRO/2.1.0/on_init/on_init_unlimitedpass/class"; +import { MockConfirmMetroUnlimitedPass210Class } from "./METRO/2.1.0/confirm/confirm_unlimitedpass/class"; +import { MockOnConfirmMetroUnlimitedPass210Class } from "./METRO/2.1.0/on_confirm/on_confirm_unlimitedpass/class"; // helpers type Ctor = new () => T; @@ -285,6 +292,15 @@ const registry = { on_confirm_METRO_PURCHASE_210: MockOnConfirmMetroPurchase210Class, on_confirm_METRO_RECHARGE_210: MockOnConfirmMetroRecharge210Class, + // ***************METRO_UNLIMITED_PASS************ + on_search_Metro_unlimitedpass_210: MockOnSearchMetro_UnlimitedPass210Class, + select_METRO_UNLIMITEDPASS_210: MockSelectMetroUnlimitedPass210Class, + on_select_METRO_UNLIMITEDPASS_210: MockOnSelectMetroUnlimitedPass210Class, + init_METRO_UNLIMITEDPASS_210: MockInitMetroUnlimitedPass210Class, + on_init_METRO_UNLIMITEDPASS_210: MockOnInitMetroUnlimitedPass210Class, + confirm_METRO_UNLIMITEDPASS_210: MockConfirmMetroUnlimitedPass210Class, + on_confirm_METRO_UNLIMITEDPASS_210: MockOnConfirmMetroUnlimitedPass210Class, + // _____________________IGM BUS (2.1.0)____________________________ issue_open: MockIssueOpenClass, issue_escalate: MockIssueEscalateClass, diff --git a/mock-service/src/config/mock-config/TRV11/factory.yaml b/mock-service/src/config/mock-config/TRV11/factory.yaml index fdd91d90..daf52c16 100644 --- a/mock-service/src/config/mock-config/TRV11/factory.yaml +++ b/mock-service/src/config/mock-config/TRV11/factory.yaml @@ -49,6 +49,41 @@ codes: action: on_confirm default: METRO/2.1.0/on_confirm/on_confirm_purchase/default.yaml message_id: false + - code: 144 + action_id: on_search_Metro_unlimitedpass_210 + action: on_search + default: METRO/2.1.0/on_search/on_search_unlimitedpass/default.yaml + message_id: false + - code: 144 + action_id: select_METRO_UNLIMITEDPASS_210 + action: select + default: METRO/2.1.0/select/select_unlimitedpass/default.yaml + message_id: true + - code: 144 + action_id: on_select_METRO_UNLIMITEDPASS_210 + action: on_select + default: METRO/2.1.0/on_select/on_select_unlimitedpass/default.yaml + message_id: false + - code: 144 + action_id: init_METRO_UNLIMITEDPASS_210 + action: init + default: METRO/2.1.0/init/init_unlimitedpass/default.yaml + message_id: true + - code: 144 + action_id: on_init_METRO_UNLIMITEDPASS_210 + action: on_init + default: METRO/2.1.0/on_init/on_init_unlimitedpass/default.yaml + message_id: false + - code: 144 + action_id: confirm_METRO_UNLIMITEDPASS_210 + action: confirm + default: METRO/2.1.0/confirm/confirm_unlimitedpass/default.yaml + message_id: true + - code: 144 + action_id: on_confirm_METRO_UNLIMITEDPASS_210 + action: on_confirm + default: METRO/2.1.0/on_confirm/on_confirm_unlimitedpass/default.yaml + message_id: false - code: 144 action_id: select_METRO_RECHARGE_210 action: select