From aae4f7a48a85162c5b46d0f7660033c294e2fcb2 Mon Sep 17 00:00:00 2001 From: Guido Date: Wed, 16 Apr 2025 11:23:26 -0300 Subject: [PATCH 1/2] feat(tpv): integrar ID de empresa en el proceso de pago y actualizar llamadas a la API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se agregó la validación del ID de empresa en OrdersView. Se refactorizaron los métodos de transacción TPV para usar los nuevos endpoints de la API. --- src/pages/Ecomerce/OrdersView.vue | 9 +++++++- src/stores/tpv.js | 36 ++++++++++++++++++------------- src/stores/user.js | 12 ++++++++++- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/pages/Ecomerce/OrdersView.vue b/src/pages/Ecomerce/OrdersView.vue index a5d6d9d9..1277f35f 100644 --- a/src/pages/Ecomerce/OrdersView.vue +++ b/src/pages/Ecomerce/OrdersView.vue @@ -13,6 +13,7 @@ import useNotify from 'src/composables/useNotify.js'; import { currency, formatDateTitle } from 'src/lib/filters.js'; import { tpvStore } from 'stores/tpv'; import { useAppStore } from 'stores/app'; +import { useUserStore } from 'stores/user'; import { storeToRefs } from 'pinia'; const { t } = useI18n(); @@ -26,6 +27,7 @@ const showAmountToPayDialog = ref(null); const amountToPay = ref(null); const orders = ref(null); const debt = ref(0); +const userStore = useUserStore(); const tpv = tpvStore(); onMounted(async () => { @@ -57,9 +59,14 @@ const onConfirmPay = async () => { return; } + if (!userStore.companyId) { + notify(t('companyConfigError'), 'negative'); + return; + } + const amount = amountToPay.value.toString().replace('.', ','); amountToPay.value = parseFloat(amount); - await tpv.pay(amountToPay.value); + await tpv.pay(amountToPay.value, userStore.companyId); }; diff --git a/src/stores/tpv.js b/src/stores/tpv.js index 53f146c2..4bf2e252 100644 --- a/src/stores/tpv.js +++ b/src/stores/tpv.js @@ -1,5 +1,5 @@ import { defineStore } from 'pinia'; -import { jApi } from 'boot/axios'; +import { api } from 'boot/axios'; export const tpvStore = defineStore('tpv', { actions: { @@ -8,9 +8,9 @@ export const tpvStore = defineStore('tpv', { const status = route.query.tpvStatus; if (!(order && status)) return null; - await jApi.execQuery('CALL myTpvTransaction_end(#order, #status)', { - order, - status + await api.post('tpvTransactions/end', { + orderId: order, + status: status }); if (status === 'ko') { @@ -28,26 +28,32 @@ export const tpvStore = defineStore('tpv', { }, async retryPay(order) { - const payment = await jApi.getObject( - `SELECT t.amount, m.companyFk - FROM myTpvTransaction t - JOIN tpvMerchant m ON m.id = t.merchantFk - WHERE t.id = #order`, - { order } + const { data: transactions } = await api.get( + 'clients/transactions', + { + params: { + orderFk: order + } + } ); - await this.realPay(payment.amount, payment.companyFk); + if (transactions && transactions.length > 0) { + const transaction = transactions[0]; + await this.realPay( + transaction.amount * 100, + transaction.merchantFk + ); + } }, async realPay(amount, company) { if (!isNumeric(amount) || amount <= 0) { throw new Error('payAmountError'); } - - const json = await jApi.send('tpv/transaction', { - amount: parseInt(amount), + const { data: json } = await api.post('tpvTransactions/start', { + amount: amount, urlOk: this.makeUrl('ok'), urlKo: this.makeUrl('ko'), - company + companyId: company }); const postValues = json.postValues; diff --git a/src/stores/user.js b/src/stores/user.js index 8b75f124..3d38fa34 100644 --- a/src/stores/user.js +++ b/src/stores/user.js @@ -8,6 +8,7 @@ const { notify } = useNotify(); const TOKEN_MULTIMEDIA = 'tokenMultimedia'; const TOKEN = 'token'; + export const useUserStore = defineStore('user', () => { const token = ref(''); const tokenMultimedia = ref(''); @@ -15,7 +16,7 @@ export const useUserStore = defineStore('user', () => { const user = ref(null); // Usuario en uso => supplantedUser || mainUser const supplantedUser = ref(null); // Usuario suplantado const mainUser = ref(null); // Usuario principal logueado - + const companyId = ref(null); const keepLogin = ref(false); const intervalId = ref(null); const isCheckingToken = ref(false); @@ -40,6 +41,7 @@ export const useUserStore = defineStore('user', () => { } else { await fetchUser(); await fetchTokenConfig(); + await fetchCompanyId(); await supplantInit(); startInterval(); } @@ -154,6 +156,7 @@ export const useUserStore = defineStore('user', () => { await fetchTokenConfig(); startInterval(); await onLogin(); + await fetchCompanyId(); } catch (error) { throw new Error('Error logging in'); } @@ -283,6 +286,12 @@ export const useUserStore = defineStore('user', () => { user.value.lang = lang; }; + const fetchCompanyId = async () => { + const { data } = await api.get('UserConfigs/getUserConfig'); + companyId.value = data.companyFk; + }; + + const $reset = () => { token.value = ''; tokenMultimedia.value = ''; @@ -317,6 +326,7 @@ export const useUserStore = defineStore('user', () => { tokenConfig, isLoggedIn, storage, + companyId, getToken, getTokenMultimedia, setToken, From 75f4e43c570e019d395ecef5250bc6a11a25652c Mon Sep 17 00:00:00 2001 From: Guido Date: Thu, 17 Apr 2025 11:34:07 -0300 Subject: [PATCH 2/2] =?UTF-8?q?refactor(tpv):=20Se=20cambi=C3=B3=20el=20no?= =?UTF-8?q?mbre=20de=20la=20variable=20de=20order=20a=20orderId=20y=20se?= =?UTF-8?q?=20actualizaron=20las=20llamadas=20a=20la=20API=20relacionadas.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/tpv.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/stores/tpv.js b/src/stores/tpv.js index 4bf2e252..e9312a52 100644 --- a/src/stores/tpv.js +++ b/src/stores/tpv.js @@ -4,19 +4,19 @@ import { api } from 'boot/axios'; export const tpvStore = defineStore('tpv', { actions: { async check(route) { - const order = route.query.tpvOrder; + const orderId = route.query.tpvOrder; const status = route.query.tpvStatus; - if (!(order && status)) return null; + if (!(orderId && status)) return null; await api.post('tpvTransactions/end', { - orderId: order, - status: status + orderId, + status }); if (status === 'ko') { const retry = confirm('retryPayQuestion'); if (retry) { - this.retryPay(order); + this.retryPay(orderId); } } @@ -27,17 +27,17 @@ export const tpvStore = defineStore('tpv', { await this.realPay(amount * 100, company); }, - async retryPay(order) { + async retryPay(orderId) { const { data: transactions } = await api.get( 'clients/transactions', { params: { - orderFk: order + orderFk: orderId } } ); if (transactions && transactions.length > 0) { - const transaction = transactions[0]; + const [transaction] = transactions; await this.realPay( transaction.amount * 100, transaction.merchantFk @@ -45,15 +45,15 @@ export const tpvStore = defineStore('tpv', { } }, - async realPay(amount, company) { + async realPay(amount, companyId) { if (!isNumeric(amount) || amount <= 0) { throw new Error('payAmountError'); } const { data: json } = await api.post('tpvTransactions/start', { - amount: amount, + amount, + companyId, urlOk: this.makeUrl('ok'), - urlKo: this.makeUrl('ko'), - companyId: company + urlKo: this.makeUrl('ko') }); const postValues = json.postValues;