Refund Manager Embed
The Refund Manager embed is a modal for refunding the items of an order. It shows both the earlier refunds and the items that can still be refunded.
The modal lists the order's items, grouped by journey. Items that can still be refunded show what was paid and what the traveler gets back. Items that have already been refunded show the status of their refund. The user selects one or more items and requests the refund, and the embed makes the API calls.
The Refund Manager 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-refund-manager-modal.js"
type="module"></script>The script registers the custom element aa-refund-manager-modal. You can then use it like any other HTML element.
To open the modal, render the element with the open attribute, or set open from JavaScript.
<aa-refund-manager-modal
open
publicApiKey="aat_your-access-token-here"
order="order_55q7y697r6s371j2x6m294n1f2"></aa-refund-manager-modal><aa-refund-manager-modal
id="my-refund-modal"
publicApiKey="aat_your-access-token-here"
order="order_55q7y697r6s371j2x6m294n1f2"></aa-refund-manager-modal>
<button type="button" id="button">Manage refunds</button>
<script>
const button = document.getElementById('button')
const modal = document.getElementById('my-refund-modal')
button.addEventListener('click', () => {
modal.open = true
})
</script>Credentials
This embed runs on public web pages, so anyone who views the page can see what you pass as publicApiKey. The embed works on an existing order. It reads the order's refund history and refundable items, and starts refunds on it. An API key that can do that for one order can do it for every order on your sales agent, so never put an API key in this attribute.
Pass an access token instead. Mint one on your server for the order the modal is opened on, with both capabilities, and render it into the page:
mutation CreateAccessToken {
createAccessToken(
restrictions: { orderId: "order_55q7y697r6s371j2x6m294n1f2" }
capabilities: [READ, WRITE]
) {
token
}
}Mint a new token each time you render the page, and put the returned token in the embed's publicApiKey attribute. The attribute keeps its name, although the value is a token. A token is valid for 15 minutes by default.
A token only reaches the order it was minted for, and only until it expires. A visitor who copies it from the page can refund and pay for that order until then, and can't do anything to your other orders.
For which credential each embed takes, see Configuring embeds safely.
Attributes
Set these attributes on the <aa-refund-manager-modal> element to tell it which order to show.
| Name | Description | Required |
|---|---|---|
publicApiKey |
An access token minted for this order with the READ and WRITE capabilities. See Credentials above. |
Yes |
order |
The order ID to manage refunds for. | Yes |
open |
Whether the modal is open. This is a boolean attribute: its presence opens the modal and removing it closes it. From JavaScript, set the open property to true or false. |
No |
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 to use for the modal. For example, en 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 Refund Manager's events with addEventListener, for example to update your page when a refund has been processed, or to handle errors.
| Name | Description |
|---|---|
aa-refund-manager-modal-refund |
Emitted when a refund has been requested, whatever the outcome. The event's detail has the Refund as refund. Check its state, which is SUCCEEDED, PENDING or ERROR. |
aa-refund-manager-modal-error |
Emitted when an error occurs. The event's detail has the error, which you can use to show an error message. |
aa-refund-manager-modal-close |
Emitted when the modal is closed, so you can update your page or clean up. |
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 credential in publicApiKey is refused, for example because the access token has expired. Other failures are reported through the aa-refund-manager-modal-error event.
<aa-refund-manager-modal
publicApiKey="aat_your-access-token-here"
order="order_55q7y697r6s371j2x6m294n1f2">
<p slot="error">Oops, something went wrong.</p>
</aa-refund-manager-modal>success
Use the success slot to show your own message when a refund has been requested. It is shown above the list after a refund has succeeded or is pending, and not if the refund fails. The content is rendered as you provide it, so style it to fit your site.
<aa-refund-manager-modal
publicApiKey="aat_your-access-token-here"
order="order_55q7y697r6s371j2x6m294n1f2">
<div slot="success">
<strong>Your refund is on its way.</strong>
<p>It can take a few days before the money shows up in your account.</p>
</div>
</aa-refund-manager-modal>Example
This Refund Manager runs on a made-up order: a return journey between Paris and Lille for Jane and John Doe, with John's outbound ticket refunded already. Select one or more of the other tickets and refund them to see the success slot from above. The order is dummy data, so nothing is actually refunded.