其他方法调用函数

I am trying to call testFunction() in the $this->mollie->payments->create method, but I get an error:

Fatal error: Uncaught exception 'Mollie_API_Exception' with message 'Error executing API call (request): The amount is lower than the minimum.'

So this means that the $this->testFunction() returns 0.

I did the following test:

$test = new gtpMollieGateway();
echo $test->testFunction();

And this gives a right value (a calculated amount for my checkout).

So this means that I do something wrong with calling the testFunction() in the $this->mollie->payments->create method

My code for creating a payment:

// 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;

The class for calculating my amount:

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;
        }
    }
}

After long time searching and trying I have found the problem. My session was not started in my plugin document. Wordpress loads the plugin before functions.php, and my session was started in functions.php.

So this was the reason that my value was 0, and that was occurring the error.

Your function testFunction() is calling function function getPrice( $type ) and function getPrice( $type ) is returning 0 so may be because of 0 amount you are getting this error from external api (Payment gateway api).