Giter Site home page Giter Site logo

synergy-wholesale's Introduction

Synergy Wholesale API Wrapper

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.