Я пытаюсь вызвать testFunction() в $this-> mollie → payments-> метод создания, но я получаю сообщение об ошибке:
Неустранимая ошибка: исключить исключение "Mollie_API_Exception" с сообщением "Ошибка выполнения вызова (запроса) API: сумма меньше минимальной".
Таким образом, это означает, что функция $this-> testFunction() возвращает 0.
Я сделал следующий тест:
$test = new gtpMollieGateway();
echo $test->testFunction();
И это дает правильное значение (расчетная сумма для моего оформления).
Таким образом, это означает, что я делаю что-то неправильно с вызовом функции testFunction() в методе $this-> mollie → payments-> create
Мой код для создания платежа:
// 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;
}
}
}
После долгого поиска и поиска я нашел проблему. Моя сессия не была запущена в моем документе плагина. Wordpress загружает плагин перед functions.php, а мой сеанс запускается в functions.php.
Таким образом, это было причиной того, что мое значение было 0, и это произошло с ошибкой.
Ваша функция testFunction() вызывает функцию function getPrice ($ type), а функция getPrice ($ type) возвращает 0, поэтому может быть из-за 0 суммы вы получаете эту ошибку из внешнего api (Payment gateway api).
amount
равна 0