2014-11-24 244 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