Payment result
Back from the payment system: the result of the payment, once, on the page the payment was made for.
Data sources
| Property | Purpose |
|---|---|
store.localeCode | Application Load response. |
Short description
The payment system's Success URL /accounts/orders/latest/success and Fail URL /accounts/orders/latest/failed (no query; /accounts/orders/latest alone works too) open the storefront's return page, which answers GET and POST. Inside the payment frame it moves the whole window out of the frame, back to the page the payment was opened for: the order for an order payment, the wallet for a top-up; the wallet when no page is remembered. That page shows this window once: «Payment received» or «Payment not completed». A result older than 10 minutes is dropped. The payment's own status always comes from the order or the wallet.
Live preview
The window after a successful payment, shown in the page instead of over it.
Inputs
| Property | Purpose | Value | Editor |
|---|---|---|---|
result?: TPaymentReturnResult | success or failed: shows this result instead of the one the return page left. Without it the component reads the result once from the tab's sessionStorage. | undefined | Supplied by the live example |
modal?: boolean | false keeps the window in the page instead of over it; the guide uses it. Default: true. | true | Supplied by the live example |
Events
This component emits no events.
Source files
app/components/basklee/payments/PaymentReturnNotice.vue
<script setup lang="ts">
import '@/components/basklee/shared/dialogs.css';
import '@/components/basklee/shared/features.css';
import { computed, nextTick, onBeforeUnmount, onMounted, ref, useId } from 'vue';
import { useBaskleeStore } from '@/stores/basklee';
import {
isPaymentReturnPath,
takePaymentResult,
} from '@/utils/basklee/paymentReturn';
import type { TPaymentReturnResult } from '@/utils/basklee/paymentReturn';
import { paymentReturnLabels } from '@/utils/basklee/paymentReturnLabels';
import {
createPageScrollLock,
focusedElement,
restoreFocus,
} from '@/utils/basklee/modalWindow';
/*
* The result of a payment, once, on the page the gateway's return page
* (…/accounts/orders/latest/success|failed) came back to. `result` shows a
* given result instead and `modal: false` keeps the window in the page
* (documentation previews).
*/
const props = withDefaults(
defineProps<{ result?: TPaymentReturnResult; modal?: boolean }>(),
{ result: undefined, modal: true },
);
const store = useBaskleeStore();
const id = useId();
const dialog = ref<HTMLDialogElement>();
const shown = ref<TPaymentReturnResult>();
const labels = computed(() => paymentReturnLabels(store.localeCode));
const copy = computed(() =>
shown.value === 'success' ? labels.value.success : labels.value.failed,
);
const pageScroll = createPageScrollLock();
let opener: HTMLElement | undefined;
function close() {
dialog.value?.close();
shown.value = undefined;
if (pageScroll.locked) {
pageScroll.unlock();
restoreFocus(opener);
}
}
function backdrop(event: MouseEvent) {
if (props.modal && event.target === dialog.value) {
close();
}
}
onMounted(async () => {
shown.value = props.result ??
(isPaymentReturnPath(window.location.pathname)
? undefined
: takePaymentResult());
if (!shown.value) {
return;
}
await nextTick();
if (!props.modal) {
// Opened by its attribute, not show(): the focus stays where it is.
dialog.value?.setAttribute('open', '');
return;
}
opener = focusedElement();
pageScroll.lock();
dialog.value?.showModal();
});
onBeforeUnmount(() => pageScroll.unlock());
</script>
<template>
<dialog
v-if="shown"
ref="dialog"
data-stable-modal="fit"
:data-payment-return-notice="shown"
:aria-labelledby="`${id}-title`"
:aria-describedby="`${id}-text`"
:class="
modal
? 'm-auto w-[420px] max-w-[calc(100vw-32px)]'
: 'relative m-0 w-full max-w-[420px]'
"
class="
box-border rounded-none p-0
border border-solid border-basklee-border
bg-basklee-surface font-basklee text-basklee-text
backdrop:bg-black/35 backdrop:backdrop-blur-[2px]
"
@cancel.prevent="close"
@click="backdrop"
>
<div class="grid gap-5 p-6">
<h2
:id="`${id}-title`"
class="m-0 text-lg uppercase tracking-[0.04em]"
>
{{ copy.title }}
</h2>
<p
:id="`${id}-text`"
class="op-notice m-0"
:class="shown === 'success' ? 'op-notice-success' : 'op-notice-error'"
role="status"
>
{{ copy.text }}
</p>
<button
type="button"
class="
flex h-11 items-center justify-center justify-self-start px-6
cursor-pointer border border-solid border-basklee-accent
bg-basklee-accent
text-xs uppercase tracking-[0.08em] text-basklee-surface
[font-family:inherit]
outline-none transition-opacity motion-reduce:transition-none
hover:opacity-85 focus-visible:opacity-85
"
data-payment-return-continue
@click="close"
>
{{ labels.continue }}
</button>
</div>
</dialog>
</template>