Customer API
getAll()
Description
Returns the list of customers.
Signature
getAll(Filter\Customer\GetAll $filters = null): DataObject\Customer\Existing[]
Throws
Example
<?php
use Dreamscape\ResellerApiSdk\Api;
use Dreamscape\ResellerApiSdk\Authenticator\ApiKey;
use Dreamscape\ResellerApiSdk\Http\Adapter\Curl;
use Dreamscape\ResellerApiSdk\Filter;
use Dreamscape\ResellerApiSdk\PredefinedValue;
use Dreamscape\ResellerApiSdk\Exception;
$api = new Api(new Curl(new ApiKey('YourAPIKeyGoesHere'), 'https://reseller-api.sandbox.ds.network'));
$filters = Filter\Customer\GetAll::build();
$filters->page = 1;
$filters->limit = 10;
try {
$customers = $api->customers->getAll($filters);
foreach ($customers as $customer) {
echo 'Customer ID: ' . $customer->id . PHP_EOL;
echo 'First Name: ' . $customer->firstName . PHP_EOL;
echo 'Last Name: ' . $customer->lastName . PHP_EOL;
if ($customer->statusId === PredefinedValue\Customer::STATUS_ACTIVE) {
echo 'Customer is active' . PHP_EOL;
}
}
} catch (Exception\BadRequestException $e) {
// Handle the errors in $e->getErrors().
}
getDetails()
Description
Returns the details of a single customer.
Signature
getDetails(int $customer_id): DataObject\Customer\Existing
Throws
Example
<?php
use Dreamscape\ResellerApiSdk\Api;
use Dreamscape\ResellerApiSdk\Authenticator\ApiKey;
use Dreamscape\ResellerApiSdk\Http\Adapter\Curl;
use Dreamscape\ResellerApiSdk\Exception;
use Dreamscape\ResellerApiSdk\PredefinedValue;
$api = new Api(new Curl(new ApiKey('YourAPIKeyGoesHere'), 'https://reseller-api.sandbox.ds.network'));
try {
$customer = $api->customers->getDetails(123456);
echo 'Customer ID: ' . $customer->id . PHP_EOL;
echo 'First Name: ' . $customer->firstName . PHP_EOL;
echo 'Last Name: ' . $customer->lastName . PHP_EOL;
if ($customer->statusId === PredefinedValue\Customer::STATUS_ACTIVE) {
echo 'Customer is active' . PHP_EOL;
}
} catch (Exception\NotFoundException $e) {
// Handle the exception.
}
createLoginLink()
Description
Creates a login link for a customer.
Signature
createLoginLink(int $customer_id, int $product_id = null): DataObject\Customer\LoginLink
Throws
Example
<?php
use Dreamscape\ResellerApiSdk\Api;
use Dreamscape\ResellerApiSdk\Authenticator\ApiKey;
use Dreamscape\ResellerApiSdk\Http\Adapter\Curl;
use Dreamscape\ResellerApiSdk\Exception;
$api = new Api(new Curl(new ApiKey('YourAPIKeyGoesHere'), 'https://reseller-api.sandbox.ds.network'));
try {
$loginLink = $api->customers->createLoginLink(123456);
echo 'Login link: ' . $loginLink->link . PHP_EOL;
} catch (Exception\NotFoundException $e) {
// Handle the exception.
}
create()
Description
Creates new customer.
Signature
create(DataObject\Customer\Create $data_object): DataObject\Customer\Existing
Throws
Example
<?php
use Dreamscape\ResellerApiSdk\Api;
use Dreamscape\ResellerApiSdk\Authenticator\ApiKey;
use Dreamscape\ResellerApiSdk\Http\Adapter\Curl;
use Dreamscape\ResellerApiSdk\DataObject;
use Dreamscape\ResellerApiSdk\Exception;
use Dreamscape\ResellerApiSdk\PredefinedValue;
$api = new Api(new Curl(new ApiKey('YourAPIKeyGoesHere'), 'https://reseller-api.sandbox.ds.network'));
try {
$new_customer = DataObject\Customer\Create::build()
->setFirstName('John')
->setLastName('Doe')
->setAddress('123 Example Street')
->setCity('Testville')
->setCountry('AU')
->setState('WA')
->setPostCode('00000')
->setCountryCode(61)
->setPhone('912345678')
->setMobile('912345678')
->setEmail('john.doe@crazydomains.com.au')
->setAccountType(PredefinedValue\Customer::ACCOUNT_TYPE_BUSINESS)
->setBusinessName('John & Doe Corp')
->setBusinessNumberType('ABN')
->setBusinessNumber('12345678');
$new_customer->username = 'john_doe';
$new_customer->password = 'NWx9673z9gptzVJN';
$customer = $api->customers->create($new_customer);
echo 'Customer ID: ' . $customer->id . PHP_EOL;
} catch (Exception\BadRequestException $e) {
// Handle the errors in $e->getErrors().
}
update()
Description
Updates the details of a single customer.
Signature
update(int $customer_id, DataObject\Customer\Update $data_object): DataObject\Customer\Existing
Throws
Example
<?php
use Dreamscape\ResellerApiSdk\Api;
use Dreamscape\ResellerApiSdk\Authenticator\ApiKey;
use Dreamscape\ResellerApiSdk\Http\Adapter\Curl;
use Dreamscape\ResellerApiSdk\DataObject;
use Dreamscape\ResellerApiSdk\Exception;
$api = new Api(new Curl(new ApiKey('YourAPIKeyGoesHere'), 'https://reseller-api.sandbox.ds.network'));
try {
$update_customer = DataObject\Customer\Update::build();
$update_customer->firstName = 'John';
$update_customer->lastName = 'Doe';
$update_customer->username = 'john_doe_2';
$customer = $api->customers->update(123456, $update_customer);
echo 'Customer ID: ' . $customer->id . PHP_EOL;
} catch (Exception\NotFoundException $e) {
// Handle the exception.
} catch (Exception\BadRequestException $e) {
// Handle the errors in $e->getErrors().
}
terminate()
Description
Terminates the customer.
Signature
terminate(int $customer_id): bool
Throws
Example
<?php
use Dreamscape\ResellerApiSdk\Api;
use Dreamscape\ResellerApiSdk\Authenticator\ApiKey;
use Dreamscape\ResellerApiSdk\Http\Adapter\Curl;
use Dreamscape\ResellerApiSdk\Exception;
$api = new Api(new Curl(new ApiKey('YourAPIKeyGoesHere'), 'https://reseller-api.sandbox.ds.network'));
try {
$api->customers->terminate(123456);
} catch (Exception\NotFoundException $e) {
// Handle the exception.
}