我想打電話給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