M
M
MarkivV2021-02-14 01:29:06
Qiwi
MarkivV, 2021-02-14 01:29:06

Qiwi billing error, does not return json response, I can't understand what is the error?

Hello, when you click on the button, you need to issue an invoice for qiwi and redirect the person to the payment form. But when invoicing, nothing is returned, even the error form, but a json response should be returned.
Here is the actual error in the console
602851cfca6b8523838790.png

Here is the server side code

app.put('/create-payment', async function (req,res,next) {
  const data = await qiwi(); // получаем в data результат вызова qiwiApi.createBill
  const p = JSON.parse(data);
  
  next(); // т.к. функция асинхронная, вызываем next, чтобы объявить о завершении выполнения этого middleware
});


async function qiwi() {
  const billId = qiwiApi.generateId();

  const fields = {
      amount: 1.00,
      currency: 'RUB',
      comment: 'test',
      expirationDateTime: '2022-03-02T08:44:07',
      successUrl: 'http://test.ru/'
  };

  const data = await qiwiApi.createBill( billId, fields );
  // тут делаем что-то еще, если нужно
  return data; // возвращаем результат вызова qiwiApi.createBill
}


Here is the client side code (button click handler)

document.querySelectorAll('.payments').forEach(function(element){
  element.onclick = createPayment;
});

function createPayment() {
  fetch('/create-payment',{
  method: 'PUT',
  headers: {
    'Authorization': 'Bearer VZswX1FRSbE6iyCj2gCRwwF3Dnh5XrasNTx3BGPiMsyXQFNKQhvukniQG8RTVhYm3iPwPhF1aV7hgCHTZbGec4giFGqmsEEVhPUjQ53RCTCTPZZSiJjWpK2yxxfQtUV8gg124j6t5xuC21LcuAvM25dLFy1x2cPKbA4QYTdqUfzK',
    'Accept': 'application/json',
    'Content-Type' : 'application/json'
  }
}).then(function (response) {
      return response.text();
  }
  )
}


That's all there is, except for authorization
. Maybe I missed something or didn't finish it?
Help to understand the error and how to solve it

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question