M
M
Markiv072021-02-13 03:01:02
API
Markiv07, 2021-02-13 03:01:02

Qiwi billing not working?

Hello, when you click the button, you need to issue an invoice for Qiwi and redirect the person to the payment form. I get this error 60272201b968b963845822.png

Here is the code that I have
This is in the app.js server side

app.put('/create-payment', function () {
  p = JSON.parse(qiwi());
});


function qiwi() {

  const billId = qiwiApi.generateId();

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

  qiwiApi.createBill( billId, fields ).then( data => {
      //do with data
  });
}


I still can’t figure out what to do with this createBill

This is a button click handler
document.querySelectorAll('.payments').forEach(function(element){
  element.onclick = createPayment;
});

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


I can’t figure out what the error is and how to deal with this error
And I can’t figure out how to accept a json response with a link to the form itself

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex K, 2021-02-13
@Markiv07

Now the code in the server-side after calling PUT /create-paymentcalls qiwi(), which returns nothing (returns undefined), and this is parsed into JSON.parse.
You probably want to parse the result of calling qiwiApi.createBill( billId, fields ). If so, then explore how to work with async functions and/or use Promises.
If you understand correctly what you wanted to do, then the server code will be like this:

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: '2018-03-02T08:44:07',
      successUrl: 'http://test.ru/'
  };

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

D
Developer, 2021-02-13
@samodum

You send a request to localhost:3000
That is, to yourself.
And you need to send it to the server of the payment system

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question