mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-07-15 20:28:06 +03:00
Add BMIS number support for business customer rates (#30)
* Add BMIS number support for business customer rates Introduces a new `bmisNumber` option to journey requests, allowing bahn.business customers to access corporate rates by providing their 7-digit BMIS number. Adds documentation and a `createBusinessClient` helper for convenience. The request payload now includes a `firmenZugehoerigkeit` object when a BMIS number is set. * Update cspell.config.json Update cspell.config.json to fix spell check issues in PR #30
This commit is contained in:
parent
b59d7b3084
commit
86f2302ad4
4 changed files with 66 additions and 1 deletions
|
@ -95,6 +95,8 @@
|
||||||
"bitmasks",
|
"bitmasks",
|
||||||
"Blaschkoallee",
|
"Blaschkoallee",
|
||||||
"Blissestr",
|
"Blissestr",
|
||||||
|
"bmis",
|
||||||
|
"BMIS",
|
||||||
"BNWNZF",
|
"BNWNZF",
|
||||||
"Böhme",
|
"Böhme",
|
||||||
"BONVOYO",
|
"BONVOYO",
|
||||||
|
@ -195,6 +197,7 @@
|
||||||
"Fehrbelliner",
|
"Fehrbelliner",
|
||||||
"Fernbf",
|
"Fernbf",
|
||||||
"Fernverkehr",
|
"Fernverkehr",
|
||||||
|
"firmen",
|
||||||
"Flexpreis",
|
"Flexpreis",
|
||||||
"Flix",
|
"Flix",
|
||||||
"Fltr",
|
"Fltr",
|
||||||
|
@ -263,6 +266,7 @@
|
||||||
"Hohenzollerndamm",
|
"Hohenzollerndamm",
|
||||||
"Hüngheim",
|
"Hüngheim",
|
||||||
"IBNR",
|
"IBNR",
|
||||||
|
"identifikationsart",
|
||||||
"Ihren",
|
"Ihren",
|
||||||
"Ihrer",
|
"Ihrer",
|
||||||
"Informationen",
|
"Informationen",
|
||||||
|
@ -610,6 +614,7 @@
|
||||||
"Zoologischer",
|
"Zoologischer",
|
||||||
"Zuege",
|
"Zuege",
|
||||||
"zugart",
|
"zugart",
|
||||||
|
"Zugehoerigkeit",
|
||||||
"zugattrib",
|
"zugattrib",
|
||||||
"zugattribute",
|
"zugattribute",
|
||||||
"Zuges",
|
"Zuges",
|
||||||
|
|
|
@ -81,6 +81,7 @@ With `opt`, you can override the default options, which look like this:
|
||||||
firstClass: false, // first or second class for tickets
|
firstClass: false, // first or second class for tickets
|
||||||
loyaltyCard: null, // BahnCards etc., see below
|
loyaltyCard: null, // BahnCards etc., see below
|
||||||
language: 'en', // language to get results in
|
language: 'en', // language to get results in
|
||||||
|
bmisNumber: null, // 7-digit BMIS number for business customer rates
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -316,6 +317,27 @@ hafas.journeys(from, to, {
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Using the `bmisNumber` option
|
||||||
|
|
||||||
|
bahn.business customers with a BMIS number can get their corporate rates and corporate tariffs by providing their 7-digit BMIS number:
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Option 1: Using the bmisNumber parameter directly
|
||||||
|
await client.journeys(from, to, {
|
||||||
|
bmisNumber: '1234567' // Your 7-digit BMIS number
|
||||||
|
})
|
||||||
|
|
||||||
|
// Option 2: Using the createBusinessClient helper function
|
||||||
|
import {createBusinessClient} from 'db-vendo-client'
|
||||||
|
import {profile as dbProfile} from 'db-vendo-client/p/db/index.js'
|
||||||
|
|
||||||
|
const businessClient = createBusinessClient(dbProfile, userAgent, '1234567')
|
||||||
|
// Now all journey searches will automatically include the BMIS number
|
||||||
|
await businessClient.journeys(from, to)
|
||||||
|
```
|
||||||
|
|
||||||
|
When a BMIS number is provided, the request will include a `firmenZugehoerigkeit` object with the BMIS number and identification type, allowing business customers to access their special rates and conditions.
|
||||||
|
|
||||||
## The `routingMode` option
|
## The `routingMode` option
|
||||||
|
|
||||||
The `routingMode` option is not supported by db-vendo-client. The behavior will be the same as the [`HYBRID` mode of hafas-client](https://github.com/public-transport/hafas-client/blob/main/p/db/readme.md#using-the-routingmode-option), i.e. cancelled trains/infeasible journeys will also be contained for informational purpose.
|
The `routingMode` option is not supported by db-vendo-client. The behavior will be the same as the [`HYBRID` mode of hafas-client](https://github.com/public-transport/hafas-client/blob/main/p/db/readme.md#using-the-routingmode-option), i.e. cancelled trains/infeasible journeys will also be contained for informational purpose.
|
28
index.js
28
index.js
|
@ -183,6 +183,7 @@ const createClient = (profile, userAgent, opt = {}) => {
|
||||||
bestprice: false, // search for lowest prices across the entire day
|
bestprice: false, // search for lowest prices across the entire day
|
||||||
deutschlandTicketDiscount: false,
|
deutschlandTicketDiscount: false,
|
||||||
deutschlandTicketConnectionsOnly: false,
|
deutschlandTicketConnectionsOnly: false,
|
||||||
|
bmisNumber: null, // 7-digit BMIS number for business customer rates
|
||||||
}, opt);
|
}, opt);
|
||||||
|
|
||||||
if (opt.when !== undefined) {
|
if (opt.when !== undefined) {
|
||||||
|
@ -243,6 +244,7 @@ const createClient = (profile, userAgent, opt = {}) => {
|
||||||
scheduledDays: false, // parse & expose dates the journey is valid on?
|
scheduledDays: false, // parse & expose dates the journey is valid on?
|
||||||
deutschlandTicketDiscount: false,
|
deutschlandTicketDiscount: false,
|
||||||
deutschlandTicketConnectionsOnly: false,
|
deutschlandTicketConnectionsOnly: false,
|
||||||
|
bmisNumber: null, // 7-digit BMIS number for business customer rates
|
||||||
}, opt);
|
}, opt);
|
||||||
|
|
||||||
const req = profile.formatRefreshJourneyReq({profile, opt}, refreshToken);
|
const req = profile.formatRefreshJourneyReq({profile, opt}, refreshToken);
|
||||||
|
@ -395,7 +397,33 @@ const createClient = (profile, userAgent, opt = {}) => {
|
||||||
return client;
|
return client;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const createBusinessClient = (profile, userAgent, bmisNumber, opt = {}) => {
|
||||||
|
if (!bmisNumber || typeof bmisNumber !== 'string') {
|
||||||
|
throw new TypeError('bmisNumber must be a non-empty string');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a client with BMIS number included in all journey requests
|
||||||
|
const client = createClient(profile, userAgent, opt);
|
||||||
|
|
||||||
|
// Wrap journeys method to always include BMIS number
|
||||||
|
const originalJourneys = client.journeys;
|
||||||
|
client.journeys = async (from, to, opt = {}) => {
|
||||||
|
return originalJourneys(from, to, {...opt, bmisNumber});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Wrap refreshJourney method to always include BMIS number
|
||||||
|
if (client.refreshJourney) {
|
||||||
|
const originalRefreshJourney = client.refreshJourney;
|
||||||
|
client.refreshJourney = async (refreshToken, opt = {}) => {
|
||||||
|
return originalRefreshJourney(refreshToken, {...opt, bmisNumber});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return client;
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
createClient,
|
createClient,
|
||||||
|
createBusinessClient,
|
||||||
loadEnrichedStationData,
|
loadEnrichedStationData,
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@ const formatBaseJourneysReq = (ctx) => {
|
||||||
// TODO opt.accessibility
|
// TODO opt.accessibility
|
||||||
// TODO routingMode
|
// TODO routingMode
|
||||||
const travellers = ctx.profile.formatTravellers(ctx);
|
const travellers = ctx.profile.formatTravellers(ctx);
|
||||||
return {
|
const baseReq = {
|
||||||
autonomeReservierung: false,
|
autonomeReservierung: false,
|
||||||
einstiegsTypList: [
|
einstiegsTypList: [
|
||||||
'STANDARD',
|
'STANDARD',
|
||||||
|
@ -27,6 +27,16 @@ const formatBaseJourneysReq = (ctx) => {
|
||||||
},
|
},
|
||||||
reservierungsKontingenteVorhanden: false,
|
reservierungsKontingenteVorhanden: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Add business customer affiliation if BMIS number is provided
|
||||||
|
if (ctx.opt.bmisNumber) {
|
||||||
|
baseReq.firmenZugehoerigkeit = {
|
||||||
|
bmisNr: ctx.opt.bmisNumber,
|
||||||
|
identifikationsart: 'BMIS',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return baseReq;
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatJourneysReq = (ctx, from, to, when, outFrwd, journeysRef) => {
|
const formatJourneysReq = (ctx, from, to, when, outFrwd, journeysRef) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue