Offer Selection Embed
The Offer Selection embed lets the user choose an offer, place properties and ancillaries for one JourneyOfferSelection of a booking.
You give it a booking id and an offer id. It shows all the offers of the JourneyOfferSelection that the offer belongs to, grouped by service class, flexibility and comfort class, so the user can find the one that suits them. If the offer has place properties or ancillaries, they are shown as well.
The embed updates the booking for you. When the user has made a selection and it has been confirmed, the embed emits the aa-offer-selection-change event.
The Offer Selection is responsive and adapts to the user's screen size. Scroll down to see an example.
Getting started
First load the script. It is a standard JavaScript module, so the script tag needs type="module".
<script
src="https://allaboard.eu/embed/aa-offer-selection.js"
type="module"></script>The script registers the custom element aa-offer-selection. You can then use it like any other HTML element.
<aa-offer-selection
publicApiKey="your-api-key-here"
booking="booking_j3x2j3x5v1y3d706v7r500v3w2"
offer="offer_t221w0f0d201d655p3y3c7v5s6">
</aa-offer-selection>Cost centers and API keys
This embed runs on public web pages, so anyone who views the page can see its publicApiKey. Give it a key with only the base scope and the payment gateway scope: live and live:payments:stripe, or test and test:payments:stripe when testing. Never use a key that can read your orders or spend your wallet. Configuring embeds safely explains why.
The Offer Selection only changes what is selected on a booking you have created. It doesn't create an order or a payment. You do that in your own code, when the passenger is done choosing.
Attributes
Set these attributes on the <aa-offer-selection> element to tell it which offers to show.
| Name | Description | Required |
|---|---|---|
publicApiKey |
Your public API key. You can find your API key in the Dashboard. | Yes |
booking |
The id of the booking. | Yes |
offer |
The id of the currently selected offer. The embed shows the offers of the JourneyOfferSelection it belongs to. | Yes |
sessionId |
The session ID to use when calling the API. Can be any unique string that identifies the session. Used for analytics and troubleshooting. | No |
language |
The language of the embed: en (the default), da, de, es, fr, nb or sv. |
No |
theme |
The color theme: light (the default), dark, or auto, which follows the visitor's light or dark system setting. |
No |
Events
Listen for the Offer Selection's events with addEventListener, for example to update the booking's total price when an offer is selected.
| Name | Description |
|---|---|
aa-offer-selection-change |
Emitted when an Offer, PlaceProperty, Placement or Ancillary is updated. The event's detail has the offerId. If you fetch the booking, this offer is now the selected one. |
aa-offer-selection-error |
Emitted when an error occurs. The event's detail has the error, which you can use to show an error message. |
Slots
Custom elements use slots to show your own markup inside the element.
error
Use the error slot to show your own message when the booking fails to load. The slot is not shown when a selection can't be saved. The embed then goes back to the previous selection and emits aa-offer-selection-error, so listen for that event to tell the passenger.
<aa-offer-selection
publicApiKey="your-api-key-here"
booking="booking_w2e452e5m765a5n25677k7g105"
offer="offer_m484c490z2b2n7v5k770c7s3z6">
<p slot="error">Could not load the booking</p>
</aa-offer-selection>Example
Change the selection and the language to see the embed update.