3
* ResellerClub.class.php
5
* This file contains the definition of the ResellerClub class.
7
* @package resellerclub
8
* @author John Diamond <jdiamond@solid-state.org>
9
* @copyright John Diamond <jdiamond@solid-state.org>
10
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
14
require_once BASE_PATH . "modules/RegistrarModule.class.php";
19
* Provides a wrapper for the Reseller Club API library.
21
* @package resellerclub
22
* @author John Diamond <jdiamond@solid-state.org>
24
class ResellerClub extends RegistrarModule
27
* @var string Configuration page
29
var $configPage = "rcm_config";
32
* @var Customer Reseller Club API Customer object
37
* @var boolean Debug flag
42
* @var string Default customer password
44
var $defaultCustomerPassword = "defaultpw";
47
* @var DomContact Reseller Club API Domain Contact object
49
var $domContact = null;
52
* @var DomOrder Reseller Club API Order object
57
* @var string Module name
59
var $name = "resellerclub";
62
* @var string Reseller Club language preference
67
* @var string Long description
69
var $description = "Reseller Club Domain Registrar Module";
72
* @var integer Parent ID
74
var $parentID = 999999998;
77
* @var string Reseller Club password
79
var $password = "password";
82
* @var integer Reseller ID
87
* @var string Reseller Club Role
89
var $role = "reseller";
92
* @var string Short Description
94
var $sDescription = "Reseller Club";
97
* @var string Service URL
99
var $serviceURL = "http://demo.myorderbox.com/anacreon/servlet/rpcrouter";
102
* @var string Reseller Club Username
104
var $username = "user@email.com";
107
* @var integer Version
114
* Create a new customer at Reseller Club
116
* @param string $username Directi Username (an email address)
117
* @param string $password Password
118
* @param string $name Customer's name
119
* @param string $company Customer's company
120
* @param string $address1 Address line 1
121
* @param string $address2 Address line 2
122
* @param string $address3 Address line 3
123
* @param string $city City
124
* @param string $state State
125
* @param string $contry Contry code
126
* @param string $zip Postal code
127
* @param string $telephone1 Customer's telephone (1-xxxxxxxxxx format)
128
* @param string $telephone2 Customer's mobile phone (1-xxxxxxxxxx format)
129
* @param string $fax Customer's fax number (1-xxxxxxxxxx format)
130
* @return integer Customer ID
132
function addCustomer( $username,
147
// Massage the data as needed
148
if( empty( $company ) )
150
// Company can not be null
154
// Add a customer at Directi
155
$telephone1 = $this->parse_phone_number( $telephone1 );
156
$telephone2 = $this->parse_phone_number( $telephone2 );
157
$result = $this->customer->addCustomer( $this->getUsername(),
158
$this->getPassword(),
160
$this->getLangPref(),
161
$this->getParentID(),
174
$telephone1['number'],
176
$telephone2['number'],
181
if( !is_numeric( $result ) )
183
// Error when adding customer
192
* Add or Edit a Reseller Club Contact Record
194
* Add a new contact record at Reseller Club, or if it already exists, update it.
196
* @param integer $customer_id The customer who this contact belongs to
197
* @param ContactDBO $contactDBO Contact DBO
198
* @return integer Directi Contact ID
200
function addOrEditContact( $customerID, $contactDBO )
202
if( empty( $contactDBO->getBusinessName ) )
204
// If no company is provided, set company field to contact name
205
$contactDBO->setBusinessName( $contactDBO->getName() );
208
// Find out if this contact already exists
210
$contacts = $this->domContact->listNames( $this->getUsername(),
211
$this->getPassword(),
213
$this->getLangPref(),
214
$this->getParentID(),
216
if( $contacts != null )
218
foreach( $contacts as $key => $data )
220
if( is_numeric( $key ) )
222
if( $data['company'] == $contactDBO->getBusinessName() &&
223
$data['name'] == $contactDBO->getName() )
225
// Contact already exists
226
$contactID = $data['contactid'];
236
$phone = $this->parse_phone_number( $contactDBO->getPhone() );
237
$fax = $this->parse_phone_number( $contactDBO->getFax() );
238
$result = $this->domContact->mod( $this->getUsername(),
239
$this->getPassword(),
241
$this->getLangPref(),
242
$this->getParentID(),
244
$contactDBO->getName(),
245
$contactDBO->getBusinessName(),
246
$contactDBO->getEmail(),
247
$contactDBO->getAddress1(),
248
$contactDBO->getAddress2(),
249
$contactDBO->getAddress3(),
250
$contactDBO->getCity(),
251
$contactDBO->getState(),
252
$contactDBO->getCountry(),
253
$contactDBO->getPostalCode(),
258
if( $result['status'] != "Success" )
261
fatal_error( "ResellerClub::addOrEditContact()",
262
"could not modify contact for domain registration at Reseller Club!" );
268
$phone = $this->parse_phone_number( $contactDBO->getPhone() );
269
$fax = $this->parse_phone_number( $contactDBO->getFax() );
271
$this->domContact->addContact( $this->getUsername(),
272
$this->getPassword(),
274
$this->getLangPref(),
275
$this->getParentID(),
276
$contactDBO->getName(),
277
$contactDBO->getBusinessName(),
278
$contactDBO->getEmail(),
279
$contactDBO->getAddress1(),
280
$contactDBO->getAddress2(),
281
$contactDBO->getAddress3(),
282
$contactDBO->getCity(),
283
$contactDBO->getState(),
284
$contactDBO->getCountry(),
285
$contactDBO->getPostalCode(),
291
if( !is_numeric( $contactID ) )
293
fatal_error( "RegistrarDirecti::add_edit_contact()",
294
"could not add contact for domain registration at Directi!" );
302
* Check Domain Availability
304
* @return boolean True if the domain is available to be registered
306
function checkAvailability( $fqdn )
308
$this->checkEnabled();
310
// Check domain name availability
311
$result = $this->domOrder->checkAvailability( $this->getUsername(),
312
$this->getPassword(),
314
$this->getLangPref(),
315
$this->getParentID(),
319
if( !isset( $result[$fqdn] ) )
321
throw new RegistrarException( "[RESELLER_CLUB_NO_DATA_RETURNED]." );
324
return $result[$fqdn]['status'] == "available";
330
* @return boolean Debug flag
332
function getDebug() { return $this->debug; }
335
* Get Default Customer Password
337
* @return string Default customer password
339
function getDefaultCustomerPassword() { return $this->defaultCustomerPassword; }
342
* Get Language Preference
344
* @return string Language preference
346
function getLangPref() { return $this->langpref; }
351
* @return integer Parent ID
353
function getParentID() { return $this->parentID; }
358
* @return string Password
360
function getPassword() { return $this->password; }
365
* @return integer Reseller ID
367
function getResellerID() { return $this->resellerID; }
372
* @return string Role
374
function getRole() { return $this->role; }
379
* @return string Service URL
381
function getServiceURL() { return $this->serviceURL; }
386
* @return string Username
388
function getUsername() { return $this->username; }
391
* Initialize Reseller Club Module
393
* Invoked when the module is loaded. Call the parent method first, then
401
$this->setDebug( $this->moduleDBO->loadSetting( "debug" ) );
402
$this->setLangPref( $this->moduleDBO->loadSetting( "langpref" ) );
403
$this->setParentID( $this->moduleDBO->loadSetting( "parentid" ) );
404
$this->setUsername( $this->moduleDBO->loadSetting( "username" ) );
405
$this->setPassword( $this->moduleDBO->loadSetting( "password" ) );
406
$this->setResellerID( $this->moduleDBO->loadSetting( "resellerid" ) );
407
$this->setRole( $this->moduleDBO->loadSetting( "role" ) );
408
$this->setServiceURL( $this->moduleDBO->loadSetting( "serviceurl" ) );
410
if( $this->isEnabled() )
413
require BASE_PATH . "modules/resellerclub/lib/domorder.class.php";
414
require BASE_PATH . "modules/resellerclub/lib/customer.class.php";
415
require BASE_PATH . "modules/resellerclub/lib/domcontact.class.php";
417
// Create Reseller Club objects
419
new DomOrder( BASE_PATH . "modules/resellerclub/lib/wsdl/domain.wsdl" );
421
new Customer( BASE_PATH . "modules/resellerclub/lib/wsdl/customer.wsdl" );
423
new DomContact( BASE_PATH . "modules/resellerclub/lib/wsdl/domaincontact.wsdl" );
428
* Install Reseller Club Module
430
* Invoked when the module is installed. Calls the parent first, which does
431
* most of the work, then saves the default settings to the DB.
436
$this->saveSettings();
440
* Verify Domain is Transfer Eligible
442
* @param string $fqdn Domain name
443
* @return boolean True if the domain is transfer eligible
445
function isTransferable( $fqdn )
447
$this->checkEnabled();
449
// Check domain name availability
450
$result = $this->domOrder->checkAvailability( $this->getUsername(),
451
$this->getPassword(),
453
$this->getLangPref(),
454
$this->getParentID(),
458
if( !isset( $result[$fqdn] ) )
460
throw new RegistrarException( "[RESELLER_CLUB_NO_DATA_RETURNED]." );
463
// Transferable rules:
464
// * The domain must not be available
465
// * The domain must not be registered through us
466
return !($result[$fqdn]['status'] == "available" ||
467
$result[$fqdn]['status'] == "regthroughus");
473
* Parse a SolidWorks phone number for use with Reseller Club
475
* @param string $phoneNumber A solidstate phone number (+x-xxxxxxxxxx)
476
* @return array Phone number components ('CC' and 'number')
478
protected function parse_phone_number( $phoneNumber )
480
$components = explode( "-", $phoneNumber );
481
$result['cc'] = intval( $components[0] );
482
$result['number'] = $components[1];
488
* Prepare Customer and Contacts
490
* Queries the customer ID, or creates a new customer if necessary. Then adds
491
* or edits the contacts as necessary.
493
* @param array $contacts An array of ContactDBO's
494
* @param AccountDBO $accountDBO The account DBO
495
* @return array ID's in an associative array with keys: customerid, adminid, techid, billingid
497
function prepareCustomerContacts( $contacts, $accountDBO )
499
// Reseller Club uses e-mail addresses as customer usernames
500
$customer = $accountDBO->getContactEmail();
502
// Query the customer's ID
503
if( !( $customerID = $this->queryCustomerID( $customer ) ) )
505
// Add a new customer
506
if( !($customerID = $this->addCustomer( $accountDBO->getContactEmail(),
507
$this->getDefaultCustomerPassword(),
508
$accountDBO->getContactName(),
509
$accountDBO->getBusinessName(),
510
$accountDBO->getAddress1(),
511
$accountDBO->getAddress2(),
513
$accountDBO->getCity(),
514
$accountDBO->getState(),
515
$accountDBO->getCountry(),
516
$accountDBO->getPostalCode(),
517
$accountDBO->getPhone(),
518
$accountDBO->getMobilePhone(),
519
$accountDBO->getFax() ) ) )
521
fatal_error( "ResellerClub::registerNewDomain()",
522
"There was an error when trying to add a new Reseller Club customer" );
526
// Enter Admin contact
527
$adminID = $this->addOrEditContact( $customerID, $contacts['admin'] );
528
if( !is_numeric( $adminID ) || $adminID < 0 )
530
fatal_error( "ResellerClub::registerDomain",
531
"could not add Admin contact for domain registration at Reseller Club!" );
534
// Enter Technical contact
535
$techID = $this->addOrEditContact( $customerID, $contacts['tech'] );
536
if( !is_numeric( $techID ) || $techID < 0 )
538
fatal_error( "ResellerClub::registerDomain",
539
"could not add Tech contact for domain registration at Reseller Club!" );
542
// Enter Billing contact
543
$billingID = $this->addOrEditContact( $customerID, $contacts['billing'] );
544
if( !is_numeric( $billingID ) || $billingID < 0 )
546
fatal_error( "ResellerClub::registerDomain",
547
"could not add Billing contact for domain registration at Reseller Club!" );
550
return array( "customerid" => $customerID,
551
"adminid" => $adminID,
553
"billingid" => $billingID );
557
* Register a New Domain
559
* Registers a new domain name without requiring any Reseller Club specific
562
* @param string $domainName Domain name to be registered (without TLD)
563
* @param string $TLD Domain TLD to register
564
* @param integer $term Number of years to register the domain for
565
* @param array $contacts Admin, billing, and technical contact DBOs
566
* @param AccountDBO $accountDBO The account that is registering this domain
568
function registerNewDomain( $domainName, $TLD, $term, $contacts, $accountDBO )
572
// Make sure this module is enabled
573
$this->checkEnabled();
575
// Prepare customer and contacts, get IDs
576
$ids = $this->prepareCustomerContacts( $contacts, $accountDBO );
579
$fqdn = sprintf( "%s.%s", $domainName, $TLD );
580
$results = $this->domOrder->registerDomain( $this->getUsername(),
581
$this->getPassword(),
583
$this->getLangPref(),
584
$this->getParentID(),
585
array( $fqdn => "{$term}" ),
586
$conf['dns']['nameservers'],
594
if( $results[$fqdn]['status'] != "Success" )
597
throw new RegistrarException( "[RESELLER_CLUB_FAILED_TO_REGISTER]: " .
598
var_export( $results ) );
605
* @param DomainServicePurchaseDBO $purchseDBO The domain to be renewed
606
* @param integer $renewTerms Number of years to renew for
608
function renewDomain( $purchaseDBO, $renewTerms )
610
$this->checkEnabled();
611
$fqdn = $purchaseDBO->getFullDomainName();
613
// Query the Reseller Club domain record
614
if( !($domainRecord = $this->queryDomainRecord( $fqdn )) )
616
// Domain record not found at Reseller Club
620
// Renew the domain (note: noofyears must be passed as a string)
621
$request = array( $fqdn => array( "entityid" => $domainRecord['entity.entityid'],
622
"noofyears" => sprintf( "%d", $renewTerms ),
623
"expirydate" => $domainRecord['orders.endtime'] ) );
624
if( !($result = $this->domOrder->renewDomain( $this->getUsername(),
625
$this->getPassword(),
627
$this->getLangPref(),
628
$this->getParentID(),
632
throw new RegistrarException( "Unexpected return value from DomOrder::renewDomain()!" );
634
if( !$result[$fqdn]['actionstatus'] == "Success" )
637
throw new RegistrarException( "[RESELLER_CLUB_FAILED_TO_RENEW]: " .
638
$result['actionstatusdesc'] );
643
* Query Reseller Club Customer ID
645
* Given the customer's username (an e-mail address), query the customer's ID
648
* @param string $username Customer's username (an e-mail address)
649
* @return integer Customer ID, or null
651
function queryCustomerID( $username )
653
$result = $this->customer->listOrder( $this->getUsername(),
654
$this->getPassword(),
656
$this->getLangPref(),
657
$this->getParentID(),
659
$this->getResellerID(),
674
if( $result['recsindb'] > 1 )
676
fatal_error( "ResellerClub::queryCustomerID()",
677
"Customer::list() returned unexpected results" );
680
return $result[1]["customer.customerid"];
684
* Query Reseller Club Domain Record
686
* Given a domain name, query the order record stored at Reseller Club
688
* @param string $fqdn Domain name
689
* @return array Reseller Club's domain record
691
function queryDomainRecord( $fqdn )
694
$result = $this->domOrder->listOrder( $this->getUsername(),
695
$this->getPassword(),
697
$this->getLangPref(),
698
$this->getParentID(),
700
$this->getResellerID(),
713
if( !is_array( $result ) )
715
fatal_error( "ResellerClub::queryDomainRecord()",
716
"Unexpected result from domOrder::listOrder()!" );
719
// Search the list for the domain name
720
foreach( $result as $key => $domainData )
722
if( is_array( $domainData ) && $domainData['entity.description'] == $fqdn )
724
// Domain record found
729
// Could not find domain record
734
* Save Reseller Club Settings
736
function saveSettings()
738
// Save default settings
739
$this->moduleDBO->saveSetting( "debug",
740
$this->getDebug() == null ? 0 : $this->getDebug() );
741
$this->moduleDBO->saveSetting( "defaultcustomerpassword", $this->getDefaultCustomerPassword() );
742
$this->moduleDBO->saveSetting( "langpref", $this->getLangPref() );
743
$this->moduleDBO->saveSetting( "parentid", $this->getParentID() );
744
$this->moduleDBO->saveSetting( "username", $this->getUsername() );
745
$this->moduleDBO->saveSetting( "password", $this->getPassword() );
746
$this->moduleDBO->saveSetting( "resellerid", $this->getResellerID() );
747
$this->moduleDBO->saveSetting( "role", $this->getRole() );
748
$this->moduleDBO->saveSetting( "serviceurl", $this->getServiceURL() );
754
* @param boolean $debug Debug flag
756
function setDebug( $debug )
758
global $debugfunction;
760
$this->debug = $debug;
762
// Reseller Club API Global var
763
$debugfunction = ($debug == true);
767
* Set Default Customer Password
769
* @param string $password Default customer password
771
function setDefaultCustomerPassword( $password )
773
$this->defaultCustomerPassword = $password;
777
* Set Language Preference
779
* @param string $langpref Language preference
781
function setLangPref( $langpref ) { $this->langpref = $langpref; }
786
* @param integer $parentid Parent ID
788
function setParentID( $parentID ) { $this->parentID = $parentID; }
793
* @param string $password Password
795
function setPassword( $password ) { $this->password = $password; }
800
* @return integer $resellerID Reseller ID
802
function setResellerID( $resellerID ) { $this->resellerID = $resellerID; }
807
* @param string $role Role
809
function setRole( $role ) { $this->role = $role; }
814
* @param string $serviceURL Service URL
816
function setServiceURL( $serviceURL )
820
$this->serviceURL = $serviceURL;
822
// Reseller Club API Global variable
823
$serviceurl = $serviceURL;
829
* @param string $username Username
831
function setUsername( $username ) { $this->username = $username; }
836
* @param string $domainName Domain name to be transferred (without TLD)
837
* @param string $TLD Domain TLD
838
* @param integer $term Number of years to renew domain for
839
* @param string $secret The domain secret
840
* @param array An associative array of ContactDBO's (admin, billing, and tech)
841
* @param AccountDBO $accountDBO The account that is transferring this domain
842
* @return boolean True for success
844
function transferDomain( $domainName, $TLD, $term, $secret, $contacts, $accountDBO )
848
// Make sure this module is enabled
849
$this->checkEnabled();
851
// Prepare customer and contacts, get IDs
852
$ids = $this->prepareCustomerContacts( $contacts, $accountDBO );
854
// Send transfer request to Reseller Club
855
$fqdn = sprintf( "%s.%s", $domainName, $TLD );
856
$result = $this->domOrder->transferDomain( $this->getUsername(),
857
$this->getPassword(),
859
$this->getLangPref(),
860
$this->getParentID(),
861
array( $fqdn => $secret ),
868
if( $result[$fqdn]['status'] != "Success" )
871
throw new RegistrarException( "[RESELLER_CLUB_FAILED_TO_TRANSFER]: " .
872
$result[$fqdn]['actionstatusdesc'] );
b'\\ No newline at end of file'