@uappi/public-sdk 1.4.3 → 1.6.0
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/PaymentHosted/PaymentHosted.vue +23 -1
- package/modules/Api/endpoints/PromotionalForecastComposable.ts +11 -0
- package/modules/Api/index.ts +2 -0
- package/modules/Api/types/context/api-params.types.ts +3 -0
- package/modules/Api/types/endpoints/promotional-forecast/promotional-forecast.interfaces.ts +11 -0
- package/modules/Api/types/index.ts +8 -0
- package/package.json +1 -1
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import { ref, computed, onMounted, onUnmounted } from 'vue';
|
|
3
3
|
|
|
4
4
|
import api from '../../modules/Api';
|
|
5
|
+
import { purchaseAction } from '../../modules/Tracking/events/actions/purchase';
|
|
5
6
|
|
|
6
7
|
import type { Props, Emits, PaymentSuccessData, PaymentRedirectData } from './types';
|
|
8
|
+
import type { CartResponse } from '../../modules/Api/types';
|
|
7
9
|
|
|
8
10
|
// `PaymentHosted` renderiza o formulário de pagamento via iframe isolado,
|
|
9
11
|
// servido pelo serviço `render.uappi`. Todos os dados sensíveis (número do cartão,
|
|
@@ -19,6 +21,13 @@ const loadingToken = ref(true);
|
|
|
19
21
|
const tokenError = ref<string | null>(null);
|
|
20
22
|
const iframeHeight = ref<number | null>(null);
|
|
21
23
|
|
|
24
|
+
// Snapshot do carrinho anterior à compra, usado apenas para disparar o evento
|
|
25
|
+
// `purchase` do GTM quando o `UAPPI_PAYMENT_SUCCESS` chegar. É necessário buscar
|
|
26
|
+
// esse dado antes do pagamento porque, após o sucesso, o carrinho já foi
|
|
27
|
+
// consumido pelo `/cart/buy` (chamado internamente pelo iframe) e não reflete
|
|
28
|
+
// mais os itens/frete/descontos da compra que acabou de ser feita.
|
|
29
|
+
const cartSnapshot = ref<CartResponse | null>(null);
|
|
30
|
+
|
|
22
31
|
const iframeSrc = computed(() => {
|
|
23
32
|
if (!paymentToken.value) return '';
|
|
24
33
|
|
|
@@ -59,6 +68,14 @@ async function fetchPaymentToken(): Promise<void> {
|
|
|
59
68
|
}
|
|
60
69
|
}
|
|
61
70
|
|
|
71
|
+
async function fetchCartSnapshot(): Promise<void> {
|
|
72
|
+
try {
|
|
73
|
+
cartSnapshot.value = await api.cart.listDetail();
|
|
74
|
+
} catch (err) {
|
|
75
|
+
console.error('[PaymentHosted] Erro ao buscar carrinho para tracking de compra:', err);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
62
79
|
/**
|
|
63
80
|
* Só processa mensagens cuja origem seja a própria janela do iframe renderizado
|
|
64
81
|
* por este componente, evitando que outra janela/frame na página finja ser o
|
|
@@ -82,6 +99,11 @@ function handleIframeMessage(event: MessageEvent): void {
|
|
|
82
99
|
break;
|
|
83
100
|
|
|
84
101
|
case 'UAPPI_PAYMENT_SUCCESS':
|
|
102
|
+
if (cartSnapshot.value) {
|
|
103
|
+
purchaseAction(props.option.paymentType.code, cartSnapshot.value);
|
|
104
|
+
} else {
|
|
105
|
+
console.error('[PaymentHosted] Carrinho indisponível: evento de tracking de compra (purchase) não foi disparado.');
|
|
106
|
+
}
|
|
85
107
|
emit('payment-success', data);
|
|
86
108
|
break;
|
|
87
109
|
|
|
@@ -101,7 +123,7 @@ function handleIframeMessage(event: MessageEvent): void {
|
|
|
101
123
|
|
|
102
124
|
onMounted(async () => {
|
|
103
125
|
window.addEventListener('message', handleIframeMessage);
|
|
104
|
-
await fetchPaymentToken();
|
|
126
|
+
await Promise.all([fetchPaymentToken(), fetchCartSnapshot()]);
|
|
105
127
|
});
|
|
106
128
|
|
|
107
129
|
onUnmounted(() => {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { usePublicApi } from '..';
|
|
2
|
+
|
|
3
|
+
import type { PromotionalForecastResponse } from '../types';
|
|
4
|
+
|
|
5
|
+
export function getPromotionalForecast(productId: number) {
|
|
6
|
+
return usePublicApi<PromotionalForecastResponse>({
|
|
7
|
+
endpoint: '/publics/products/promotional-forecast',
|
|
8
|
+
method: 'GET',
|
|
9
|
+
params: { productId },
|
|
10
|
+
});
|
|
11
|
+
}
|
package/modules/Api/index.ts
CHANGED
|
@@ -56,6 +56,7 @@ import { createInterest } from './endpoints/InterestComposable';
|
|
|
56
56
|
import { loggout } from './endpoints/LoggoutComposable';
|
|
57
57
|
import { listMenu } from './endpoints/MenuComposable';
|
|
58
58
|
import { listPairOffers } from './endpoints/PairOfferComposable';
|
|
59
|
+
import { getPromotionalForecast } from './endpoints/PromotionalForecastComposable';
|
|
59
60
|
import { paymentConditions } from './endpoints/PaymentComposable';
|
|
60
61
|
import {
|
|
61
62
|
deleteProductComment,
|
|
@@ -190,6 +191,7 @@ const promotional = {
|
|
|
190
191
|
deleteWallet,
|
|
191
192
|
applyPoint,
|
|
192
193
|
deletePoint,
|
|
194
|
+
getPromotionalForecast,
|
|
193
195
|
};
|
|
194
196
|
|
|
195
197
|
const notify = {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface PromotionalForecastPointSystem {
|
|
2
|
+
name: string;
|
|
3
|
+
pointValue: number;
|
|
4
|
+
finalAmount: number;
|
|
5
|
+
finalValue: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface PromotionalForecastResponse {
|
|
9
|
+
pointSystem: PromotionalForecastPointSystem | null;
|
|
10
|
+
promotions: Array<Record<string, unknown>>;
|
|
11
|
+
}
|
|
@@ -143,6 +143,10 @@ import type {
|
|
|
143
143
|
PairOffer,
|
|
144
144
|
PairOfferResponse,
|
|
145
145
|
} from './endpoints/pair-offer/pair-offer.interfaces';
|
|
146
|
+
import type {
|
|
147
|
+
PromotionalForecastPointSystem,
|
|
148
|
+
PromotionalForecastResponse,
|
|
149
|
+
} from './endpoints/promotional-forecast/promotional-forecast.interfaces';
|
|
146
150
|
import type {
|
|
147
151
|
Payment,
|
|
148
152
|
PaymentConfiguration,
|
|
@@ -354,6 +358,10 @@ export type {
|
|
|
354
358
|
PairOffer,
|
|
355
359
|
PairOfferResponse,
|
|
356
360
|
|
|
361
|
+
// Previsão de promocional/pontos por produto
|
|
362
|
+
PromotionalForecastPointSystem,
|
|
363
|
+
PromotionalForecastResponse,
|
|
364
|
+
|
|
357
365
|
// Avaliaçoes
|
|
358
366
|
ProductReviewRequest,
|
|
359
367
|
CreateProductReviewResponse,
|