@
@
@salomatin2019-09-24 07:41:16
JavaScript
@salomatin, 2019-09-24 07:41:16

How to process Promise resolve in case of successful QIWI payment?

I set up Checkout Popup for p2p (Accepting Transfers). The documentation says that in case of successful payment, Promise resolves with the parameters with which the invoice was created, otherwise it is rejected with the reason due to which the payment was interrupted I
wrote the following code:
QiwiCheckout.createInvoice({
publicKey: 'publikkey**** *',
amount: 1200,
successUrl: ' https://site.ru/success/ ',
})
.then(data => {
alert('success');
$(location).attr('href', ' https://site.ru/success/ ');
})
.catch(error => {
alert('error');
console.log('Error: '+error);
})
The error handler ".catch(error => "works, when the modal window is closed or there is an error during payment, it works correctly, and issues alert and console.log.
But in case of successful payment, the text in the modal window changes to a success message and a link to go to the site from the "successUrl" parameter. 2 seconds after the payment is made, the payment form closes (as it says in the documentation)
I can't figure out how to call a custom Javascript function on successful payment. Since the modal window closes too quickly, the user cannot understand that the payment passed + after the payment, I need to clear S_SESSION to delete the cart data.
ps I repeat, I use Qiwi Checkout Popup (generation of a modal window with Qiwi payment)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
salomatin, 2019-11-21
_

This cannot be done. In the official chat, they answered that the code was written through one place. They don’t plan to fix it, it’s impossible to do this through modal windows, only redirection to the QIWI website

V
Vitaly, 2019-09-24
@vshvydky

Judging by the code of the popup, it is nasty and vile. The solution to the issue of redirect inhibition and the use of your custom callback is possible only in the case of a fork of this bible and rewriting it for yourself.
In the code there, both timings and reactions are hardwired, redefinition in the code is not provided.
And this is of turnip kiwi, tin ....

window.addEventListener('message', event => {
      if (event.data === 'PAYMENT_SUCCEEDED') {
        setTimeout(onPaymentSucceeded, 2000);
      } else if (event.data === 'PAYMENT_FAILED') {
        setTimeout(onPaymentFailed, 2000);
      }
    });

SUCCEEDED - hmm...
settimeouts - hmm...
any ill-conceived exit from a form by a developer, a non-resolvable promise - well...
in short, not the best code that could be pulled into a project.

A
Anton Neverov, 2019-09-24
@TTATPuOT

The simplest thing is to hit the person in the face with "PAYMENT COMPLETE" via alert. While alert hangs, further JS will not be executed. You can also make up your own modal window and display it, which is also a crutch.
You were correctly pointed to the fork. In general, the library uses the most common iframes. You can write this yourself. Although, of course, more time will obviously go away.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question