我想打电话给testFunction()在$这个 - > mollie->付款 - >创建的方法,但我得到一个错误:呼叫功能
致命错误:未捕获异常'Mollie_API_Exception'消息'执行API调用时出错(请求):金额低于最小值'。
所以这意味着$这个 - > testFunction()返回0
我做了如下试验:
$test = new gtpMollieGateway();
echo $test->testFunction();
这给出了一个正确的价值(计算的金额我的结帐)。
因此,这意味着我做错事与调用testFunction()在$这个 - > mollie->付款 - >创建方法
我创建支付代码:
// Create payment
class gtpMollieGateway {
public $mollie, $price;
function __construct() {
$this->mollie = new Mollie_API_Client;
$this->mollie->setApiKey('myapikey');
$this->price = new gtpCheckoutData();
add_action('init', array($this, 'gtpCreatePayment'));
}
private function testFunction() {
return $this->price->getPrice('inclusive');
}
public function gtpCreatePayment() {
if(isset($_POST['checkout_submit'])) {
$payment = $this->mollie->payments->create(array(
// Here is the problem
'amount' => $this->testFunction(),
));
header('Location: ' . $payment->getPaymentUrl());
}
}
}
$_mollie = new gtpMollieGateway;
计算我量类:
class gtpCheckoutData {
private $tax, $price;
public function __construct() {
$this->tax = get_option('gtp_theme_settings');
$this->tax = $this->tax['gtp_tax']/100;
if(isset($_SESSION['shopping_cart'])) {
$this->price = $_SESSION['shopping_cart']['total_price'] + $_SESSION['shopping_cart']['shipping_price'];
$this->shipping = $_SESSION['shopping_cart']['shipping_price'];
}
}
public function getPrice($type) {
if(isset($type)) {
switch($type) {
case 'exclusive' :
$totalPrice = $this->price;
break;
case 'tax' :
$totalPrice = $this->price * $this->tax;
break;
case 'inclusive' :
$totalPrice = $this->price * ($this->tax + 1);
break;
}
return $totalPrice;
}
}
}
它似乎是您的付款网关错误,因此请检查您的付款集成指南。 – 2014-11-24 10:53:25
@hardiksolanki他说这个错误发生在'amount'为0时 – 2014-11-24 10:54:27
您可能没有定义$ _SESSION ['shopping_cart'] ['total_price']。你可以做var_dump($ _ SESSION)并检查它是否存在于会话中?你也有太多的耦合,尝试重新分解你的代码 – Igor 2014-11-24 11:33:04