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) {
//訂單已成功完成
window.location.href = 'https://app.bukza.com/result.html?result=success&culture=en';
} else {
//訂單已完成但因某些原因無效
window.location.href = 'https://app.bukza.com/result.html?result=warning&culture=en';
}
} else {
if (result.isValid) {
if (result.amount != window.amount) {
//應付金額已變更,返回上一頁
window.history.go(-1);
} else {
//一切正常,等待付款
}
} else {
//訂單變為無效,返回上一頁
window.history.go(-1);
}
}
}
else {
window.location.href = 'https://app.bukza.com/result.html?result=error&culture=en';
}
}