arrow_back_ios

How can I check the order state when processing a payment on my website?

1. You will need to obtain the userId and checkStateToken.
In the Payments API, these are provided in the initial request to create a payment. You can immediately insert them into the parameters of your payment page.
2. On your payment processing page, add the following script:
<script src="https://app.bukza.com/static/js/bukzaCheckState.js"></script>
3. Once the DOM is ready, execute the following code:
var bukzaCheckState = new BukzaCheckState({
    userId: 12345,
    token: 'eyJVc2VySWQiOjIsIk9yZGVyS...Ws9In0%3D',
    handler: function (result) {
        console.log(result); //{isFinished:true, isValid:true, amount:99.99}
    }
});
bukzaCheckState.bind();
This script will check the order state. Every 10 seconds, it will receive the result and call your handler function. In the handler, you can review the result and take the appropriate action: display an error, return the user to the previous page, or show a success page.
If the userId and token values are not specified, the script will retrieve them from the page's query parameters: bukzaUserId and bukzaCheckStateToken.

Sample code

A real-world example can be found in the source code of the page https://app.bukza.com/paw.html. The following handler code is used there:
handler: function (result) {
    if (result) {
        if (result.isFinished) {
            if (result.isValid) {
                //order is completed succesfully
                window.location.href = 'https://app.bukza.com/result.html?result=success&culture=en';
            } else {
                //order is completed but for some reason it is not valid
                window.location.href = 'https://app.bukza.com/result.html?result=warning&culture=en';
            }
        } else {
            if (result.isValid) {
                if (result.amount != window.amount) {
                    //amount to pay has changed, going to the previous page
                    window.history.go(-1);
                } else {
                    //everything is ok, waiting for payment
                }
            } else {
                //order became invalid, going to the previous page
                window.history.go(-1);
            }
        }
    }
    else {
        window.location.href = 'https://app.bukza.com/result.html?result=error&culture=en';
    }
}