Результат оплаты
Возврат из платёжной системы: результат оплаты один раз на странице, для которой открывалась оплата.
Источники данных
| Свойство | Назначение |
|---|---|
store.localeCode | Ответ Application Load. |
Краткое описание
Success URL /accounts/orders/latest/success и Fail URL /accounts/orders/latest/failed платёжной системы (без параметров; подходит и просто /accounts/orders/latest) открывают страницу возврата магазина; она отвечает на GET и POST. Внутри окна оплаты она выводит из него всю вкладку и возвращает на страницу, для которой открывалась оплата: к заказу при оплате заказа, в кошелёк при пополнении; в кошелёк — если страница не запомнена. Там это окно показывается один раз: «Оплата получена» или «Оплата не прошла». Результат старше 10 минут не показывается. Состояние самого платежа всегда берётся из заказа или кошелька.
Живой пример
Окно после успешной оплаты, показанное на странице, а не поверх неё.
Входящие значения
| Свойство | Назначение | Значение | Редактор |
|---|---|---|---|
result?: TPaymentReturnResult | success или failed: показывает этот результат вместо оставленного страницей возврата. Без него компонент один раз читает результат из sessionStorage вкладки. | undefined | Значение задаёт живой пример |
modal?: boolean | false оставляет окно на странице, а не поверх неё; так оно показано в этом руководстве. По умолчанию true. | true | Значение задаёт живой пример |
События
Компонент не создаёт событий.
Исходные файлы
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>