|
@@ -110,12 +110,11 @@
|
|
|
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 { getSchedulePixPayment, getServicePackagePix, paySchedule, payServicePackage } from 'src/api/payment'
|
|
|
|
|
|
|
+import { getServicePackagePix, payServicePackage } from 'src/api/payment'
|
|
|
import { usePaymentStore } from 'src/stores/payment'
|
|
import { usePaymentStore } from 'src/stores/payment'
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
|
- schedule: { type: Object, default: null },
|
|
|
|
|
- servicePackage: { type: Object, default: null },
|
|
|
|
|
|
|
+ servicePackage: { type: Object, required: true },
|
|
|
total: { type: Number, required: true },
|
|
total: { type: Number, required: true },
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -125,8 +124,7 @@ const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } = useDialogPluginC
|
|
|
const $q = useQuasar()
|
|
const $q = useQuasar()
|
|
|
const paymentStore = usePaymentStore()
|
|
const paymentStore = usePaymentStore()
|
|
|
|
|
|
|
|
-const isServicePackage = computed(() => !!props.servicePackage)
|
|
|
|
|
-const item = computed(() => props.servicePackage ?? props.schedule)
|
|
|
|
|
|
|
+const item = computed(() => props.servicePackage)
|
|
|
const itemId = computed(() => item.value.id)
|
|
const itemId = computed(() => item.value.id)
|
|
|
|
|
|
|
|
const payment = ref(null)
|
|
const payment = ref(null)
|
|
@@ -173,33 +171,21 @@ const applyPaymentStatus = (nextPayment) => {
|
|
|
if (nextPayment.status === 'paid') {
|
|
if (nextPayment.status === 'paid') {
|
|
|
success.value = true
|
|
success.value = true
|
|
|
processing.value = false
|
|
processing.value = false
|
|
|
- if (isServicePackage.value) {
|
|
|
|
|
- paymentStore.clearPixPaymentForServicePackage(itemId.value)
|
|
|
|
|
- } else {
|
|
|
|
|
- paymentStore.clearPixPayment(itemId.value)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ paymentStore.clearPixPaymentForServicePackage(itemId.value)
|
|
|
stopPolling()
|
|
stopPolling()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (['failed', 'cancelled'].includes(nextPayment.status)) {
|
|
if (['failed', 'cancelled'].includes(nextPayment.status)) {
|
|
|
processing.value = false
|
|
processing.value = false
|
|
|
- if (isServicePackage.value) {
|
|
|
|
|
- paymentStore.clearPixPaymentForServicePackage(itemId.value)
|
|
|
|
|
- } else {
|
|
|
|
|
- paymentStore.clearPixPayment(itemId.value)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ paymentStore.clearPixPaymentForServicePackage(itemId.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
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (isServicePackage.value) {
|
|
|
|
|
- paymentStore.setPixPaymentForServicePackage(itemId.value, nextPayment)
|
|
|
|
|
- } else {
|
|
|
|
|
- paymentStore.setPixPayment(itemId.value, nextPayment)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ paymentStore.setPixPaymentForServicePackage(itemId.value, nextPayment)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const checkPaymentStatus = async () => {
|
|
const checkPaymentStatus = async () => {
|
|
@@ -207,9 +193,7 @@ const checkPaymentStatus = async () => {
|
|
|
|
|
|
|
|
pollingInFlight = true
|
|
pollingInFlight = true
|
|
|
try {
|
|
try {
|
|
|
- const result = isServicePackage.value
|
|
|
|
|
- ? await getServicePackagePix(itemId.value)
|
|
|
|
|
- : await getSchedulePixPayment(itemId.value)
|
|
|
|
|
|
|
+ const result = await getServicePackagePix(itemId.value)
|
|
|
applyPaymentStatus(result)
|
|
applyPaymentStatus(result)
|
|
|
updateCountdown()
|
|
updateCountdown()
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
@@ -237,11 +221,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) {
|
|
|
- if (isServicePackage.value) {
|
|
|
|
|
- paymentStore.clearPixPaymentForServicePackage(itemId.value)
|
|
|
|
|
- } else {
|
|
|
|
|
- paymentStore.clearPixPayment(itemId.value)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ paymentStore.clearPixPaymentForServicePackage(itemId.value)
|
|
|
stopPolling()
|
|
stopPolling()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -251,9 +231,7 @@ onMounted(async () => {
|
|
|
countdownTimer = setInterval(updateCountdown, 1000)
|
|
countdownTimer = setInterval(updateCountdown, 1000)
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- const cachedPayment = isServicePackage.value
|
|
|
|
|
- ? paymentStore.getValidPixPaymentForServicePackage(itemId.value)
|
|
|
|
|
- : paymentStore.getValidPixPayment(itemId.value)
|
|
|
|
|
|
|
+ const cachedPayment = paymentStore.getValidPixPaymentForServicePackage(itemId.value)
|
|
|
|
|
|
|
|
if (cachedPayment) {
|
|
if (cachedPayment) {
|
|
|
applyPaymentStatus(cachedPayment)
|
|
applyPaymentStatus(cachedPayment)
|
|
@@ -262,9 +240,7 @@ onMounted(async () => {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const paymentResult = isServicePackage.value
|
|
|
|
|
- ? await payServicePackage(itemId.value, { payment_method: 'pix' })
|
|
|
|
|
- : await paySchedule(itemId.value, { payment_method: 'pix' })
|
|
|
|
|
|
|
+ const paymentResult = await payServicePackage(itemId.value, { payment_method: 'pix' })
|
|
|
|
|
|
|
|
applyPaymentStatus(paymentResult)
|
|
applyPaymentStatus(paymentResult)
|
|
|
updateCountdown()
|
|
updateCountdown()
|