arrow_back_iosQuestions
help

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

check_circle
1. You will need to get userId and checkStateToken.
In the Payments API we pass them in the first 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 script:
<script src="https://app.bukza.com/static/js/bukzaCheckState.js"></script>
3. After the DOM is ready, run:
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 run the order state check. Every 10 seconds it will receive the result and call your handler. In the handler, you can check the result and perform the required action: output 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 take them from the page query parameters: bukzaUserId and bukzaCheckStateToken.

Sample code

A real use case 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';
    }
}
Didn't find the answer to your question?
Feel free to ask it at
mail_outline support@bukza.com