2014-11-24 245 views
0

我想打电话给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; 
     } 
    } 
} 
+0

它似乎是您的付款网关错误,因此请检查您的付款集成指南。 – 2014-11-24 10:53:25

+0

@hardiksolanki他说这个错误发生在'amount'为0时 – 2014-11-24 10:54:27

+0

您可能没有定义$ _SESSION ['shopping_cart'] ['total_price']。你可以做var_dump($ _ SESSION)并检查它是否存在于会话中?你也有太多的耦合,尝试重新分解你的代码 – Igor 2014-11-24 11:33:04

回答

0

经过很长时间的搜索和尝试我发现了问题。我的会话没有在我的插件文档中开始。 Wordpress在functions.php之前加载插件,并且我的会话在functions.php中启动。

所以这就是我的价值为0的原因,那是发生错误。

0

您的函数testFunction()正在调用函数getPrice($ type),函数getPrice($ type)返回0,因此可能是因为您从外部api(支付网关api)中收到此错误的数量为0。

+0

谢谢你的回答,但那是我在我的问题中已经说过的。 – Robbert 2014-11-24 12:59:04