Answer the question
In order to leave comments, you need to log in
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
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
});
}
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();
}
)
}
Answer the question
In order to leave comments, you need to log in
Now the code in the server-side after calling PUT /create-payment
calls 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
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question