arrow_back_ios

在我的網站處理付款時,如何檢查訂單狀態?

1. 您需要取得 userId 和 checkStateToken。
使用付款 API 時,這兩個值會在建立付款的第一個請求中提供。 您可以直接將這兩個值放入付款頁面的參數中。
2. 在處理付款的頁面中加入下列指令碼:
<script src="https://app.bukza.com/static/js/bukzaCheckState.js"></script>
3. DOM 載入完成後,執行下列程式碼:
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();
此指令碼會檢查訂單狀態。 指令碼每 10 秒取得一次結果,並呼叫您的 handler 函式。 您可以在 handler 中檢查結果並採取對應的動作:顯示錯誤、讓客戶返回上一頁,或顯示成功頁面。
若未指定 userId 和 token 的值,指令碼會從頁面的查詢參數中取得:bukzaUserId 和 bukzaCheckStateToken。

範例程式碼

實際範例請見 https://app.bukza.com/paw.html 頁面的原始碼,其中使用了下列 handler 程式碼:
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';
    }
}