receive information from backend to frontend

Hello, I need some help solving a problem.

In my application I am using another non-wix payment gatway, I integrated it with the site using the backend and I am able to perform the transactions smoothly, the problem is that when the payment gatway, approves the payment I dont know how send this approved or unapproved message to the frontend and show it to the user.
I tried to save the information in the database and refresh the dataset, but the information doesn’t arrive in time.

Can someone help me please?

Thanks

You need to call it on your page code from the backend function.

https://support.wix.com/en/article/corvid-calling-server-side-code-from-the-front-end-with-web-modules
https://support.wix.com/en/article/corvid-accessing-third-party-services-with-the-fetch-api

Hi @givemeawhisky , thanks for the support, I’m didnt understand very well rsrs

my client side code looks like this

call the function payment onClick button

//call backend function to start payment
 criarToken({
 number: String($w('#ncartao').value),
 verification_value: String($w('#cvc').value),
 first_name: String(prinome),
 last_name: String(ultnome),
 month: String($w('#expiracaoMM').value),
 year: String($w('#expiracaoAA').value)},
 $w('#text248').text,
 Number($w('#parcelamento').value),
 [{ description: descricao, quantity: 1, price_cents: price }],
 String($w('#cpf').value),
 UserName, userEmail,
 String($w('#cep').value),
 idAtendimento,
 itemsAtendimento.title,
 itemsAtendimento.valorTotal,
 dataAgendamento
            )
            //function ends, here i want to return the information from backend
            .then(attstatus => {
 $w('#mensagemfinal').text = ???
 $w('#mensagemfinal').show()
            })

Here is the backend code


//first function on backend is to create a toke payment and verify his credit card

export function criarToken(dadosCartao, userEmail, parcelas, produtos, cpf, name, email, cep, idAtendimento, os, valorTotal, dataAgendamento) {
 console.log('chamou back')

 var request = require("request");
 var options = {
 method: 'POST',
 url: 'https://api.iugu.com/v1/payment_token',
 body:
        {
 account_id: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
 method: 'credit_card',
 test: 'true',
 data: dadosCartao
        },
 json: true
    };

 request(options, function (error, response, body) {
 if (error) throw new Error(error);

 let tokenpgto = body.id

 let insertToken = {
 'fk_atendimento': idAtendimento,
 'token': tokenpgto
        }
 wixData.insert('cobracas_iugu', insertToken)
            .then(res => {
 
 //then I call the function 'cobrar' to charge the user
            
 cobrar(tokenpgto, userEmail, parcelas, produtos, cpf, name, email, cep, idAtendimento, os, valorTotal, dataAgendamento)
            })
    })
}

function cobrar(token, userEmail, parcelas, produtos, cpf, name, email, cep, idAtendimento, os, valorTotal, dataAgendamento) {

 var request = require("request");

 var options = {
 method: 'POST',
 url: 'https://api.iugu.com/v1/charge?api_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
 body:
        {
 token: token,
 email: userEmail,
 months: parcelas,
 items: produtos,
 payer:
            {
 cpf_cnpj: cpf,
 name: name,
 email: email,
 address:
                {
 zip_code: cep
                }
            }
        },
 json: true
    }

 request(options, function (error, response, body) {

 // the results of the payment post 

 wixData.get('atendimento', idAtendimento)
            .then((item) => {
 item.pago = body.success
 item.invoice_id = body.invoice_id
 item.url_iugu = body.url
 item.recibo_pdf = body.pdf
 item.mensage_iugu = body.message
 item.parcelascliente = parcelas
 wixData.update('atendimento', item)
 console.log(item)
            })
            
 if (body.success === true) {
 wixData.get('atendimento', idAtendimento)
                .then((item) => {
 item.dataAgendamento = dataAgendamento
 wixData.update('atendimento', item)
                })
 notifySiteContributors('OS ' + os + ' - R$ ' + valorTotal, 'Fatura paga pelo cliente ' + name, '', 'https://www.otimicar.com')
        } else {
 if (error) throw new Error(error);
 notifySiteContributors('OS ' + os + ' - R$ ' + valorTotal, ' PROBLEMA NO PAGAMENTO CLIENTE ' + name, ' ', 'https://www.otimicar.com')
        }
 
        // How I can send the information 'body.success' to frontend? And how do i get it in the frontend?
 
        
 return body.success

    });
}

Thanks a lot!!