metaregistrar / php-epp-client

Object-oriented PHP EPP Client
https://www.metaregistrar.com/docs/
MIT License
214 stars 159 forks source link

Check Balance on Switch (NIC.ch) #390

Open IIPoliII opened 4 months ago

IIPoliII commented 4 months ago

Hello,

I am currently playing around with this code but I don't understand how to use the checbalance function.

Here is my code

<?php
require('../autoloader.php');

use Metaregistrar\EPP\eppConnection;
use Metaregistrar\EPP\eppException;
use Metaregistrar\EPP\eppCheckDomainRequest;
use Metaregistrar\EPP\eppCheckDomainResponse;

echo "Checking balance";
try {
    if ($conn = eppConnection::create('../settings.ini')) {
        $conn->addExtension("balance-1.0", "https://www.nic.ch/epp/balance-1.0");
        // Connect and login to the EPP server
        if ($conn->login()) {
            echo "Checking balance\n";
            checkBalance($conn);
            $conn->logout();
        }
    }
} catch (eppException $e) {
    echo "ERROR: " . $e->getMessage() . "\n\n";
}

function checkBalance($conn) {
    // Create request to be sent to EPP service
    $check = new eppBalanceInfoRequest();
    // Write request to EPP service, read and check the results
    if ($response = $conn->request($check)) {
        $checkResult = $response->getBalance();
        echo $checkResult;
    }
}

Here you can see that I load the "eppCheckDomainRequest". However when I call eppBalanceInfoRequest using "$check = new eppBalanceInfoRequest();"

I get the following error

PHP Fatal error:  Uncaught Error: Class "eppBalanceInfoRequest" not found in /RED/php-epp-client/Examples/checkbalance1.php:27
Stack trace:
#0 /RED/php-epp-client/Examples/checkbalance1.php(17): checkBalance()
#1 {main}
  thrown in /RED/php-epp-client/Examples/checkbalance1.php on line 27

I am searching since a few hours now, and I would definitly love some help/guidance.

Thanks in advance.

metaregistrar commented 2 months ago

It might be that you are missing the import (use Metaregistrar\EPP\eppBalanceInfoRequest)

Or you can try to use the complete path in $check = new Metaregistrar\EPP\eppBalanceInfoRequest();