#milioli_error

1 messages · Page 1 of 1 (latest)

viscid fulcrumBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1238568500658962433

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

hot vigil
#

the Logs

prime frost
#

Hi, let me grab someone who has more expertise with Terminal. Thank you for your patience.

hot vigil
#

Ok. Thanks

opaque shadow
#

Hello there

hot vigil
#

Hi!

opaque shadow
#

Can you share the exact code you're using for this?

hot vigil
#

Sure. Just a moment

#

const {
discoverReaders,
connectLocalMobileReader,
createPaymentIntent,
collectPaymentMethod,
confirmPaymentIntent,
discoveredReaders,
disconnectReader
} = useStripeTerminal({
onUpdateDiscoveredReaders: (readers: any) => {
setReader(readers[0])
},
onDidChangeConnectionStatus: status => {
setStatusReader(status)
},
onDidReportReaderSoftwareUpdateProgress: progress => {
console.log(progress)
},
onDidChangePaymentStatus: status => {
setStatusPayment(status)
},
onFinishDiscoveringReaders: (data: any) => {
if (data && data.message === 'Device does not have NFC') {
Alert.alert(
'Device does not have NFC',
'Your device does not have NFC and therefore the option to pay by tapping is disabled.'
)
setFinishDescoveringReaders(data.message)
}

  // if (data && data.code === 'AlreadyConnectedToReader') return disconnectReader()
},
onDidReportAvailableUpdate: async update => {
  console.log(update.estimatedUpdateTime)
  await logsService.createLog({
    type: 'error',
    where: 'tap_to_pay',
    message: ⁠ [TICKET] --> ${update} ⁠
  })
}

})

#

useEffect(() => {
discoverReaders({
discoveryMethod: 'localMobile'
})
}, [discoverReaders])

async function connectionWithTheReader(selectedReader: any) {
setBtnDisabled(true)
try {
// Verifica se há um leitor selecionado
if (!selectedReader) {
return handleDisconnect()
}

  // Obtém a localização para o leitor selecionado
  const { data } = await tapToPayService.getLocation({ domain: domainId })

  // Conecta o leitor selecionado
  const { error } = await connectLocalMobileReader({
    reader: selectedReader,
    locationId: data.location?.id
  })

  // Verifica se houve erro ao conectar o leitor
  if (error) {
    await logsService.createLog({
      type: 'error',
      where: 'tap_to_pay',
      message: `[TICKET] Error connecting to the reader ---> ${error.message}`
    })
    console.log('ERROR error:', error)
    Alert.alert('Error connecting to the reader.', 'Please, try again', [
      {
        text: 'Ok',
        onPress: async () => {
          setModalTapToPatVisible(false)
          await handleReconnect()
        }
      }
    ])
    return
  }
} catch (error: any) {
  // Trata erros ao obter a localização
  console.log('ERROR GET LOCATION', error.response?.data)
  Alert.alert('Location not found.', 'Please, configure your location in dashboard', [
    {
      text: 'OK',
      onPress: () => setModalTapToPatVisible(false)
    }
  ])
} finally {
  setBtnDisabled(false)
}

}

#

I am sending the file too

opaque shadow
#

What does await handleReconnect() do?

hot vigil
#

async function handleReconnect() {
setBtnDisabled(true)
try {
await Promise.all([
discoverReaders({
discoveryMethod: 'localMobile'
}),
connectionWithTheReader(discoveredReaders[0] as any)
])
} catch (error) {
console.error('Error when reconnecting the reader:', error)
} finally {
setBtnDisabled(false)
}
}

opaque shadow
#

I have a feeling that function is being invoked again for some reason
Can you comment it out and see if that makes a difference here?

hot vigil
#

Comment the handleReconnect?

opaque shadow
#

yeah

hot vigil
#

When I do this, every time I close the window and open it again, it logs that I already have a reader connected and doesn't let me proceed with the payment.

#

Is there a way to use a Reader that is already connected without the need to reconnect again?

opaque shadow
#

if you're then you can skip discovery

#

and move on to collecting payment method

hot vigil
#

Nice. I will try this!

#

It worked!

#

Thank you very much!!!