@uappi/public-sdk 1.4.0 → 1.4.2
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.
- package/components/{PaymentHostedFields/PaymentHostedFields.vue → PaymentHosted/PaymentHosted.vue} +3 -3
- package/components/PaymentHosted/index.ts +1 -0
- package/components/{PaymentHostedFields → PaymentHosted}/styles.scoped.css +1 -0
- package/components/README.md +163 -0
- package/components/index.ts +1 -1
- package/package.json +1 -1
- package/components/PaymentHostedFields/index.ts +0 -1
- /package/components/{PaymentHostedFields → PaymentHosted}/types.ts +0 -0
package/components/{PaymentHostedFields/PaymentHostedFields.vue → PaymentHosted/PaymentHosted.vue}
RENAMED
|
@@ -5,7 +5,7 @@ import api from '../../modules/Api';
|
|
|
5
5
|
|
|
6
6
|
import type { Props, Emits, PaymentSuccessData, PaymentRedirectData } from './types';
|
|
7
7
|
|
|
8
|
-
// `
|
|
8
|
+
// `PaymentHosted` renderiza o formulário de pagamento via iframe isolado,
|
|
9
9
|
// servido pelo serviço `render.uappi`. Todos os dados sensíveis (número do cartão,
|
|
10
10
|
// CVV, etc.) trafegam diretamente entre o iframe e o gateway, sem passar pela loja.
|
|
11
11
|
const props = defineProps<Props>();
|
|
@@ -44,14 +44,14 @@ async function fetchPaymentToken(): Promise<void> {
|
|
|
44
44
|
const response = await api.cart.paymentToken({ paymentOptionId: props.option.id });
|
|
45
45
|
|
|
46
46
|
if (!response?.token) {
|
|
47
|
-
console.error('[
|
|
47
|
+
console.error('[PaymentHosted] Token ausente na resposta:', response);
|
|
48
48
|
tokenError.value = 'Não foi possível iniciar o formulário de pagamento.';
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
paymentToken.value = response.token;
|
|
53
53
|
} catch (err) {
|
|
54
|
-
console.error('[
|
|
54
|
+
console.error('[PaymentHosted] Erro ao buscar token de pagamento:', err);
|
|
55
55
|
tokenError.value = 'Não foi possível iniciar o formulário de pagamento.';
|
|
56
56
|
} finally {
|
|
57
57
|
loadingToken.value = false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as PaymentHosted } from './PaymentHosted.vue';
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# ../../components
|
|
2
|
+
|
|
3
|
+
Componentes Vue 3 + TypeScript prontos para uso nas lojas do ecossistema Uappi.
|
|
4
|
+
|
|
5
|
+
## Instalação
|
|
6
|
+
|
|
7
|
+
Adicione ao seu projeto:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @uappi/public-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Componentes Disponíveis
|
|
14
|
+
|
|
15
|
+
- [**PaymentHosted**](#PaymentHosted): Formulário de pagamento hospedado via iframe isolado (render.uappi).
|
|
16
|
+
- [**ColorTheme**](#colortheme): Aplica variáveis CSS de cor e fonte customizadas da loja no `document.documentElement`.
|
|
17
|
+
- [**SocialAuth**](#socialauth): Botões de login social (`GoogleAuth`, `FacebookAuth`) via OAuth em popup.
|
|
18
|
+
- [**Animations**](#animations): Utilitários de transição (`ExpandTransition`).
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## [PaymentHosted](#PaymentHosted)
|
|
23
|
+
|
|
24
|
+
Renderiza o formulário de pagamento (cartão, etc.) dentro de um `<iframe>` isolado, servido pelo serviço `render.uappi`. Dados sensíveis (número do cartão, CVV, etc.) trafegam diretamente entre o iframe e o gateway, sem passar pela loja.
|
|
25
|
+
|
|
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
|
+
|
|
28
|
+
```vue
|
|
29
|
+
<script setup lang="ts">
|
|
30
|
+
import { PaymentHosted } from '@uappi/public-sdk';
|
|
31
|
+
import type { PaymentSuccessData, PaymentRedirectData } from '@uappi/public-sdk';
|
|
32
|
+
|
|
33
|
+
function onSuccess(data: PaymentSuccessData) {
|
|
34
|
+
// pedido criado, mesmo formato de api.cart.buy
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function onRedirect(url: string, data: PaymentRedirectData) {
|
|
38
|
+
// gateway pediu redirecionamento (ex: 3DS)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function onError(errorCode: string | undefined, message: string) {
|
|
42
|
+
// falha reportada pelo render.uappi
|
|
43
|
+
}
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<template>
|
|
47
|
+
<PaymentHosted
|
|
48
|
+
:option="selectedPaymentOption"
|
|
49
|
+
cta-color="#FF0000"
|
|
50
|
+
lang="pt-BR"
|
|
51
|
+
country-code="BRA"
|
|
52
|
+
@payment-ready="onReady"
|
|
53
|
+
@payment-success="onSuccess"
|
|
54
|
+
@payment-redirect="onRedirect"
|
|
55
|
+
@payment-error="onError"
|
|
56
|
+
/>
|
|
57
|
+
</template>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Props
|
|
61
|
+
|
|
62
|
+
| Prop | Tipo | Obrigatório | Descrição |
|
|
63
|
+
|---|---|---|---|
|
|
64
|
+
| `option` | `PaymentOption` | Sim | Opção de pagamento selecionada (item retornado por `api.cart.listPayments`). |
|
|
65
|
+
| `ctaColor` | `string` | Não | Cor hex do botão CTA do iframe (com ou sem `#`). Padrão: cor do render.uappi. |
|
|
66
|
+
| `lang` | `string` | Não | Locale do formulário (`pt-BR`, `en-US`, `es-ES`, ...). Padrão: `pt-BR`. |
|
|
67
|
+
| `countryCode` | `string` | Não | Código Alpha-3 para pré-selecionar o DDI do telefone (`BRA`, `USA`, ...). Padrão: `BRA`. |
|
|
68
|
+
| `iframeHost` | `string` | Não | Host do serviço render.uappi. Sobrescreve `VITE_PAYMENT_IFRAME_HOST` quando informado. |
|
|
69
|
+
|
|
70
|
+
### Eventos
|
|
71
|
+
|
|
72
|
+
| Evento | Payload | Quando é emitido |
|
|
73
|
+
|---|---|---|
|
|
74
|
+
| `payment-ready` | — | Iframe carregou e está pronto para interação. |
|
|
75
|
+
| `payment-success` | `data: PaymentSuccessData` | Pagamento concluído; `data` tem o mesmo formato de `api.cart.buy`. |
|
|
76
|
+
| `payment-redirect` | `url: string, data: PaymentRedirectData` | Gateway exige redirecionamento (ex: autenticação 3DS). |
|
|
77
|
+
| `payment-error` | `errorCode: string \| undefined, message: string` | Falha ao processar o pagamento. |
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## [ColorTheme](#colortheme)
|
|
82
|
+
|
|
83
|
+
Aplica cores e fonte customizadas da loja como variáveis CSS globais (`--primary-cta-text`, `--checkout-cta-default`, `--font-family`, etc.) assim que é montado. Não renderiza elementos próprios — repassa o slot padrão via `Fragment`.
|
|
84
|
+
|
|
85
|
+
```vue
|
|
86
|
+
<script setup lang="ts">
|
|
87
|
+
import { ColorTheme } from '@uappi/public-sdk';
|
|
88
|
+
import type { CSSVariables } from '@uappi/public-sdk';
|
|
89
|
+
|
|
90
|
+
const variables: CSSVariables = {
|
|
91
|
+
font: { family: 'Inter', link: 'https://fonts.googleapis.com/css2?family=Inter' },
|
|
92
|
+
colors: {
|
|
93
|
+
CheckoutCTADefault: '#000000',
|
|
94
|
+
CheckoutCTAHover: '#333333',
|
|
95
|
+
CheckoutCTAText: '#FFFFFF',
|
|
96
|
+
PrimaryCTAText: '#FFFFFF',
|
|
97
|
+
PrimaryInteractiveDefault: '#000000',
|
|
98
|
+
PrimaryInteractiveHover: '#333333',
|
|
99
|
+
PrimaryInteractiveHoverLow: '#666666',
|
|
100
|
+
PrimarySurfaceDisabled: '#CCCCCC',
|
|
101
|
+
PrimarySurfaceLow: '#F5F5F5',
|
|
102
|
+
PrimaryTextDecorative: '#000000',
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
</script>
|
|
106
|
+
|
|
107
|
+
<template>
|
|
108
|
+
<ColorTheme :variables="variables">
|
|
109
|
+
<App />
|
|
110
|
+
</ColorTheme>
|
|
111
|
+
</template>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## [SocialAuth](#socialauth)
|
|
117
|
+
|
|
118
|
+
- `GoogleAuth` / `FacebookAuth`: botão de login social que abre um popup OAuth via `api.thirdParty.oauthRedirect`.
|
|
119
|
+
|
|
120
|
+
```vue
|
|
121
|
+
<script setup lang="ts">
|
|
122
|
+
import { GoogleAuth, FacebookAuth } from '@uappi/public-sdk';
|
|
123
|
+
</script>
|
|
124
|
+
|
|
125
|
+
<template>
|
|
126
|
+
<GoogleAuth uri="/conta" />
|
|
127
|
+
<FacebookAuth uri="/conta" />
|
|
128
|
+
</template>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
| Prop | Tipo | Obrigatório | Descrição |
|
|
132
|
+
|---|---|---|---|
|
|
133
|
+
| `uri` | `string` | Sim | Prefixo de rota da loja usado para montar as URLs de callback (`{uri}/signin`, `{uri}/signup`). |
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## [Animations](#animations)
|
|
138
|
+
|
|
139
|
+
- `ExpandTransition`: wrapper sobre `<Transition>` do Vue que anima altura e opacidade (expandir/colapsar), útil para acordeões e listas condicionais.
|
|
140
|
+
|
|
141
|
+
```vue
|
|
142
|
+
<script setup lang="ts">
|
|
143
|
+
import { ExpandTransition } from '@uappi/public-sdk';
|
|
144
|
+
</script>
|
|
145
|
+
|
|
146
|
+
<template>
|
|
147
|
+
<ExpandTransition>
|
|
148
|
+
<div v-if="open">Conteúdo</div>
|
|
149
|
+
</ExpandTransition>
|
|
150
|
+
</template>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
| Prop | Tipo | Obrigatório | Descrição |
|
|
154
|
+
|---|---|---|---|
|
|
155
|
+
| `mode` | `BaseTransitionProps['mode']` | Não | Modo de transição do Vue (`in-out`, `out-in`, `default`). Padrão: `out-in`. |
|
|
156
|
+
|
|
157
|
+
## Contribuição
|
|
158
|
+
|
|
159
|
+
Contribuições são bem-vindas! Abra uma issue ou envie um pull request.
|
|
160
|
+
|
|
161
|
+
## Licença
|
|
162
|
+
|
|
163
|
+
ISC
|
package/components/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as PaymentHostedFields } from './PaymentHostedFields.vue';
|
|
File without changes
|