You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutterwave支付成功后仍跳转至失败页面问题求助

Flutterwave支付成功后跳转失败问题修复

你的问题出在回调函数的条件判断逻辑错误,导致无论支付是否成功,都会跳转到失败页面。

错误原因

原代码中的判断条件逻辑完全颠倒且存在逻辑漏洞:

if (response.tx.chargeResponse !== '00' || response.tx.chargeResponse !== '0') {
    window.location = "success.php";
} else {
    window.location = "failed.php";
}

一个值不可能同时等于'00'和'0',所以无论返回的响应码是成功的'00'/'0'还是其他失败码,这个条件永远为true,最终会执行else分支跳转到失败页面。

修复方案

将判断逻辑改为检测响应码是否为成功状态,当响应码是'00'或'0'时跳转到成功页面,否则跳失败页面:

callback: function (response) {
    flw_ref = response.tx.flwRef;// 收集flwRef,后续可传给后端做状态校验
    console.log("支付响应结果", response);
    // 正确判断支付成功状态
    if (response.tx.chargeResponse === '00' || response.tx.chargeResponse === '0') {
        window.location = "success.php";
    } else {
        window.location = "failed.php";
    }
    x.close();
}

额外注意事项

  • 本地测试时,redirect_url和custom_logo建议使用http://localhost而非https://localhost,本地环境通常没有有效HTTPS证书,可能导致资源加载或回调异常。
  • 生产环境务必通过后端接口验证支付状态(用flw_ref调用Flutterwave查询API),不要仅依赖前端回调判断,避免恶意篡改。

内容的提问来源于stack exchange,提问作者Ndongesit Edet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 14:52:33