hampel/synergy-wholesale

Synergy Wholesale API wrapper using SoapClient

1.5.0 2022-08-10 07:02 UTC

README

Latest Version on Packagist Total Downloads Open Issues License

A Synergy Wholesale API wrapper using SoapClient

By Simon Hampel

Installation

To install using composer, run the following command:

composer require hampel/synergy-wholesale

Note that if you intend to use this package with Laravel, we recommend installing the hampel/synergy-wholesale-laravel package instead, which provides a simple Laravel service provider and Facade for working with this API wrapper. The Laravel version automatically links into the Laravel logging system as well, making it easy to keep track of issues with the API.

Usage

You will need to turn on API access in your Synergy Wholesale control panel, which will tell you your Reseller ID. You also need to add the IP address of your web server to the IP whitelist to enable an API key.

Specify the Reseller ID and API Key as parameters to the SynergyWholesle constructor.

You can optionally specify a logging implementation which uses the psr/log interface (eg Monolog), which will enable the API calls and responses to be logged for debugging and error tracking purposes.

This API wrapper provides a rich object-oriented interface to the API calls, using value objects to construct inputs which provide granular validation of input data.

Raw responses from the API are stdClass objects containing public properties with the response values. This wrapper processes and validates these responses and provides a richer interface for accessing the returned data.

Exceptions are thrown on errors.

Long-hand Initialisation Example

// start by creating a SoapClient with the location of the WSDL file supplied by Synergy Wholesale
$client = new SoapClient(null, array('location' => SynergyWholesale::WSDL_URL, 'uri' => ''));

// create a Response generator (the engine which maps command objects to response objects)
$responseGenerator = new \SynergyWholesale\BasicResponseGenerator();

// now we can build our command execution engine, pass "null" for the logger if we don't have one
$sw = new \SynergyWholesale\SynergyWholesale($client, $responseGenerator, null, "reseller_id", "api_key");

Alternative Static Factory Example

// does all the heavy lifting for you if you don't need a logger
$sw = \SynergyWholesale\SynergyWholesale::make("reseller_id", "api_key");

Balance Query Command Example

// create a command object for the SynergyWholesale service to execute
$command = new BalanceQueryCommand(); // no parameters required for this call!

// execute the command
try {
    $response = $sw->execute($command);
}
catch (Exception $e) {
    // different exceptions are thrown on different types of errors
    // you can be as coarse or as granular as you like with error handling
    exit("Error executing command: " . $e->getMessage());
}

echo "Account balance: " . $response->getBalance();

Domain Information Command Example

// need to create a Domain object first
try {
    $domain = new \SynergyWholesale\Types\Domain('example.com');
}
catch (\SynergyWholesale\Exception\InvalidArgumentException $e) {
    exit("Error building domain object: " . $e->getMessage());
}

// pass this as a parameter to the command
$command = new DomainInfoCommand($domain);

// execute the command
try {
    $response = $sw->execute($command);
}
catch (Exception $e) {
    exit("Error executing command: " . $e->getMessage());
}

echo "

// check availability of a domain for registration
$command = new CheckDomainCommand('example.com');
$response = $sw->execute($command);

var_dump($response);

Notes

Only the Domain Name and SMS API calls have been implemented

TODO:

  • Implement all the other calls to the SynergyWholesale API