我正在网上商店工作,需要帮助才能获得iDeal插件(来自荷兰的付款方式)。
我需要通过需要支付的物品的金额(价格)发送。 我从上一页获得了这个项目的数量
$qty = $_POST['qty'];
并制作这样的总价格变量(2999是价格,需要以美分为单位,因此价格为29,99)
$totaalprijs = 2999 * $qty;
$iAmount = $totaalprijs;
访客选择银行并按下提交按钮启动付款 然后发生这种情况
$oIdeal->setIdealAmount ( $iAmount );
它将变量发送到另一个php文件中的此函数,检查该值是否为非0的数字,并通过另一个函数将其发送到付款方式。
public function setIdealAmount ( $intIdealAmount ) {
# Is this a valid ideal amount?
if ( is_numeric ( $intIdealAmount ) && $intIdealAmount > 0 ) {
$this->idealAmount = $intIdealAmount;
}
else {
throw new Exception( 'Invalid ideal amount, please check.' );
}
return $this;
}
这就是问题,当它通过函数发送时它总是返回0 除非我例如这样做:
$iAmount = 2999;
我希望商品的总价格是价格*数量,但是当我像上面那样声明我的$ iAmount变量时,它只返回$ this。
我得到的错误信息是:
Fatal error: Uncaught exception 'Exception' with message 'Invalid ideal amount, please check.' in /home/spraytanning-express.nl/www/TargetPayIdeal.class.php:154 Stack trace: #0 /home/spraytanning-express.nl/www/betalen.php(116): TargetPayIdeal->setIdealAmount(0) #1 {main} thrown in /home/spraytanning-express.nl/www/TargetPayIdeal.class.php on line 154
希望你们中的一些人可以帮助我...... 顺便说一句,抱歉我的英语不好:)
提前致谢!
答案 0 :(得分:0)
尝试拆分支票并根据检查失败明确抛出异常:
public function setIdealAmount ( $intIdealAmount ) {
var_dump($intIdealAmount); // see what the value is
if (!is_numeric($intIdealAmount)) {
throw new Exception( 'ideal amount not numeric' );
}
if ($intIdealAmount <= 0) {
throw new Exception('ideal amount <= 0');
}
etc...
}
现在你的异常对于显示出错是有用的,但是没有用来解释为什么出错了。
答案 1 :(得分:0)
如果你还没有这样做,你可能需要在使用$ this-&gt;引用它之前初始化$ idealAmount变量。宾语。另外,您可能需要检查$ _POST ['qty']是否为数字。