|
@@ -110,12 +110,13 @@
|
|
|
import { computed, ref, onMounted, onUnmounted } from 'vue'
|
|
import { computed, ref, onMounted, onUnmounted } from 'vue'
|
|
|
import { useDialogPluginComponent, useQuasar, copyToClipboard } from 'quasar'
|
|
import { useDialogPluginComponent, useQuasar, copyToClipboard } from 'quasar'
|
|
|
import { formatCurrency } from 'src/helpers/utils'
|
|
import { formatCurrency } from 'src/helpers/utils'
|
|
|
-import { getServicePackagePix, payServicePackage } from 'src/api/payment'
|
|
|
|
|
|
|
+import { getServicePackagePix, payServicePackage, getScheduleProposalPix, payScheduleProposal } from 'src/api/payment'
|
|
|
import { usePaymentStore } from 'src/stores/payment'
|
|
import { usePaymentStore } from 'src/stores/payment'
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
|
servicePackage: { type: Object, required: true },
|
|
servicePackage: { type: Object, required: true },
|
|
|
total: { type: Number, required: true },
|
|
total: { type: Number, required: true },
|
|
|
|
|
+ targetType: { type: String, default: 'service_package' },
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
defineEmits([...useDialogPluginComponent.emits])
|
|
defineEmits([...useDialogPluginComponent.emits])
|
|
@@ -124,8 +125,12 @@ const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } = useDialogPluginC
|
|
|
const $q = useQuasar()
|
|
const $q = useQuasar()
|
|
|
const paymentStore = usePaymentStore()
|
|
const paymentStore = usePaymentStore()
|
|
|
|
|
|
|
|
|
|
+const pay = props.targetType === 'schedule_proposal' ? payScheduleProposal : payServicePackage
|
|
|
|
|
+const getPix = props.targetType === 'schedule_proposal' ? getScheduleProposalPix : getServicePackagePix
|
|
|
|
|
+
|
|
|
const item = computed(() => props.servicePackage)
|
|
const item = computed(() => props.servicePackage)
|
|
|
const itemId = computed(() => item.value.id)
|
|
const itemId = computed(() => item.value.id)
|
|
|
|
|
+const cacheKey = computed(() => `${props.targetType}:${itemId.value}`)
|
|
|
|
|
|
|
|
const payment = ref(null)
|
|
const payment = ref(null)
|
|
|
const success = ref(false)
|
|
const success = ref(false)
|
|
@@ -173,7 +178,7 @@ const applyPaymentStatus = (nextPayment) => {
|
|
|
position: 'top',
|
|
position: 'top',
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- paymentStore.clearPixPaymentForServicePackage(itemId.value)
|
|
|
|
|
|
|
+ paymentStore.clearPixPaymentForServicePackage(cacheKey.value)
|
|
|
stopPolling()
|
|
stopPolling()
|
|
|
|
|
|
|
|
onDialogOK()
|
|
onDialogOK()
|
|
@@ -184,14 +189,14 @@ const applyPaymentStatus = (nextPayment) => {
|
|
|
|
|
|
|
|
if (['failed', 'cancelled'].includes(nextPayment.status)) {
|
|
if (['failed', 'cancelled'].includes(nextPayment.status)) {
|
|
|
processing.value = false
|
|
processing.value = false
|
|
|
- paymentStore.clearPixPaymentForServicePackage(itemId.value)
|
|
|
|
|
|
|
+ paymentStore.clearPixPaymentForServicePackage(cacheKey.value)
|
|
|
stopPolling()
|
|
stopPolling()
|
|
|
$q.notify({ type: 'negative', message: nextPayment.failure_message || 'Pagamento Pix não confirmado.' })
|
|
$q.notify({ type: 'negative', message: nextPayment.failure_message || 'Pagamento Pix não confirmado.' })
|
|
|
onDialogCancel()
|
|
onDialogCancel()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- paymentStore.setPixPaymentForServicePackage(itemId.value, nextPayment)
|
|
|
|
|
|
|
+ paymentStore.setPixPaymentForServicePackage(cacheKey.value, nextPayment)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const checkPaymentStatus = async () => {
|
|
const checkPaymentStatus = async () => {
|
|
@@ -199,7 +204,7 @@ const checkPaymentStatus = async () => {
|
|
|
|
|
|
|
|
pollingInFlight = true
|
|
pollingInFlight = true
|
|
|
try {
|
|
try {
|
|
|
- const result = await getServicePackagePix(itemId.value)
|
|
|
|
|
|
|
+ const result = await getPix(itemId.value)
|
|
|
applyPaymentStatus(result)
|
|
applyPaymentStatus(result)
|
|
|
updateCountdown()
|
|
updateCountdown()
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
@@ -227,7 +232,7 @@ const updateCountdown = () => {
|
|
|
if (!pixExpiresAt.value && totalSeconds.value > 0) totalSeconds.value--
|
|
if (!pixExpiresAt.value && totalSeconds.value > 0) totalSeconds.value--
|
|
|
|
|
|
|
|
if (pixExpiresAt.value && totalSeconds.value <= 0) {
|
|
if (pixExpiresAt.value && totalSeconds.value <= 0) {
|
|
|
- paymentStore.clearPixPaymentForServicePackage(itemId.value)
|
|
|
|
|
|
|
+ paymentStore.clearPixPaymentForServicePackage(cacheKey.value)
|
|
|
stopPolling()
|
|
stopPolling()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -237,7 +242,7 @@ onMounted(async () => {
|
|
|
countdownTimer = setInterval(updateCountdown, 1000)
|
|
countdownTimer = setInterval(updateCountdown, 1000)
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- const cachedPayment = paymentStore.getValidPixPaymentForServicePackage(itemId.value)
|
|
|
|
|
|
|
+ const cachedPayment = paymentStore.getValidPixPaymentForServicePackage(cacheKey.value)
|
|
|
|
|
|
|
|
if (cachedPayment) {
|
|
if (cachedPayment) {
|
|
|
applyPaymentStatus(cachedPayment)
|
|
applyPaymentStatus(cachedPayment)
|
|
@@ -246,7 +251,7 @@ onMounted(async () => {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const paymentResult = await payServicePackage(itemId.value, { payment_method: 'pix' })
|
|
|
|
|
|
|
+ const paymentResult = await pay(itemId.value, { payment_method: 'pix' })
|
|
|
|
|
|
|
|
applyPaymentStatus(paymentResult)
|
|
applyPaymentStatus(paymentResult)
|
|
|
updateCountdown()
|
|
updateCountdown()
|