@uappi/public-sdk 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -17,6 +17,7 @@ const iframeEl = ref<HTMLIFrameElement | null>(null);
|
|
|
17
17
|
const paymentToken = ref<string | null>(null);
|
|
18
18
|
const loadingToken = ref(true);
|
|
19
19
|
const tokenError = ref<string | null>(null);
|
|
20
|
+
const iframeHeight = ref<number | null>(null);
|
|
20
21
|
|
|
21
22
|
const iframeSrc = computed(() => {
|
|
22
23
|
if (!paymentToken.value) return '';
|
|
@@ -66,12 +67,13 @@ async function fetchPaymentToken(): Promise<void> {
|
|
|
66
67
|
function handleIframeMessage(event: MessageEvent): void {
|
|
67
68
|
if (!iframeEl.value || event.source !== iframeEl.value.contentWindow) return;
|
|
68
69
|
|
|
69
|
-
const { type, data, url, errorCode, message } = (event.data ?? {}) as {
|
|
70
|
+
const { type, data, url, errorCode, message, height } = (event.data ?? {}) as {
|
|
70
71
|
type: string;
|
|
71
72
|
data: PaymentSuccessData & PaymentRedirectData;
|
|
72
73
|
url: string;
|
|
73
74
|
errorCode: string | undefined;
|
|
74
75
|
message: string;
|
|
76
|
+
height: number | undefined;
|
|
75
77
|
};
|
|
76
78
|
|
|
77
79
|
switch (type) {
|
|
@@ -90,6 +92,10 @@ function handleIframeMessage(event: MessageEvent): void {
|
|
|
90
92
|
case 'UAPPI_PAYMENT_ERROR':
|
|
91
93
|
emit('payment-error', errorCode, message);
|
|
92
94
|
break;
|
|
95
|
+
|
|
96
|
+
case 'UAPPI_PAYMENT_RESIZE':
|
|
97
|
+
if (typeof height === 'number' && height > 0) iframeHeight.value = height;
|
|
98
|
+
break;
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
101
|
|
|
@@ -101,13 +107,14 @@ onMounted(async () => {
|
|
|
101
107
|
onUnmounted(() => {
|
|
102
108
|
window.removeEventListener('message', handleIframeMessage);
|
|
103
109
|
});
|
|
110
|
+
|
|
104
111
|
</script>
|
|
105
112
|
|
|
106
113
|
<template>
|
|
107
|
-
<div class="payment-hosted
|
|
108
|
-
<div v-if="loadingToken" class="payment-
|
|
114
|
+
<div class="payment-hosted">
|
|
115
|
+
<div v-if="loadingToken" class="payment-hosted__skeleton" />
|
|
109
116
|
|
|
110
|
-
<p v-else-if="tokenError" class="payment-
|
|
117
|
+
<p v-else-if="tokenError" class="payment-hosted__error">
|
|
111
118
|
{{ tokenError }}
|
|
112
119
|
</p>
|
|
113
120
|
|
|
@@ -115,7 +122,8 @@ onUnmounted(() => {
|
|
|
115
122
|
v-else-if="iframeSrc"
|
|
116
123
|
ref="iframeEl"
|
|
117
124
|
:src="iframeSrc"
|
|
118
|
-
|
|
125
|
+
:style="iframeHeight ? { height: `${iframeHeight}px` } : undefined"
|
|
126
|
+
class="payment-hosted__iframe"
|
|
119
127
|
frameborder="0"
|
|
120
128
|
scrolling="no"
|
|
121
129
|
title="Formulário de pagamento seguro"
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
.payment-hosted
|
|
1
|
+
.payment-hosted {
|
|
2
2
|
width: 100%;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
.payment-
|
|
5
|
+
.payment-hosted__iframe {
|
|
6
6
|
display: block;
|
|
7
7
|
width: 100%;
|
|
8
|
-
height: 100%;
|
|
9
8
|
min-height: 420px;
|
|
10
9
|
border: none;
|
|
10
|
+
transition: height 0.2s ease;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
.payment-
|
|
13
|
+
.payment-hosted__skeleton {
|
|
14
14
|
width: 100%;
|
|
15
15
|
height: 420px;
|
|
16
16
|
border-radius: 4px;
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
var(--neutral-surface-low) 63%
|
|
22
22
|
);
|
|
23
23
|
background-size: 400% 100%;
|
|
24
|
-
animation: payment-hosted-
|
|
24
|
+
animation: payment-hosted-skeleton 1.4s ease infinite;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
@keyframes payment-hosted-
|
|
27
|
+
@keyframes payment-hosted-skeleton {
|
|
28
28
|
0% { background-position: 100% 50%; }
|
|
29
29
|
100% { background-position: 0 50%; }
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
.payment-
|
|
32
|
+
.payment-hosted__error {
|
|
33
33
|
margin: 0;
|
|
34
34
|
padding: 16px;
|
|
35
35
|
text-align: center;
|
package/components/README.md
CHANGED
|
@@ -25,6 +25,8 @@ Renderiza o formulário de pagamento (cartão, etc.) dentro de um `<iframe>` iso
|
|
|
25
25
|
|
|
26
26
|
O componente busca um token de pagamento via `api.cart.paymentToken` ao montar, monta a URL do iframe com esse token, e escuta `postMessage` do iframe para emitir eventos de pagamento. Mensagens de janelas que não sejam o `contentWindow` do próprio iframe são ignoradas.
|
|
27
27
|
|
|
28
|
+
A altura do iframe tem um piso definido em CSS (`min-height`), mas se ajusta automaticamente ao conteúdo quando o `render.uappi` envia `postMessage({ type: 'UAPPI_PAYMENT_RESIZE', height })` (`height` em pixels, número do conteúdo real do formulário). Isso é necessário porque o iframe é cross-origin — o componente não tem acesso ao `contentDocument` para medir a altura sozinho. Sem esse evento, o iframe mantém apenas o `min-height` fixo.
|
|
29
|
+
|
|
28
30
|
```vue
|
|
29
31
|
<script setup lang="ts">
|
|
30
32
|
import { PaymentHosted } from '@uappi/public-sdk';
|